Learning / Agentic Operations / Lesson 0012
Tracing & the Planted Regression
You debug agents by reading traces. So first you build the trace — then an eval that catches a bug you hid.
1 · Instrument a real trace
A trace is the full trajectory of a run: every model call, tool call, and retrieval, with inputs, outputs, and timing (Lesson 0003). Extend the logging you've built since 0005 into one structured trace per run — one record per step:
{"run_id", "step", "type": "model_call|tool_call",
"input", "output", "tokens", "latency_ms", "ts_offset"}
Hosted tools (Langfuse, Arize, Opik) do this for you in production and add a UI — Vernant already has a langfuse-bridge in the tree if you want to wire the real thing. But build the JSONL version by hand first: the discipline is knowing what must be captured, and you only learn that by capturing it.
2 · Build a small eval set
Write 8–12 test cases for your agent: input + expected outcome. Then split scoring into the two M3 levels — because a right answer via a broken path breaks at scale (Lesson 0003):
- Outcome checks: is the final answer correct? (assert on the value)
- Trajectory checks: did it take a sane path? (e.g. "used the calculator tool for arithmetic", "made ≤ N model calls", "never read a note it didn't search for first") — assertions over the trace from step 1.
3 · Plant a regression — the lab
Introduce a bug that a naive outcome-only test would miss. Best kind: one that keeps answers right on easy cases but corrupts the path or fails on edge cases. Examples:
- Weaken the system prompt so the agent sometimes does mental math instead of calling the tool (outcome often still correct — trajectory now wrong).
- Cap the loop at 2 iterations (multi-hop questions now truncate).
- Silently drop
is_errorhandling (errors now corrupt instead of recover).
Self-grade — the M3 gate is nearly closed
- Trace is complete — every model/tool step with I/O + timing; run reconstructable from it alone, decisions explicable
- Eval has both levels — outcome and trajectory assertions, green on the good agent
- Regression caught — suite goes red on your planted bug; a trajectory assertion catches at least one plant
- You can debug from the trace — you found the broken step by reading, not re-running
Next
Lesson 0013 — the critic/verifier step: add a self-correction stage and measure how many silent wrong answers it kills; then the M3 readiness check.