The replay module lets you look inside completed agent runs, compare two runs side-by-side, and re-execute a past run with different configuration — all without touching trace files manually.
output_a = agent.run("Summarize the report.")output_b = agent.run("Summarize the report.")diff = agent.compare(output_a, output_b)print(diff.token_diff) # -150 (b used 150 fewer tokens)print(diff.cost_diff) # -0.0005print(diff.content_diff) # Unified diff stringprint(diff.tool_calls_diff.added) # Tools in b but not aprint(diff.tool_calls_diff.removed) # Tools in a but not bprint(diff.tool_calls_diff.common) # Count of matching tools
Pass override arguments to replay() to re-run the same input with different configuration. This returns a new RunOutput instead of a Replay:
# Re-execute with a different modelnew_output = agent.replay( run_output=output, model=OpenAIChat(id="gpt-4o-mini"),)# Re-execute with different instructions and toolsnew_output = agent.replay( trace_file="./traces/run.jsonl", run_id="abc123", instructions="Be more concise.", tools=[new_tool],)# Compare original vs re-executiondiff = agent.compare(output, new_output)print(diff.cost_diff) # How much cheaper was gpt-4o-mini?
Re-execution makes a live API call. The original input is extracted from the replay and sent to the model with your overrides applied.