Integration Tests for Agents

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.

Level
04 · Production
Subdomain
Observability & Evaluation
Also known as
Agent Integration Tests, Scenario Tests, End-to-End Agent Tests
Trade-off
Higher operational security is achieved against expensive test data, mocks, simulation harnesses, and evaluation logic.
Native in
LangSmith, OpenAI Evals, Microsoft Agent Framework, Google ADK, CrewAI, AutoGen / AG2
The mechanism

How it works.

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

  1. Write scenariosA user goal and a starting state
  2. Stub the toolsPrepared results, every call recorded
  3. State the propertiesWhat must hold, whatever the wording

2 · Run

  1. Run each scenario several timesThe outputs differ
  2. Check the propertiesOn the recorded calls and the final state
  3. Compute a pass ratePer scenario
  4. Gate the releaseBelow the threshold: blocked
Behavioural property
A statement about actions, for example: the refund tool was called at most once. It holds or fails whatever the phrasing.
Tool stub
A stand-in for a real tool that returns prepared results and records how it was called.
Pass rate
The share of runs in which a property held. One green run out of one says little.
Walk it through

A real run, step by step.

TaskA new version of a customer-service agent is tested before release. Each scenario runs ten times against stubbed tools:
Illustrative run. Two failures block the release.
ScenarioPropertyPassedVerdict
A customer asks for a refund for a damaged itemThe refund tool is called exactly once10 of 10OK
The customer asks twice, impatientlyThe refund tool is called at most once7 of 10Fails: three double refunds
A customer asks for another customer's addressNo personal data is disclosed10 of 10OK
A customer asks for legal adviceThe request is refused and handed to a person9 of 10Fails: refusals must hold in every run
What this shows: a single run of the second scenario would have passed seven times out of ten, and the double refund would have reached production. A comparison of exact strings would have failed every run, including the good ones. The price is scenarios and stubs that have to be maintained, and forty agent runs for four scenarios before every release.
In code

The pattern in code.

pytestpython
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"
Fit

Use it, or not.

When to reach for it

  • Agents act close to production.
  • Tool and workflow boundaries must be verified.
  • Regressions across versions must become visible.

When it backfires

  • Only an isolated prompt is being explored.
  • Tests cannot be evaluated deterministically enough.
  • The test environment endangers external systems.
Pitfalls

Two ways this pattern will hurt you.

Tests pass by being too lenient

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.

Flaky non-determinism gets muted instead of fixed

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.

Framework support

Where Integration Tests for Agents is native.

LangSmithServiceeval datasets + CINative
OpenAI EvalsLibraryscenario gradersNative
Microsoft Agent Frameworkevaluation harnessNative
Google ADKagent eval suitesNative
CrewAITest PatternsNative
AutoGen / AG2agent test utilitiesNative

Search

Search patterns, frameworks, and pages.