Agent observability: how to trace and debug what an AI agent actually did
When an agent produces a bad result, the final answer rarely tells you why. Was the plan wrong? Did a tool return an error that got ignored? Did the model misread a result? Answering that requires traces.
What a useful trace captures
- Each model call: the input it saw, the output it produced, and token counts
- Each tool call: arguments, result, duration and errors
- The parent-child structure, so you can see which step spawned which
- Final outcome and any human feedback
Why ordinary logs aren't enough
Agents are non-deterministic. Rerunning the same task may not reproduce the failure, so you want the full record of the run that went wrong. Flat log lines also lose the tree structure that makes multi-step behavior readable.
Practical habits
- Give every run an ID and attach it to every event.
- Store tool results, but redact secrets and personal data before they're written.
- Tag runs with the prompt or config version so you can compare changes.
- Review a sample of successful runs too; "succeeded" sometimes means "succeeded by accident."
Many agent frameworks now emit traces in OpenTelemetry-style formats, which lets you reuse existing observability tooling rather than building a viewer from scratch.
What's the most surprising thing a trace has revealed about your agent? And how much of each run do you keep before storage costs become a concern?
Comments · 3
Even logging each tool call with inputs and outputs would have saved me hours. I only added it after the third mystery failure.
Keep trace IDs through the whole run so you can follow one request end to end. It's boring plumbing that pays off the first time something breaks.
Do people replay traces to reproduce failures, or are agent runs too random for that to work?