Skip to main content
Your agent did something wrong in production. A customer complained, or you saw it in your tracing tool. This guide turns that run into a test you run on your computer. Your agent runs for real, on the same input. Each of its tool calls gets the answer production got. The test checks for what went wrong and tells you whether the failure happens again. The test stays in your repository, so once you fix the agent the failure cannot quietly come back.

Before you start

  • The Ancha CLI: npm install -g @ancha-labs/cli.
  • An agent whose runs are traced: OpenTelemetry (the AI SDK, OpenLLMetry, any GenAI instrumentation), Langfuse or LangSmith.
  • For traces kept in your workspace: an account at app.ancha.io, then ancha login. To keep everything on your computer, use ancha import --offline with a trace file instead.

1. Wrap your agent’s tools

In a test, your agent’s tools must not reach production. Wrap them once. Outside a test the wrapper calls your function as before. In a test, each call is answered from production’s recorded calls.
Install with npm install @ancha-labs/tools or pip install ancha. Tools your agent reaches over MCP need no wrapper: point the MCP client at {{tools.mcp_url}} in ancha.yaml. Tool wrappers has the details. If a tool the trace recorded is not wrapped, the test stops before your agent runs and names the tool, so a test never calls production by accident.

2. Bring in the trace

Pick the source your agent already uses.
Import one trace by its id, with your own keys from this shell. They never leave your computer.
For LangSmith, set LANGSMITH_API_KEY and pass --from langsmith. Ancha reads the whole conversation of a thread and the feedback on every turn.
--expect says in one sentence what went wrong. The test gets a check for it, and Ancha judges whether production did it (it did). Without --expect, the checks come from the trace: a thumbs-down comment becomes a check that the agent does not do what the user complained about, and an error that ended the run becomes a check that the agent finishes. With neither, the test asks what the agent should have done. The test lands in scenes/from-traces/trace-<id>/:

3. Answer what one trace cannot settle

The import lists the questions. The two you meet most:
  • tools.mcp: which tools your agent reaches over MCP. A trace cannot tell. The test serves those at {{tools.mcp_url}}.
  • tools.simulate_writes: which writes may be simulated when the agent makes one production never made. By default such a write fails, so a test never invents a write’s success.
For a trace in your workspace, answer with ancha pull <id> --answer ..., which saves a new version. See ancha pull.

4. Reproduce it

Run the test against the version of the agent that failed in production:
Output
The last line says how much of the run stood on production’s own answers. A call production never made to a tool that only reads is answered by a model shown the tool’s description, every answer production got, and the agent’s writes so far. A tool that changed something is never simulated unless you said so. ancha explain lists each answer that was not production’s. If production’s failure does not happen here, either the agent is already fixed or the test differs from production. questions.json says where it may differ.

5. Fix the agent and keep the test

Change your agent and run the test again until production’s failure no longer happens:
Output
Run it several times. An agent that passes once can still fail. Then commit scenes/from-traces/. Every ancha run, in CI too, keeps the failure fixed. See Run Ancha in CI. Add checks of your own in scene.yaml, such as refund_order {order_id: A-1002} never being called. Ancha computes production’s result for them too, and they stay when you pull a newer version. See Checks.

When the agent calls vendor APIs directly

An agent that calls Slack, GitHub, Datadog or another tool Ancha has a twin of, with the request and response bodies in its trace, gets that twin seeded from the calls. The test then answers new calls from the twin’s state, not from a recording. Add the bodies with the Ancha recorder. A tool of your own whose code called such a vendor runs against the twin for calls production never made.

What a trace can and cannot tell

  • It shows what your agent was asked and what each tool answered. It cannot show what a tool would have answered to a call production never made; that is replayed from a similar call, simulated, or failed, and each answer says which.
  • It cannot test a bug inside a tool’s own code. Ancha answers in the tool’s place; what is tested is what your agent decides.
  • Your trace data stays in your workspace, redacted before it is stored. See Trace privacy.