Skip to content

Agent observability: traces, replay and gates

What to record so agent behaviour can be explained, replayed and safely changed.

8 MIN READUPDATED 2026-11-18Evaluation & safety
ORIGINAL DIAGRAM · 4 STEPS1Emit a span for2Record prompt/model ver…3Link spans with a4Score traces for quality

Original flow diagram from note steps — not a copied image

§ 01Key concepts
SpanOne unit of work: a model call, tool call or retrieval step.
TraceThe full tree of spans for one request or agent run.
ReplayReconstructing a past run from recorded inputs and versions.
Ship gateA pre-merge check on cost, behaviour and exposure before a change goes live.
§ 02When to use
  • Agents act on production systems.
  • You must explain or audit a decision.
  • Costs and latency need step-level attribution.
§ 03How it works
  1. 01Emit a span for every model call, retrieval and tool execution.
  2. 02Record prompt/model versions, tool arguments, outputs and latency.
  3. 03Link spans with a run ID across agents and hand-offs.
  4. 04Score traces for quality and gate changes on cost and behaviour deltas.
§ 04Use cases & scenarios

Explaining an agent's decision

Context
A customer disputes why an order was refunded.
Problem
Plain logs cannot reconstruct the agent's reasoning path.
Approach
Trace every model and tool span with prompt and model versions, then replay by run ID.
Outcome
Support can show exactly what happened and why.

Cost spike after a release

Context
A deploy doubles inference spend.
Problem
There is no way to tell which step became expensive.
Approach
Attribute spans by step and compare cost and latency deltas in a ship gate.
Outcome
The offending step is found and future regressions are blocked.
§ 05Examples

Span record for a tool call

json
{
  "run_id": "run-8821",
  "span": "tool.lookup_order",
  "prompt_version": "v7",
  "model_version": "pinned-small@3",
  "args_redacted": { "order_id": "ORD-104200" },
  "latency_ms": 180,
  "outcome": "ok"
}

Redact secrets and personal data before storage, but keep versions so a past decision can be replayed.

Replay a run by ID

sql
SELECT span, prompt_version, model_version, args_redacted, outcome, latency_ms
FROM agent_spans
WHERE run_id = :id
ORDER BY started_at;

Query traces by run, feature and customer. A trace with missing versions cannot be reproduced.

§ 06Trade-offs

Full capture

Up: Complete replay and audit

Down: Storage cost and privacy handling

Metadata only

Up: Lower risk and cost

Down: Cannot reconstruct past decisions

Sampling

Up: Cheaper at scale

Down: Misses rare failures

§ 07Implementation checklist
  • Redact secrets and personal data before storage.
  • Keep prompt and model versions with every span.
  • Record failed and retried calls, not just successes.
  • Make traces queryable by run, customer and feature.
§ 08Configuration reference
KeyTypical valueNote
capture_textpolicy-drivenOff by default where data is sensitive.
retentiondocumentedAlign with your policy.
ship_gatescost + behaviourRun before merge.
§ 09Troubleshooting
SymptomCauseFix
Trace has gapsSpans emitted after process exitFlush before shutdown.
Cannot reproduce a decisionMissing prompt/model versionsRecord versions with each span.
§ 10Frequently asked questions

Is observability the same as logging?

No. Logs are flat; traces reconstruct the full decision path across models, tools and agents.

What should a ship gate check?

At minimum: cost and latency deltas, behaviour changes on the golden set, and new tool permissions or exposure.

More in Evaluation & safety