This repository is part of the Reliable Long-Running Agents (RLRA) research initiative.
Trajectory telemetry, tracing, and failure analysis for AI agents.
Boundary. AgentTrace captures operational execution. It does not infer semantic state or evaluate correctness.
Siblings in the RLRA stack — TypedMem · AgentCheck · AgentTrace · ReliAgent Bench · AgentLab
AgentTrace captures the full path from user goal to final result — planning, model calls, tool use, memory access, retries, errors, cost, and state changes — and records it as a causal graph rather than a flat log. Instead of what happened, it can answer why did the agent do this, and how did it get here?
Think Git + OpenTelemetry + DevTools for a single agent run.
Logs answer what happened. Debugging an agent needs why:
- Which memory caused this decision?
- Which tool produced the wrong information?
- Where did a bad answer first go wrong?
- Which retry fixed it — and what did the run cost?
The difference is structure. A log is a list; an agent trajectory is a DAG where
every output has provenance (the events it depends on) and state changes are
explicit (before → after), not side effects hidden inside memory.append(...).
Everything an agent does is a TraceEvent that names its causal parents:
user_input → goal_created → planner_step → memory_read ┐
└→ tool_call → error → retry → tool_call → tool_result ┐
reasoning_step ← ──────────────────────────────────────────────────────────────────────┘
└→ state_transition (healthy → unhealthy) → llm_completion → agent_output
Each event carries parent_ids, actor, inputs/outputs, latency_ms, cost,
and (for transitions) state_before / state_after. Types: goal_created,
planner_step, reasoning_step, memory_read/memory_write, tool_call/
tool_result, observation, model_call/llm_completion, reflection, retry,
branch/merge, state_transition, evaluator, agent_output, error.
pip install -e .
python examples/emit_trace.py # records a run with a failure, retry, and belief flip
agenttrace show traces/demo.jsonl # the causal timeline
agenttrace why traces/demo.jsonl <id> # an event's full provenance
agenttrace view traces/demo.jsonl -o traces/demo.html --openfrom agenttrace import Tracer, TraceGraph, TraceQuery
tr = Tracer.to_file("traces/run.jsonl")
goal = tr.goal("answer the question")
mem = tr.memory_read("prefs", outputs={"unit": "metric"}, parents=[goal])
tool = tr.tool_call("web_search", inputs={"q": "..."}, parents=[goal])
ans = tr.output("...", parents=[mem, tool])
q = TraceQuery(TraceGraph.from_events(tr.events))
q.why(ans.event_id) # how the agent got here (provenance, causal order)
q.memory_influence(ans.event_id) # which memory actually fed the answer
q.root_cause(ans.event_id) # earliest error on the path to this eventagenttrace
├── events.py # TraceEvent + EventType (the causal schema)
├── tracer.py # instrumentation SDK — auto-linked parents + typed helpers
├── collector.py # append-only JSONL storage + read-back
├── graph.py # TraceGraph — DAG builder, ancestors/descendants, topo, validate
├── query.py # TraceQuery — why / affected_by / memory_influence / root_cause / cost
├── viewer.py # self-contained HTML viewer (provenance highlighting)
└── cli.py # agenttrace show / why / view
- Which trajectory patterns predict failure before completion?
- Can trace features identify root cause automatically?
- Can a trace become an executable artifact — replayed, diffed, and mined to improve future behavior — rather than just a debugging artifact?
- Can observability data improve test selection (feeding AgentCheck)?
Complementary, not overlapping. TypedMem
answers what is true now (persistent state); AgentTrace answers how did we get
here (operational execution history). A trace records every memory_read,
memory_write, and state_transition; TypedMem can provide the underlying state model.
StateGraph is the semantic counterpart. AgentTrace records operational provenance — what happened (tool calls, retries, memory reads, latency, cost). StateGraph records semantic provenance — what the agent believed, why the belief changed, and which decisions depended on it. They are kept as separate representations on purpose: StateGraph's core experiment measures semantic provenance against an operational baseline, so both must exist independently.
AgentTrace what happened operational provenance
StateGraph what was believed semantic provenance
v0.2 — recording & inspection works end to end. Causal schema, Tracer SDK,
JSONL storage, DAG builder, query API, HTML viewer, and CLI are implemented and
tested (pytest). Next: trace diff, a failure taxonomy over the graph, a latency
waterfall in the viewer, and an OpenTelemetry bridge — see ROADMAP.