Design a test environment
Guidelines for test environments and runners that give the same result on every run and fail only when the agent's behavior changes.
A good test environment makes a case fail only when the agent's behavior changes. If a case fails because a tool was called in a way the environment didn't expect, or because a real service changed, you're testing the setup, not the agent. These guidelines keep the failure on the agent.
They assume you have read Run cases in a test environment, which covers the definition format and the runner calls.
Play the agent you ship
Build the agent the way production builds it: the same system prompt, the same tool definitions and the same options. Replace only what the agent talks to: its tools and its data. A runner that builds a simplified agent tests something you don't ship.
Take the tool definitions from the agent's code, not from the environment. An environment that holds its own copy of a tool's name, description or input schema goes stale when the real tool changes, and the case keeps passing against a tool that no longer exists.
Make each environment one world plus one change
- Start from one baseline world. Its
seedis a complete, realistic set of data, such as every record the agent might look up. Create it once, asbaseline@1. - Make each other environment the baseline plus one change. For example,
one tool fails, or one record sits at a policy edge. Name it for the change,
such as
confirmation-service-down@1, and say what changed in its description. - Give every environment a complete seed, even when it only changes a tool. A runner that falls back to some default data when the seed is empty runs the case in a world the case didn't name.
- Never edit a version. Add a version, then move the cases that should use it. See Change an environment.
Answer every tool call deterministically
Use tools rules only for the change the environment is about. Every other
call goes to a deterministic version of the tool that reads the case's seed: the
real tool over a store built from the seed, or an in-memory fake.
Avoid environments where every call must match a rule. An agent rarely calls a tool with exactly the same arguments twice, especially an agent that writes code to call its tools. If a call no rule matches raises an error, the case fails on how the tool was called, not on what the agent did. If your runner can't give a tool a deterministic version, answer unmatched calls with a neutral result the real tool returns, such as "not found", and log each one so you can add rules for the calls that matter.
Copy each return from what the real tool returns, including the shape of its
errors.
Leave nothing live
A case reaches nothing outside its environment:
- No real services. No tool call reaches a production or staging API.
- No live sandboxes. If the agent runs code, run it in a sandbox the runner controls, with no network access, or answer its tools from the environment too.
- No wall clock. Store dates relative to the run, such as
delivered_days_ago, or give the runner a fixed "today", so a case written today still holds next month. - A fresh store for each case. Build the seed into a store that only one case uses, so one case's writes never reach another case.
Check before you spend
Before playing any case, stop the run if:
- a case names no environment;
- an environment has no seed;
- an environment has rules for a tool the agent doesn't have. A misspelled tool name mocks nothing and lets the real tool run.
The runner in Apply the environment in your runner does these checks. Checking before the run starts costs nothing; finding out after every case has played costs the whole run.
Play one case as one conversation
A case's input holds the user's side of one conversation. Send each message after the agent's previous turn has ended or the agent is waiting for the user, and keep every turn in one trace and one session, so judges grade the whole conversation. Give each case a timeout, and cancel the agent's run when it expires.
Both the agent and model judges can vary from run to run. Retry a failed case once before you fail the job, and report each failed check with the output it expected and the output it got.
Make a reproduction fail first
A case written to reproduce a failure must fail on the version of the agent that has the failure. If it passes there, the environment doesn't force the failure, and the case can't show that a fix worked.
- Write the environment so it forces the failure, for example by returning the tool results the agent saw when the failure happened.
- Run the case on the current agent and confirm it fails.
- Run it on the fix and confirm it passes.
A case that passes on both is still useful as a guard against the failure coming back. Put it in the suite every change runs.
Choose a judge for each check
In an environment you know what each tool returned, so most checks have an exact answer.
- Use a Code judge where the recorded tool calls answer the question: whether a tool was called, with which arguments, and what it returned. Pair each tool call with its result, rather than searching the conversation for text.
- Use an Agent judge only where the reply has to be read: what the user was told, whether a claim is supported, or the tone.
Before you pin a judge on your cases, run it on stored traces whose right answer you know. See Choose a judge for each check.
Checklist
- The runner builds the agent the way production does.
- Tool definitions come from the agent's code.
- There is one complete baseline world, and each other environment is the baseline plus one change.
- Rules cover only the change. Other calls get a deterministic answer from the seed.
- Nothing live: services, sandboxes, network access and the clock.
- The runner stops on a case with no environment, an environment with no seed, or a rule for an unknown tool.
- One case is one conversation, in one trace and one session, with a timeout.
- Every reproduction case fails on the agent that has the failure.
- Code judges check facts in the record; Agent judges check wording.
Next step
Run your agent on the test suite and read each case's result.