Skip to contentSkip to page list

Docs

Scenario Testing Best Practices

One worked story, a refund-support agent and its gold customer Anna, that takes a scenario from its first line to a gate in CI, and a table to choose how to build it.

On this page

These pages tell one story. A refund-support agent answers customers who want their money back. Anna is a gold customer with a delivered order, and she asks for a refund. We want a test that proves the agent finds her order and quotes the right amount, every time, against data that exists only for that test.

Each page takes the story one step further:

  1. Writing scenarios: the situation, the world it needs and criteria a judge can check.
  2. Test data: fixtures that build Anna's world before the first turn and remove it after the last. Its five rules, one section each, apply on every path.
  3. Parameters and suites: what varies between runs, and how scenarios group.
  4. Running and CI: repeats, comparisons, gating a release, and Not scored versus failed.

Which path fits your team

The practices are the same on every path. What changes is where the scenario, the test data and the run live. Each cookbook builds Anna's scenario end to end.

You wantPathScenario lives inTest data is made byWhat you needStart with
Tests in your repository, run by pytest or vitestCodeYour test filesA pytest fixture, or vitest beforeEach and afterEachA developer who writes the tests, and the Scenario SDK release after 1.7.1 (Python) or 1.8.2 (TypeScript)Test an agent fully in code
Engineers own the agent and its data, product owns the scenariosHybridThe platformSetup and teardown hooks on a connected agent, in your processA developer who connects the agent with the LangWatch SDK and keeps its process running, and the langwatch SDK release after 2.5.0 (TypeScript) or 2.0.1 (Python)Test an agent with code and the platform
No process of your own running, the agent reachable through an APIAppThe platformThe setup and teardown blocks of a Scenario ConnectorAn API LangWatch can reach, and a developer to paste the blocks: about half an hour if your API matches the example. Ask your developer early whether it does, with the hand-off messageTest an agent in the app

Pick the code path when every scenario change goes through code review anyway. Pick the hybrid path when the data needs your database, private network or internal secrets. Pick the app path when your API is reachable from the internet and no one wants to run a process. On every path, fixtures are plain data: in the test file on the code path, and in the scenario editor or the API on the other two.

The code path needs the Scenario SDK release after langwatch-scenario 1.7.1 and @langwatch/scenario 1.8.2, with vitest 4.1 or later. The hybrid path needs the langwatch SDK release after 2.5.0 (TypeScript) or 2.0.1 (Python). Until those releases ship, only the app path runs on published versions.

Why fixtures make results repeatable

A verdict means something only when the agent saw the world the scenario describes. Setup creates that world from fixtures before the first turn, and teardown removes it, in reverse order, after the last. Every run starts from the same data, so a failed run points at the agent, not at leftovers from the run before.

Next: Writing scenarios.

Documentation