← Back to Blog

AI Engineering

Did Your Agent Fix Actually Work? How to Replay the State of the World

Rerunning an old production trace won't show whether your agent fix worked once the data has changed. How to freeze the world and build tests that last.

This is Part 2 of a series on eval-driven development. If you’re new to evals, start with Part 1.

In Part 1, a customer asked our refund agent “Where is my refund?” The agent called search_orders, saw that order #4821’s refund was pending (approved but not yet sent), and replied that it couldn’t help. We promoted that trace into a test case and wrote down what the agent should have done: look up the order, issue the refund, and tell the customer when to expect it.

Now say you fix the agent prompt and rerun that case a week later.

In that week, a support rep saw the complaint and sent the refund by hand. When your offline case runs, it calls the same search_orders as production, which now says “refunded” instead of “pending.”

The bug only shows up when a refund is pending, so the old agent never hits it. It gives the same answer as the fixed one: your refund is on its way. Both pass the reference-answer grader, and both fail the check that issue_refund ran once, since there’s nothing left to refund. The case can no longer tell your fix from the bug, and telling them apart was the whole point of promoting the trace.

A week after the original failure, the order has already been refunded, so the old agent and the fixed agent give the same answer and get the same grades.

Part 1 assumed you could rerun a trace later under the same conditions it ran under in production. That doesn’t hold for an agent that reads from and writes to real systems, because its results depend on what was in those systems at the time, and that data keeps changing: orders get refunded, records get edited, and policies change.

What does it mean to freeze the world?

Part 1 showed that an eval is a grader applied to a trace. Part 2’s core idea is that when you rerun a promoted case, you keep everything outside the agent as it was and change only the agent; we call that freezing the world.

Everything a trace depended on falls into one of two groups:

  • The world: what your tools returned, the data behind those answers, the time, and, in a conversation, the user. Freeze as much of it as you can, as it was when the trace ran.
  • The agent: the prompt, the model, tool descriptions, and your code, including the code inside your tools. Change these, because that’s why you’re rerunning the case.

What to freeze and what to change: the world (tool results, the data behind them, the time, and the user) stays as it was, and the agent (prompt, model, tool descriptions, and code) is what you change.

Set up this way, a promoted case is a controlled experiment. One thing changed, so a pass or a fail tells you something about that change. Rerun it against the live world and you’ve changed two things at once (your agent and a week of changes to your data), and you can’t tell which one moved the result.

Note: The model belongs to the agent, but it’s the one piece you can’t fully control. Providers retire old versions, and even a pinned version can answer differently from run to run. Pin a version anyway, and run each case several times (k runs, as in Part 1).

Why not just play back what the tools returned?

The obvious way to freeze the world is to save what each tool returned in production and play it back when the case reruns. When the agent calls search_orders for #4821, it gets “pending,” just like the first time. This is usually called record-and-replay, and it works as long as the agent makes the same calls it made the first time.

A fixed agent often doesn’t, and a recording breaks in three ways:

  • The fixed agent makes a call that was never recorded. Say the fix adds a get_refund_status call to double-check before refunding. There’s nothing to play back for it. Send new calls to the live system instead and you’re testing today’s world again, and a new issue_refund really refunds the customer.
  • The agent refunds, checks again, and still sees “pending.” Even if you fake a success for the refund, the next search_orders will get the stale recorded answer from before the refund. The agent may think the refund failed and try again.
  • A fix you made to a tool never runs. Say you added a check to issue_refund that blocks refunds on the wrong order. Playback returns the recorded result without running the tool, so the check never gets tested.

Most fixes change which calls the agent makes, and a recording can only answer the calls the original agent made.

For engineers: Recording at the HTTP layer instead of at your tools solves the third problem, since your tool code runs, but not the first two.

Fake the world, not the tools

So how do you build a world that can answer calls it has never seen? Put the fakes one layer down. Your search_orders and issue_refund code runs for real, and the orders database and payments API underneath it are swapped for fakes: small working stand-ins that answer reads and record writes.

