Trace¶
Trace recording, replay, and time-travel debugging.
Recorder¶
agentprobe.trace.recorder
¶
Trace recorder: captures agent execution events into structured Traces.
Provides an async context manager for recording LLM calls, tool invocations, and message exchanges during agent execution.
TraceRecordingContext
¶
Mutable context for recording events during an agent run.
Accumulates LLM calls, tool calls, and turns that will be
assembled into a frozen Trace by TraceRecorder.finalize().
Source code in src/agentprobe/trace/recorder.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | |
elapsed_ms
property
¶
Return elapsed time since recording started.
record_llm_call(*, model, input_tokens=0, output_tokens=0, input_text='', output_text='', latency_ms=0, metadata=None)
¶
Record an LLM call event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str
|
Model identifier. |
required |
input_tokens
|
int
|
Number of input tokens. |
0
|
output_tokens
|
int
|
Number of output tokens. |
0
|
input_text
|
str
|
Prompt text. |
''
|
output_text
|
str
|
Response text. |
''
|
latency_ms
|
int
|
Call latency in milliseconds. |
0
|
metadata
|
dict[str, Any] | None
|
Additional metadata. |
None
|
Returns:
| Type | Description |
|---|---|
LLMCall
|
The recorded LLMCall object. |
Source code in src/agentprobe/trace/recorder.py
record_tool_call(*, tool_name, tool_input=None, tool_output=None, success=True, error=None, latency_ms=0)
¶
Record a tool call event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_name
|
str
|
Name of the tool. |
required |
tool_input
|
dict[str, Any] | None
|
Arguments passed to the tool. |
None
|
tool_output
|
Any
|
Output from the tool. |
None
|
success
|
bool
|
Whether the call succeeded. |
True
|
error
|
str | None
|
Error message if failed. |
None
|
latency_ms
|
int
|
Call latency in milliseconds. |
0
|
Returns:
| Type | Description |
|---|---|
ToolCall
|
The recorded ToolCall object. |
Source code in src/agentprobe/trace/recorder.py
TraceRecorder
¶
Records agent execution events into a structured Trace.
Use as an async context manager via recording() to capture
events, then call finalize() to produce the frozen Trace.
Attributes:
| Name | Type | Description |
|---|---|---|
agent_name |
Name of the agent being recorded. |
|
model |
Primary model being used. |
|
tags |
Optional tags for filtering. |
Example
Source code in src/agentprobe/trace/recorder.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
__init__(agent_name, model=None, tags=None)
¶
Initialize a new trace recorder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_name
|
str
|
Identifier for the agent being recorded. |
required |
model
|
str | None
|
Primary model name. |
None
|
tags
|
list[str] | None
|
Optional tags for categorization. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If agent_name is empty. |
Source code in src/agentprobe/trace/recorder.py
recording()
async
¶
Start a recording session.
Yields a TraceRecordingContext for recording events.
Yields:
| Type | Description |
|---|---|
AsyncGenerator[TraceRecordingContext, None]
|
A mutable recording context. |
Source code in src/agentprobe/trace/recorder.py
finalize(*, input_text='', output='')
¶
Produce a frozen Trace from the recorded events.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_text
|
str
|
The input given to the agent. |
''
|
output
|
str
|
The final output from the agent. |
''
|
Returns:
| Type | Description |
|---|---|
Trace
|
An immutable Trace object. |
Raises:
| Type | Description |
|---|---|
TraceError
|
If no recording session was started. |
Source code in src/agentprobe/trace/recorder.py
Replay Engine¶
agentprobe.trace.replay
¶
Trace replay engine for re-executing recorded traces.
Supports pure replay from recorded data, with optional mock overrides for tool calls and outputs. Computes a ReplayDiff showing differences between original and replayed results.
ReplayEngine
¶
Replays recorded traces for comparison and testing.
In pure replay mode, tool calls return their recorded outputs. Optional mock functions can override specific tools.
Attributes:
| Name | Type | Description |
|---|---|---|
mock_tools |
Mapping of tool names to mock functions. |
|
mock_output |
If set, override the replay output text. |
Source code in src/agentprobe/trace/replay.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
__init__(*, mock_tools=None, mock_output=None)
¶
Initialize the replay engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mock_tools
|
dict[str, Callable[..., Any]] | None
|
Optional tool name to mock function mapping. |
None
|
mock_output
|
str | None
|
If set, override the output text. |
None
|
Source code in src/agentprobe/trace/replay.py
replay(trace)
¶
Replay a trace, applying any mock overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace
|
Trace
|
The original trace to replay. |
required |
Returns:
| Type | Description |
|---|---|
Trace
|
A new trace with mock overrides applied. |
Source code in src/agentprobe/trace/replay.py
diff(original, replay)
¶
Compute the diff between an original trace and a replay.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original
|
Trace
|
The original trace. |
required |
replay
|
Trace
|
The replayed trace. |
required |
Returns:
| Type | Description |
|---|---|
ReplayDiff
|
A ReplayDiff showing the differences. |
Source code in src/agentprobe/trace/replay.py
Time Travel¶
agentprobe.trace.time_travel
¶
Time-travel debugger for step-by-step trace inspection.
Provides indexed access to individual turns in a trace with cumulative metrics at each step, enabling debugging and analysis of agent execution flow.
TimeTravel
¶
Step-by-step trace inspector with cumulative metrics.
Pre-computes a list of TraceStep objects on construction, providing indexed access and iteration over the trace timeline with cumulative token, cost, and latency metrics at each step.
Attributes:
| Name | Type | Description |
|---|---|---|
trace |
Trace
|
The trace being inspected. |
Source code in src/agentprobe/trace/time_travel.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 | |
trace
property
¶
Return the underlying trace.
total_steps
property
¶
Return the total number of steps.
__init__(trace, *, cost_per_1k_input=0.0, cost_per_1k_output=0.0)
¶
Initialize the time-travel debugger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trace
|
Trace
|
The trace to inspect. |
required |
cost_per_1k_input
|
float
|
Cost per 1K input tokens for cumulative cost. |
0.0
|
cost_per_1k_output
|
float
|
Cost per 1K output tokens for cumulative cost. |
0.0
|
Source code in src/agentprobe/trace/time_travel.py
__getitem__(index)
¶
Get a step by index.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index
|
int
|
Zero-based step index. Supports negative indexing. |
required |
Returns:
| Type | Description |
|---|---|
TraceStep
|
The TraceStep at the given index. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If the index is out of range. |
Source code in src/agentprobe/trace/time_travel.py
steps()
¶
rerun_from(step_index)
¶
Return all steps from a given index onward.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
step_index
|
int
|
Zero-based starting index. |
required |
Returns:
| Type | Description |
|---|---|
list[TraceStep]
|
Steps from the given index to the end. |
Raises:
| Type | Description |
|---|---|
IndexError
|
If step_index is out of range. |