# Recording agent runs

> To investigate a failure, I need records of tool calls, model calls, retries, and state changes.

Source page: https://alexcinovoj.dev/proof/ai/observability
Markdown: https://alexcinovoj.dev/llms/proof/ai/observability.md

## 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.

## About this method

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.

## Steps

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

## 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.

## 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.