Each case supplies what the fakes start from:

  • A fixture. The data the trace depended on (order #4821, its customer, and the refund policy at the time), loaded into the fake orders database.
  • A frozen clock, set to when the trace ran, so “pending for 3 days” doesn’t become “pending for 10.”

When issue_refund runs, the refund is recorded in the fake payments service and the order is marked refunded, so the next search_orders sees it. Each of the k runs starts from a fresh copy of the fixture, so one run’s refund doesn’t carry into the next.

The agent's tools run for real, while the orders database and payments API underneath them are replaced with fakes loaded from a fixture.

Faking the systems underneath your tools solves all three problems with a recording. A call the original agent never made is answered from the same frozen data, a write shows up the next time the agent reads, and because your tool code runs, a fix inside issue_refund gets tested.

You still keep the recording, but only as a check: the original calls, replayed against the fakes, should get the same answers production gave (step 3 below).

Sometimes the fixed agent asks for data the fixture doesn’t have, like a second order from the same customer. Give each fixture a clear scope, such as everything about this customer, and have the fakes return an error for anything outside it, so a gap fails the run instead of looking like “no order found.” Then add the data and rerun it. Don’t fall back to the live system (you’ll get a mixed, inconsistent world), and don’t let an LLM make up an answer.

The fakes record every change the agent makes, so you can grade the outcome itself by reading the end state of the data. Instead of counting calls to issue_refund, as Part 1’s deterministic check did, check what the world looks like after the run: order #4821 is marked refunded in the fake orders database, and the fake payments service recorded exactly one refund, for $84. Because you’re grading the outcome, a fixed agent that takes a different but valid route still passes. Keep your trajectory graders next to it, though. A refund sent without confirming the order belongs to the customer leaves the same end state as a correct one, and only a check on the agent’s steps will catch it.

How do you build the frozen world?

You have to build this layer yourself. As of December 2026, none of LangSmith, Langfuse, Braintrust, or Arize recreates the state of your systems for you. Your eval platform can store the case, fixture included, and keep the scores, but the fakes and the code that loads them live in your eval harness, the test code that sits between your agent and the systems it calls.

For engineers: Most teams need one code change: a way for the harness to hand each tool its database and API clients, instead of the tool opening its own connections. In production the tools get the real clients, and in a case they get fakes loaded from the fixture.

Not every system needs a hand-written fake. Choose the approach by the kind of system:

Part of the worldHow to freeze it
Your own databaseThe same database engine, loaded with only the fixture’s rows. It still needs the scope check above, and a pinned clock if your queries use the current time.
Outside services you write to, like payments or ticketingA small fake that covers only the calls your tools make, behaves like the real service, and records every attempt, including the ones it rejects
Outside data you only read, like web searchRecord-and-replay, since nothing the agent does changes it. This is the one place a live call for a new query can be OK: it’s only a read, so the worst case is some drift.
Tools you don’t own, like a vendor’s MCP serverThere’s no layer under the tool that you control, so fake the tool itself and have the fake keep track of changes

The work grows with the number of systems behind your tools, not the number of tool calls or cases. A refund agent with a dozen tools might talk to three systems. Once those have fakes, a new case only adds fixture rows, and those come from your logs.

You don’t always need fakes. If your agent only reads, freeze what you can and record the rest, since fakes pay off once an agent writes something and reads it back. If the failure was one bad decision, rerun just that model call (see “Check the failing step first” below).

Some systems already keep history

Freezing a system doesn’t always mean building a fake. For agents that work on engineering tasks, two of the most common systems can be frozen with a single marker:

  • Code repositories. Record which commit each repo was on during every run, and have a replay check out those exact commits. Without that, the agent’s shell tools, like grep and git log, read today’s code instead of the code the original run saw.
  • Slack. Slack is mostly append-only, so it already keeps most of its own history. Instead of building mock data, a replay can use a Slack MCP that only returns messages from before the trace’s timestamp. That doesn’t bring back messages that were edited or deleted later.

Before you build a fake, check whether the system already keeps history. If it does, a commit or a timestamp may be all you need to freeze it.

What about the customer conversation?

The customer is the one part of the world you can’t freeze. Say the #4821 customer answered “I can’t help with that” with “Then I want to talk to a person.” Your fixed agent issues the refund instead, so that recorded reply no longer fits the conversation.

The simplest option is to replay the real conversation up to the turn where the agent went wrong, and grade only the agent’s reply at that turn. For #4821, that’s right after the customer’s first message. It’s cheap, and it keeps the customer’s real words. When you need to test a whole conversation, have an LLM play the customer, starting from the real opening message and given their goal from the trace: “find out where the refund for order #4821 is.” Simulated customers tend to be easier to satisfy than real ones, so don’t read a simulated pass rate as a real one.

From production trace to replayable case

Here’s the full process. It fills in two steps of Part 1’s loop (turning a production trace into a case, and confirming it fails before you fix it) for an agent that works with real systems.

  1. Capture the world with every trace. Log each tool call’s arguments, raw result, and timestamp, plus the prompt, model, and agent versions. If a tool returns a summary like “refund: pending,” log the record behind it too. If you don’t log this when the trace runs, you can’t get it back later. Tool results can hold customer data, so redact what you can when you log it and limit who can read production traces.
  2. Build the frozen world. When you promote the trace, build the fixture from what step 1 logged, not from your database as it is today, and set the clock to the trace’s timestamp. Build the fixture to match the state at the start of the trace, before the agent’s first write, so the tools make those changes again during the rerun. If your database keeps history, you can also pull rows as of that moment, but most keep only days or weeks of it, so don’t wait. Keep the fixture small, only what the failure depended on, and replace names and emails with consistent placeholders instead of blanking them, so the data still hangs together.
  3. Prove the case reproduces. First, replay the recorded calls through your tools against the fakes and confirm each one returns what production returned. Then run the unfixed agent k times and confirm it fails. If it never fails, the fixture is probably missing something the failure depended on, or the failure was intermittent and needs more runs to show up. (If the original model has been retired, run the old prompt and code on a current model as your baseline.)
  4. Fix it with Part 1’s loop. Change the agent and rerun until the case passes at your k bar (say, 3 of 3 runs), then run the full dataset to make sure nothing else broke.

Once the fix passes, the case joins your regression suite. Because the fakes answer from data instead of saved responses, it keeps working when your agent takes new paths. It still needs upkeep: run your schema migrations on fixtures too, check fakes against the real services when their APIs change, and have whoever changes a tool update its fake in the same pull request.

What a team starting out needs to know

  • Turn on tool-output capture now. Many tracing setups, including the OpenTelemetry GenAI conventions and Microsoft’s Agent Framework, leave tool results out by default. If yours leaves them out, none of the traces you collect today can be replayed later.
  • Check the failing step first. While you iterate on a prompt, you can rerun just the model call that went wrong, with its recorded inputs and your new prompt. No fakes needed, and LangSmith, Langfuse, Braintrust, and Arize all let you do it from a trace. The frozen world is what you keep as the regression case.
  • Start with one system. You don’t need a copy of production. Freeze the system behind your most common failures first, and start with cases that only touch it. Add other systems when a case needs them.
  • Note where the rerun leaves the recorded path. When a fixed agent makes a call the original never made, that’s often the fix working, and the first point where the two paths split shows you what your fix changed.

Coming next: intercepting writes

This post used one simple write, a refund recorded by a fake payments service. Part 3 covers the writes that are harder to fake, like emails to customers, PR creation, calls to systems with no test environment, and actions that can’t be undone, and how to catch and grade them in offline runs.

Subscribe to Ultrathink to get Part 3 when it goes live, or check back on the blog.

Common questions

Questions leaders ask us

Why can't I just rerun an old production trace to test an agent fix?

Because the data behind it has changed. An agent that reads from and writes to real systems gets different answers a week later (an order that was pending may already be refunded), so the old agent and the fixed agent can give the same answer and the case can no longer tell your fix from the bug.

What does it mean to freeze the world for an agent eval?

When you rerun a promoted case, you keep everything outside the agent as it was (tool results, the data behind them, the time, and the user) and change only the agent (prompt, model, tool descriptions, and code). One thing changes, so a pass or a fail tells you something about that change.

Why isn't record-and-replay of tool results enough?

A recording can only answer the calls the original agent made. A fixed agent often makes a call that was never recorded, reads stale data after its own write, or depends on a tool fix that playback never runs.

How do you build a frozen world that can answer new calls?

Put the fakes one layer down. Your tool code runs for real, and the databases and APIs underneath it are swapped for small working fakes loaded from a fixture of the data the trace depended on, with the clock frozen to when the trace ran.

What should a team do first to make agent traces replayable?

Turn on tool-output capture now. Many tracing setups leave tool results out by default, and if you don't log them when the trace runs, you can't get them back later.

Stop debating AI. Start deploying it.

Get Started