When a scheduled agent run fails with no human watching, the conversation log is the replay buffer: the full sequence of tool calls that led to the error. Without it, you know the run failed and nothing else. With it, you can inspect the exact step where it went wrong and test the fix against the same history.
Before you start
A store for run records, such as a database table, and an agent loop you can wrap with logging.
Record the full loop, not just the result
For each run, store the job id, the start and end time, the status, the error if any, and the full conversation log: every message, tool call and tool result in order.
Redact secrets from the log before you store it: API keys and passwords do not belong in a replay buffer.
Store runs by id, with the job attached
Give each run an id and link it to its job, so you can list all runs of one job and see which ones failed. Keep the runs table small and queryable: job, status, start time, error.
Keep the logs long enough to debug a failure reported days later, and set a retention rule so the store does not grow forever.
Replay the failure to test the fix
When a run fails, open its log and walk the tool calls in order until the bad step shows. Fix the tool, the prompt or the guardrail, then replay the same task and compare the new log with the old one.
If the replay passes, the fix works for that failure. If it fails differently, the log shows the new bad step.
Practice check: fictional Maple Corner nightly agent, 7 runs, 1 failed
The table below is fictional practice material, worked out by hand from the stated run log. It is the expected result for the practice log, not a run of any agent.
| Run | Status | Tool calls | Error | Verdict |
|---|---|---|---|---|
| Mon | Success | 8 | None | Pass |
| Tue | Success | 9 | None | Pass |
| Wed | Failed | 6 | Tool timeout | Reproduced from log |
| Thu | Success | 8 | None | Pass |
| Fri | Success | 7 | None | Pass |
Five runs are logged and the Wednesday failure is reproduced from its log: the sixth tool call timed out. The fix is a longer timeout for that tool, verified by replaying the same task.
Expected result. UNTESTED: the runs in the practice table are worked out by hand, not measured by running an agent. Log the full conversation for your own runs, store them by run id, and replay the next failure from its log.
Limits
- A log without the tool results cannot be replayed: store the results, not just the calls.
- Logs hold real data: redact secrets and set a retention rule before you store them.
