Test the world, not the path
Exact-path trajectory tests fail correct agents and pass dangerous ones. Assert the state the agent leaves behind and the rules that must hold at every step, and keep exact order for the few places it matters.
The obvious first trajectory eval pins the exact sequence of tool calls. The agent should call get_order, then check_refund_policy, then create_refund. Record a good run, save the sequence, compare every future run against it.
It feels rigorous, and it fails in both directions. A correct agent that calls get_order twice, because it wanted to confirm the amount after reading the policy, fails the test. A broken agent that follows the exact sequence and refunds the wrong amount passes it. After a few weeks of the first kind of failure, someone loosens the match to “these tools in any order,” and now neither kind gets caught.
The fix is to change what you assert. Check the world the agent leaves behind, check rules that must hold at every step of the run, and pin exact order only where order is the requirement.
What the benchmarks already figured out
The research benchmarks for tool-using agents stopped grading paths a while ago. τ-bench grades a customer-service conversation by comparing the database state at the end with an annotated goal state, plus a check that the agent’s replies contained the information the user asked for. It doesn’t care how the agent got there. AgentDojo does the same for security: each task’s utility check is a deterministic function over the environment before and after the run. No judge model is involved.
Anthropic’s guide to agent evals from January says it plainly: it’s often better to grade what the agent produced, not the path it took, and checking for a fixed sequence of tool calls makes tests too rigid. It defines the outcome as the final state of the environment at the end of the trial.
Common eval tooling still nudges you toward paths. LangChain’s agentevals offers trajectory match modes (strict, unordered, subset, superset), all comparisons against a reference sequence. Strict matching is fine for the few ordered requirements in layer three. As the starting point it brings back the problem above.
Layer one: end state
Run the agent against a world, then assert on the world.
case: partial-refund-damaged-item
world: fixtures/store-with-order-A1001.yaml
input: "Half my order arrived broken. Can I get money back?"
expect:
state:
# exactly one refund, for the broken half
refunds: [{ order: A-1001, amount_cents: 2125 }]
orders.A-1001.status: delivered # not cancelled
emails_sent: { to: customer, count: 1 }
Any path that ends in this state passes. One that refunds the wrong amount or cancels the order fails. Exact-path tests can’t see the wrong-amount case at all: the right tools, called in the right order, with the wrong arguments.
“What must not change” deserves its own assertions. An agent that refunds the right order and also quietly edits the customer’s shipping address passes a refund-only check. Diff the whole world before and after, and fail on any change the case didn’t expect.
In practice a whole-world diff fails on every timestamp, generated ID and audit row, so you declare an ignore list. Unexpected side effects hide in that list. Keep it in the repo and review every addition like code, because “ignore customers.*.updated_at” is one careless glob away from “ignore customers.*”.
Layer two: rules over the whole run
End state misses things that happened and then got undone, and things whose order mattered. An agent that sends an email, notices it was wrong, and sends a correction ends in an acceptable state. The customer still got two emails.
So the second layer checks properties over every event in the trace:
always:
- approval_before:
{ tool: create_refund, when: policy.requires_approval }
- at_most: { tool: create_refund, per: order, count: 1 }
- only: { tool: send_email, to: customer.email_on_file }
- no_writes_after: user_said_stop
Hypothesis’s stateful testing runs invariants after every step of a generated sequence and reports the step where one broke. The failure message for an agent trace should do the same: “create_refund called a second time for A-1001 at step 9.”
The part of property-based testing worth stealing is the generator, though. Checking rules over the runs you happened to get is just assertions. The agent version of a generator is fault injection in the world: create_refund commits and then times out, get_order returns data from before the last write, the email provider returns one 500. Run the same case under each perturbation and check the same rules. That’s the usual source of double refunds: the refund commits, the response times out, and the agent tries again.
A rule names what can never happen and leaves the agent free to do everything else. Rules are also the right place to encode the policies production enforces. If production requires approval for refunds over a limit, load the test rule from the same policy definition. Tests and enforcement can’t drift apart, and a policy change immediately fails any case where the agent breaks it.
Layer three: exact order, sparingly
Some sequences are the requirement. Verify identity before reading account details. Confirm the return arrived before refunding it. For those, assert followed_by between the specific pair of events and nothing else. Most cases need one or two ordered pairs, if any. A fully pinned sequence should be rare enough that you can name every case that has one.
Use fakes
None of this works against mocks that return canned responses, because the agent never sees the consequences of what it did. Call create_refund and then get_order, and a mock returns the original order with no refund on it. Agents often re-read state after a write. Against a mock, that read contradicts the write, and the agent’s next step reacts to a world that can’t exist.
A fake is a small in-memory implementation with the real rules: a refund reduces the refundable balance, and a cancelled order can’t be refunded. It costs more to build than a mock. Without one, the end-state layer has nothing real to assert against.
A fake that disagrees with production is worse than none. Run the same contract tests against the fake and a sandbox of the real API, and treat a divergence as a failing test. Include the error messages in that contract. The agent’s next move depends on the wording of an error, so a fake that returns a tidy "invalid request" where production returns three sentences about refund windows tests a different agent than the one you ship.
Time is a dependency
Agents that act often act later: send a reminder in 24 hours, escalate if nobody approves by morning. Nobody writes a test that waits a day.
Route every wait through one injected clock, and let the test advance it. When the run is idle, jump to the next due timer. Temporal’s test server does this for workflows with time skipping, and the same idea works for an agent loop. A three-day follow-up becomes a test that runs in milliseconds and fails deterministically when the reminder fires twice.
Replay production, and know when replay lies
The best regression cases are real conversations that went wrong. Record the model’s responses, the tool results and a snapshot of the world state from a production trace, then replay them against the new version of the agent. CI needs no API keys, and a run costs no model tokens.
The catch is that a recorded model response is valid only for the exact request that produced it. Change the system prompt or add a tool, and the recorded response answers a request the new code never sent. Hash each model request during replay. When the hash doesn’t match, the replay has diverged, and you have two choices: fail the case and re-record, or switch that case to a live model from that point on. If you take the live route, seed a fake from the recorded world state, apply the recorded writes up to the divergence point, and send the live model’s tool calls there. The recorded tool results stop fitting the moment the new agent calls something different. Silently serving the stale response is the failure to design against.
An exact hash has its own problem: every prompt edit invalidates every recording. The options are bad. Re-recording the whole suite costs money and swaps in new nondeterminism. Loosening the match brings back stale responses. Hash a normalized request instead. Strip timestamps and generated IDs, list the differences you deliberately tolerate, and report each case as “diverged at turn 4” so a reviewer can see how far the old recording still holds.
Nondeterminism needs two thresholds
Run each case several times. τ-bench introduced pass^k, the chance that all k attempts at a task succeed, because a single pass hides inconsistency. In their results, gpt-4o’s function-calling agent had a pass^1 of about 61% in the retail domain, and its pass^8 fell under 25%.
Inconsistency is tolerable for some assertions and fatal for others, so they need different thresholds. A quality check (“the reply mentions the refund amount”) can reasonably pass at four out of five. A safety rule (“never refund twice”) must hold on every run, and here the arithmetic is unkind. A bug that double-refunds 1% of the time passes ten clean runs about 90% of the time. Zero failures in n runs only tells you, with 95% confidence, that the rate is below roughly 3/n. For ten clean runs the exact bound is about 26%.
So CI can catch a safety regression that got common. It can’t certify that a rare one is gone. Rare violations need enforcement in the agent itself, such as an intent-level idempotency key on create_refund or a policy check before every write. Then run the same layer-two rules as monitors over production traces, where n is large enough to mean something.
Grade the prose last
Deterministic checks on state and rules are cheap and give the same answer every time. Judge models cost money and can disagree with themselves on a rerun. Run the deterministic layers first and pay a judge only for cases that passed them. If the agent cancelled the order, nobody cares how polite the reply was.
Sources
- Yao, Shinn, Razavi and Narasimhan, τ-bench (2024)
- Debenedetti et al., AgentDojo (2024)
- Anthropic, Demystifying evals for AI agents (January 2026)
- LangChain, agentevals
- Hypothesis, Stateful testing
- Temporal, Testing suite: skipping time