Trajectory DAGs

AgentDiff translates a multi-turn execution sequence into a directed acyclic graph (DAG) of steps. Each node is a step (a tool call, an LLM call, a routing decision, or a thought); edges follow the parent-child flow of execution.

Canonical data model

AgentDiff uses Pydantic (v2+) for strongly-typed trace schemas.

AgentTrace - one run

FieldTypeNotes
schema_versionstrFormat version ("1.0.0").
trace_idstrUnique ID for the run.
agent_namestrName of the agent.
agent_versionstr?Optional agent version.
task_inputdictThe task given to the agent.
final_outputdict?The agent's final answer.
stepslist[TraceStep]Ordered execution steps.
total_latency_msfloat?Total duration in ms.
total_tokensTokenUsage?Aggregated token/cost metadata.
metadatadict?Free-form extra data.

TraceStep - one node

FieldTypeNotes
step_idstrUnique identifier.
parent_idstr?Parent step id (defines hierarchy).
step_indexintSequential position in the run.
step_typeStepTypetool_call, llm_call, routing, or thought.
namestrAction name, e.g. web_search.
input_payloaddictArguments to the step.
output_payloaddict?Return values.
statusStepStatussuccess, error, retry, or abandoned.
error_messagestr?Set when the step errored.
latency_msfloat?Duration in ms.
tokensTokenUsage?Token counts and cost.
metadatadict?Free-form extra data.

TokenUsage

prompt_tokens, completion_tokens, total_tokens, estimated_cost_usd.

Example (Generic format)

json
{ "schema_version": "1.0.0", "trace_id": "run-101", "agent_name": "WeatherAgent", "task_input": { "query": "weather in NYC" }, "final_output": { "answer": "It is sunny and 75F in NYC." }, "steps": [ { "step_id": "step-1", "step_index": 0, "step_type": "tool_call", "name": "geocode_city", "input_payload": { "city": "NYC" }, "output_payload": { "lat": 40.71, "lng": -74.0 }, "status": "success", "latency_ms": 120.0, "tokens": { "prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0, "estimated_cost_usd": 0.0 } }, { "step_id": "step-2", "parent_id": "step-1", "step_index": 1, "step_type": "llm_call", "name": "generate_report", "input_payload": { "lat": 40.71, "lng": -74.0 }, "output_payload": { "report": "sunny, 75 degrees" }, "status": "success", "latency_ms": 1100.0, "tokens": { "prompt_tokens": 150, "completion_tokens": 80, "total_tokens": 230, "estimated_cost_usd": 0.0035 } } ], "total_latency_ms": 1220.0, "total_tokens": { "prompt_tokens": 150, "completion_tokens": 80, "total_tokens": 230, "estimated_cost_usd": 0.0035 } }

Working with the graph in Python

Load a trace and inspect it as a NetworkX graph:

python
import networkx as nx from agentdiff import load_trace trace = load_trace("run.json") # auto-detects the format digraph: nx.DiGraph = trace.to_networkx() print(list(nx.topological_sort(digraph)))

You can also parse raw dict data without a file:

python
from agentdiff.loader import parse_trace_data trace = parse_trace_data(raw_dict, adapter_name="generic")

See Ingestion Adapters for the supported formats.