Lesson 7 of 9 · 24m
Observability for Agent Runs
Instrument runs with structured traces, decision snapshots, tool evidence, costs, and replayable artifacts rather than relying on chat logs.
Chat transcripts are terrible observability. They show what the system said, not why it acted, which state it saw, which policy allowed the action, or what the tool actually did. When an agent causes a production issue, "the model decided to" is not a root cause. You need traces built for a control loop.
Trace the unit of work
A run should have a stable identifier and child identifiers for steps, model calls, validation decisions, and tool executions:
{
"run_id": "run_01JCX8...",
"step": 7,
"event": "tool.completed",
"tool": "refund_invoice",
"duration_ms": 412,
"input_digest": "sha256:9d1...",
"output_digest": "sha256:02a...",
"policy_decision": "allowed",
"cost_usd": 0.013
}Store payloads separately with redaction and retention rules. Digests let you prove what was sent without putting sensitive data in every log pipeline.
Capture decision snapshots
At each decision point record the compact state view, the available tools, the selected action, and validation results. You do not need every token of model reasoning. You need enough context to reconstruct why the system thought the action made sense.
run id, step, timestamp
state version / observation digests
candidate action and arguments
policy result, schema result, risk classification
model/provider/version and prompt template version
tool result classificationThis makes debugging empirical. You can answer whether the model saw stale state, whether validation was absent, or whether a tool returned misleading output.
Metrics that matter
Token count is not the only cost. Track operational and safety signals:
runs started/completed/stopped/escalated
steps per run and wall-clock distribution
tool error rate by error code
retry count for mutating operations
confirmation approval/edit/rejection rate
loop-detection interventions
human override rate
cost per successful outcome, not per invocationA fall in completion rate paired with rising confirmations may mean the agent became more honest, not worse. Interpret metrics with product context.
Replay beats screenshots
Store enough artifacts to replay or inspect runs: input task, plan revisions, tool schemas, prompt template versions, policy configuration, and environment versions. For browser or desktop agents, annotated traces and recordings help, but structured state transitions remain the spine.
Alert on behavior, not only crashes
Agents can be dangerously successful. Alert when write volume spikes, one user triggers unusual tool distribution, repeated unknown outcomes occur, or a run approaches budget limits. A process can be healthy at the HTTP level while actively making a mess.
Field notes
- Never log raw secrets because they appeared in tool arguments. Redaction belongs at the instrumentation boundary.
- Include the model and prompt/template version in traces; behavior cannot be reproduced without them.
- Sampling is fine for routine traffic, but never sample away failed, stopped, or escalated runs.
- Build the incident view before launch. During the incident is too late to discover that traces span six incompatible dashboards.
Was this lesson helpful?