AgentTrace
The top-level container for a complete agent execution.| Field | Type | Description |
|---|---|---|
nodes | list[TraceNode] | Ordered list of spans in execution order. DAG structure is encoded via parent_id. |
ideal | str | None | Expected or reference output for the run. Optional — used by ablation’s placeholder="ideal" strategy and by judges that compare against a known-good answer. |
metadata | dict | Arbitrary key/value metadata for the trace (e.g. session_id, model_name, pipeline_version). |
Methods
Serialisation
TraceNode
One span in the execution trace.| Field | Type | Default | Description |
|---|---|---|---|
name | str | required | Human-readable span name. Not required to be unique — use id for stable identity. |
input | Any | None | The span’s input. Any JSON-serializable value. |
output | Any | None | The span’s output. Any JSON-serializable value. |
id | str | "" | Unique identifier within this trace. Auto-assigned as n0, n1, … if left empty. Required when using parent_id wiring. |
parent_id | str | None | None | id of the parent span. None means this is a root span. Parallel siblings share the same parent_id. |
kind | str | "other" | Span kind — see Span kinds below. |
prompt_id | str | None | None | Identity of the underlying prompt. Multiple spans may share a prompt_id (e.g. the planner prompt at each reasoning step). Reflex uses this to optimize the prompt once and have the update apply to every call site. |
step | int | None | None | Logical step index in a plan-act loop. None for simple linear traces. |
optimize | bool | False | Mark this span’s prompt as a Reflex optimization target. When multiple spans share a prompt_id, set optimize=True on all of them. |
tokens | int | 0 | LLM tokens consumed (prompt + completion combined). 0 for non-LLM spans. |
started_at | float | None | None | Unix timestamp (seconds) when the span began. |
ended_at | float | None | None | Unix timestamp (seconds) when the span ended. |
error | str | None | None | Short error message if the span failed. None on success. |
metadata | dict | {} | Arbitrary per-span key/value metadata. See Well-known metadata keys. |
Span kinds
| Constant | String value | When to use |
|---|---|---|
KIND_REASON | "reason" | An LLM reasoning or planning step |
KIND_TOOL | "tool" | A tool or function call (native or MCP) |
KIND_RETRIEVE | "retrieve" | A retrieval or memory lookup |
KIND_AGENT | "agent" | A nested sub-agent invocation |
KIND_OTHER | "other" | Anything else / unspecified |
Well-known metadata keys
| Key | Constant | Description |
|---|---|---|
"mcp_server" | META_MCP_SERVER | Name of the MCP server that exposed this tool (e.g. "github", "slack"). Signals “this is an MCP tool call”. |
"tool_call_id" | META_TOOL_CALL_ID | The LLM’s tool_use id, linking this tool span to the reasoning turn that dispatched it. |
"error_code" | META_ERROR_CODE | Machine-readable error code from a failed tool call. |
"latency_ms" | META_LATENCY_MS | Wall-clock duration in milliseconds, when started_at/ended_at aren’t available. |
Factory: TraceNode.mcp_tool()
Convenience constructor for MCP tool spans — pins the metadata
conventions so Origin and dashboards render them consistently:
DAG wiring examples
Linear pipeline — noparent_id needed:
p1 and p2 carry prompt_id="planner" and optimize=True.
Reflex will optimize the single planner prompt and the update applies
to every step.