Agents, Tool Use & MCP·Question 55 of 90Advanced

A customer reports the agent did something wrong three days ago. You have the trace. Can you reproduce it? How do you build a system where the answer is yes?

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

With a typical trace, no. You have what happened, not enough to make it happen again. Traces are for reading; replay is a separate capability you design for, and the gap between them is where most agent debugging dies.

Full worked answer with diagram

With a typical trace, no. You have what happened, not enough to make it happen again. Traces are for reading; replay is a separate capability you design for, and the gap between them is where most agent debugging dies.

The barriers, and what each costs to remove:

The model is nondeterministic. Even at temperature 0, batching and floating-point nondeterminism in serving stacks mean identical tokens are not guaranteed, and model versions change under you. So true re-execution of the model is off the table. That is fine, because you rarely want it.

The world moved on. get_inventory returns different data now. Re-running against live dependencies reproduces a different scenario, not the bug.

So I build two distinct replay modes, and the distinction is the interview signal:

  1. Deterministic replay: no model call at all. Persist a full event log, every LLM response and tool result verbatim, then re-drive your loop against the recording with model responses as fixtures. This reproduces exactly and answers "is the bug in my code": the parser, the state machine, the permission gate, the compaction logic. Fast, free, and it runs in CI as a regression test forever. It catches more real bugs than people expect, because a large share of agent failures are orchestration bugs rather than model failures.

  2. Counterfactual replay: real model, recorded tool results. Pin the tool outputs from the log and let the model respond fresh. This answers "does the new prompt or model fix this?" It is not reproduction, it is an experiment, so run it k times and read the distribution. A single pass tells you nothing about a stochastic system.

What the event log must contain for either to work: the exact request bytes including resolved system prompt, tool definitions, and sampling params; the raw response including tool call IDs and reasoning blocks where the API returns them; every tool result verbatim; timestamps; and code and prompt versions. Append-only, keyed by run ID, treated as the source of truth from which trace UIs are derived. If you built tracing as fire-and-forget spans with payloads truncated for cost, you cannot replay, and the truncated tool result is exactly the field you will need.

Worth sketching. Two branches off one event log, each answering a different question, is the distinction the question is built around.

flowchart LR
    A["Event log: request bytes,<br/>raw responses, tool results"] --> B["Deterministic replay,<br/>no model call at all"]
    A --> C["Counterfactual replay:<br/>live model, pinned tool results"]
    B --> D["Answers: is the bug in my<br/>parser, gate or compactor?"]
    C --> E["Answers: does the new prompt<br/>fix it? Run k times, read the spread"]

What a good answer covers

  • You have what happened, not enough to make it happen again
  • Traces are for reading; replay is a separate capability you design for, and the gap between them is…
  • Even at temperature 0, batching and floating-point nondeterminism in serving stacks mean identical…
  • So true re-execution of the model is off the table
  • That is fine, because you rarely want it

Key terms: The model is nondeterministic · The world moved on · two distinct replay modes

Interviewer follow-ups to expect

  1. Storing full payloads for every run is expensive at scale. What is your retention policy?

  2. How do you replay a run that involved a human approval and a 20-minute pause?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep