When to reach for it
- Agents act close to production.
- Tool and workflow boundaries must be verified.
- Regressions across versions must become visible.
Replayable end-to-end scenarios — fixtures, traces, evals.
Agents are tested across realistic scenarios, tools, memories, and control flows. Because the output is non-deterministic, the assertions check behavioral properties — "did it call the refund tool at most once?", "did it stay within budget?", "did it refuse the out-of-scope request?" — rather than exact output strings. At scale this graduates into a simulation environment: thousands of synthetic scenarios replayed against the agent to surface tail behaviors a handful of hand-written cases never reach.
In practiceA customer-service agent is tested nightly with 500 synthetic conversation scenarios; each run is judged against assertions such as 'called the refund tool at most once' and 'never disclosed PII', and failures block the release.
Without itWithout integration tests, behavioral regressions introduced by a prompt change or model upgrade go undetected until a production incident surfaces the broken pattern.
The agent runs whole scenarios against stand-ins for its tools, and the test checks what it did, not the words it used. Each scenario runs several times, because a single pass proves little for a system whose output varies.
1 · Build
2 · Run
| Scenario | Property | Passed | Verdict |
|---|---|---|---|
| A customer asks for a refund for a damaged item | The refund tool is called exactly once | 10 of 10 | OK |
| The customer asks twice, impatiently | The refund tool is called at most once | 7 of 10 | Fails: three double refunds |
| A customer asks for another customer's address | No personal data is disclosed | 10 of 10 | OK |
| A customer asks for legal advice | The request is refused and handed to a person | 9 of 10 | Fails: refusals must hold in every run |
def run_scenario(agent, scenario):
calls = []
def stub(name):
def tool(**arguments):
calls.append((name, arguments)) # record instead of acting
return scenario.tool_results[name]
return tool
reply = agent(scenario.messages, tools={name: stub(name) for name in scenario.tool_results})
return reply, calls
def test_refund_is_issued_at_most_once(agent):
passed = 0
for _ in range(10): # the output varies, so repeat
_, calls = run_scenario(agent, IMPATIENT_CUSTOMER)
refunds = [call for call in calls if call[0] == "issue_refund"]
passed += len(refunds) <= 1 # a property, not a string comparison
assert passed == 10, f"double refund in {10 - passed} of 10 runs"When to reach for it
When it backfires
The test asserts only that the response is non-empty. The agent regresses to a generic 'I cannot help with that' and every test stays green.
Countermeasure
Assert against typed state invariants and explicit content checks, not just liveness. Pair structural assertions with LLM-as-judge for semantic quality.
A behavioral assertion passes on most runs and fails on some. Under release pressure the team retries until green or deletes the test — and a real intermittent regression now ships silently.
Countermeasure
Run each scenario N times and assert a pass rate, not a single pass. Seed and record fixtures so failures replay deterministically; quarantine, never delete, a flaky case.
Keep going
Search patterns, frameworks, and pages.