alexcinovoj.devby TechTide AI
Back to AI notes
Pattern · AI agent testing

Recording agent runs

To investigate a failure, I need records of tool calls, model calls, retries, and state changes. A shared trace ID connects those records. Missing or sampled-out events limit what I can reconstruct.

Short answer

What should I record to investigate an agent failure?

To investigate a failure, I need records of tool calls, model calls, retries, and state changes. A shared trace ID connects those records.

Implementation

  • Assign a trace ID at the request boundary and propagate it through every tool call.
  • Record model calls with provider, model, token counts, and cost.
  • Record tool calls with arguments, result status, and duration, with secrets redacted at write time.
  • Emit state transitions as events, so the run's shape is reconstructable without replaying the model.
  • Retain traces long enough to cover your incident review window.

What can go wrong

  • Redacting only when displaying a trace leaves the raw secret in storage.
  • Sampling can discard the records needed to investigate a failed run.
  • Traces without tool arguments can leave the cause of a failure unclear.

Checks to try

  • Pick a random failed run and reconstruct it end to end using only stored records.
  • Grep the trace store for credential-shaped strings.

Questions this pattern answers

What should I record to investigate an agent failure?

To investigate a failure, I need records of tool calls, model calls, retries, and state changes. A shared trace ID connects those records.

What steps does this method use?

Assign a trace ID at the request boundary and propagate it through every tool call. Record model calls with provider, model, token counts, and cost. Record tool calls with arguments, result status, and duration, with secrets redacted at write time. Emit state transitions as events, so the run's shape is reconstructable without replaying the model. Retain traces long enough to cover your incident review window.

How can I check the result?

Pick a random failed run and reconstruct it end to end using only stored records. Grep the trace store for credential-shaped strings.

What can go wrong with this approach?

Redacting only when displaying a trace leaves the raw secret in storage. Sampling can discard the records needed to investigate a failed run. Traces without tool arguments can leave the cause of a failure unclear.

Related projects

Related patterns

I explain this method here. Current service scope, prices, and terms are on TechTide AI.

Systems Decision Audit at TechTide AI