How to Replay and Debug an AI Agent Session, Tool Calls Included (2026)
Step through a recorded agent session call by call, find the turn where it went wrong, and know when a re-run is worth the cost and the risk.
On this page
An agent session that went wrong is a long story: dozens or hundreds of model calls and tool calls, spread over minutes or hours, with the mistake usually somewhere in the middle. Reading it in a terminal scrollback or in flat logs is slow, and asking the agent "what did you do?" gets you a summary written by the same model that made the mistake.
Replaying the session is faster. This guide covers what a session needs to record to be replayable, how to step through one and find the turn where it went wrong, how to debug a whole trajectory instead of single steps, and when it is worth re-running the session instead of reading it.
Replay is not re-run
"Replay" is used for two different things, and mixing them up wastes time and money:
| Replay (read the recording) | Re-run (execute again) | |
|---|---|---|
| What happens | You step through what was recorded, call by call | The agent runs the task again with the same input |
| Cost | Nothing | Tokens and tool time again |
| Side effects | None | Can repeat them: commits, emails, writes, payments |
| Same path? | Always: it is the original run | Not guaranteed, even with the same input |
| Answers | What happened, and where it went wrong | Whether it happens again, and whether a fix works |
Start with replay. Most root causes are visible in the recording, and a re-run can take a different path and hide the failure you were looking for.
What a session must record to be replayable
You can only step through what was captured. For each session, record:
- Every model call: what the model was sent, the exact model id the provider returned, the parameters that shape the answer (temperature, maximum tokens, the tools it was offered), what it answered, and the tokens and cost.
- Every tool call: the tool name, the arguments, the raw result or error, when it started, how long it took, and whether it succeeded.
- Order and parentage: which model call produced which tool call, and which steps belong to a subagent.
- Ids: a session id for the whole process, a trace id per task, and a step index, so the timeline can be rebuilt in order.
- Context that changes behaviour: the repository and commit, versions of the tools, configuration flags.
Decide early how much content to keep. Metadata only (tool names, timings, tokens, outcomes) is safe for sensitive environments and still shows where a session failed and how long each step took. Full content, with secrets and personal data scrubbed before it leaves the machine, is what lets you read why.
Step through a session
1. Open the session and find the task
A session holds everything one process did; the task you care about is one trace inside it. Find it by time, by the prompt that started it, or by the failed outcome you are investigating.
2. Walk the timeline turn by turn
For each turn, read three things in order: what the model saw, what it decided (a tool call, an answer, a question), and what came back. Do not jump to the end. The last step shows where the damage became visible, not where it started.
3. Find the divergence point
Look for the first turn where a correct run would have chosen differently. The usual signals:
- A tool called with arguments built from the wrong field, or a guessed value.
- A tool error or an empty result that the next turn treats as a normal answer.
- The same call repeated with the same arguments three or more times.
- The context growing sharply, or a compaction, right before the behaviour changes.
- A different model id appearing in the middle of the session.
4. Inspect the tool calls around it
At the divergence point, compare the arguments with what the tool expects, check whether the result was truncated or paginated, and read the raw error, not the model's paraphrase of it. Most agent bugs live at this boundary.
5. Write down the cause with its evidence
Note the step number, the call, the result and the decision that followed. A cause with evidence can be handed to a teammate, or to a coding agent, and checked against the next run.
Debug the trajectory, not only the step
A trajectory is the sequence of decisions an agent made on its way to an outcome. Some failures have no single broken step; the whole path is wrong. Compare the failed trajectory with a successful run of the same task: the number of steps, the order of tools, and where the two paths split.
| Trajectory pattern | What it looks like | Usual cause |
|---|---|---|
| Wandering | Many reads and searches, no action | A vague goal, or missing context the agent keeps looking for |
| Thrashing | Edit, test, fail, the same edit again | No limit on retries, or a test the agent cannot make pass |
| Premature success | Claims the task is done after a partial check | No rule about what "done" means |
| Tool avoidance | Answers from memory where a tool call was needed | A tool description that does not say when to use it |
| Drift after compaction | Behaviour changes after the context is compacted | An instruction that did not survive the summary |
Patterns repeat across sessions. Once you have named one, look for it in other failed runs before fixing a single instance.
When a re-run is worth it
Re-run a session when the recording cannot answer the question:
- The content is missing. The session was captured with metadata only and the cause depends on what the prompt said.
- You need to confirm a fix. Same input, new prompt or tool contract: does the agent now take the right path?
- You need a failure rate. Run the same task several times and count. One pass proves little either way.
Make re-runs safe and comparable:
- Feed recorded tool results back instead of calling live systems, so the re-run cannot change anything and sees the same data.
- Sandbox what cannot be mocked: read-only credentials, a throwaway branch or database, dry-run flags.
- Pin the model id and parameters of the original run. Even at temperature 0, identical output is not guaranteed.
- Cap the run with a maximum number of steps and tokens, so a loop cannot burn the budget.
Replaying sessions in Voight
Voight Observability records sessions from Claude Code, Cursor and Codex, wrapped OpenAI and Anthropic clients, the Vercel AI SDK, Python apps and the plain HTTP API, and lets you step through them:
- Sessions, traces and events. One session per process, one trace per task, and every tool call as a single row with its duration and outcome. A call that starts and gets no result for more than two minutes is flagged.
- A waterfall for every trace, with each step's duration, tokens and cost.
- Smart analysis on every trace: the first failure with its offset, latency and cost hotspots, retry loops of three or more identical calls, and how the run compares with the agent's median over the last seven days.
- Explain with AI. One click returns a plain-language explanation of what happened in the trace.
- Issues across sessions. Failures with the same pattern are grouped into one issue, and Diagnose with AI proposes a root cause and a fix you can paste into Claude Code, Cursor or Codex.
- A privacy chip on each event, so you know whether the content is there before you go looking for it.
Voight records sessions and lets you read them step by step; it does not re-execute them. Connect a coding agent with one command:
npx -y @voightxyz/sdk setup
Checklist
- Every model call and tool call is recorded with ids, order, timing and outcome.
- The content level is decided up front, per environment.
- Read the recording before re-running anything.
- Start from the first divergence, not the last failure.
- Compare the trajectory with a successful run of the same task.
- Re-runs use recorded tool results, a sandbox, the pinned model and a step limit.
- Run a fix several times before calling it fixed.