What to trace in an agent, and who should be able to read it

Four different readers come to an agent trace with the same question, which is why the agent did what it did. Record each decision with the inputs the agent saw and the action it took, then build a view for every person who has to act on it.

By Nabil Ahmed8 minute read

The lunar surface near 36°S, 27°W, lit by a low Sun with night falling across one side.
The Moon near 36°S, 27°W. Rendered by Farside from NASA Lunar Reconnaissance Orbiter elevation data.

A conventional service tends to fail in ways its logs were built to capture, such as a request that times out on a query, with a stack trace pointing to the line responsible. Agents fail in another way. Every call can return successfully and every tool can respond while the agent still issues a credit note to the wrong account, because at step four it read a search result that looked right but was wrong. An error log has no entry for that, since no error occurred.

Most teams learn this after their first incident, when the model provider's request logs cannot be joined with the application's logs into an account of what the agent believed when it acted.

We treat the trace as part of the product from the start, rather than a debugging aid added later. That means deciding what gets recorded, and who needs to read it, before the agent is given write access to anything. An engineer, an operations lead, an auditor and a support agent will all ask why the agent did something, and each needs a different answer from the same record.

In brief

  • At every step an agent trace should record what the agent saw, what it decided and what it changed, because agent failures are usually wrong decisions and seldom errors.
  • Each tool call needs its full arguments and result, the identity it ran under, and whether it changed anything in a system of record.
  • Every run should carry its prompt, model and tool versions, since without them a regression cannot be told apart from a one-off.
  • A trace has at least four readers (engineer, process owner, auditor, support), and a raw span viewer is useful only to the first of them.
  • Because a trace contains whatever the agent read, its redaction, access control and retention have to be designed along with it.

What an agent trace has to record

A trace is the complete, ordered record of one unit of work, from the request that triggered it to the last action it caused. Distributed tracing builds a trace out of spans, which are timed operations nested inside each other, each with a start, an end and attributes. For an agent the whole run is the trace, and every model call, tool call, retrieval and human approval inside it is a span.

Agent tracing differs from service tracing in what the attributes hold. Timing matters least for an agent, while content matters most, meaning the exact text the model received and returned and the exact arguments passed to each tool. An agent's behavior follows from its context, so a trace that leaves the context out cannot explain what the agent did.

Most tracing tools use the span model defined by OpenTelemetry, the open-source observability project hosted by the Cloud Native Computing Foundation. If you build on it, your agent's spans can sit in the same trace as the API calls and database queries they set off. The standard defines the envelope, and what goes inside it is your decision.

What to capture at each step

For every field, ask whether someone a month from now would need it to explain the run.

Step Record Why it matters later
Run start Run ID, triggering user or event, the task as given, agent version, prompt version, model name and version, tool manifest version Lets you group runs by version and find when behavior changed
Model call Full input (system prompt reference, messages, tool definitions), full output, token counts, latency, stop reason The input is what the agent believed; the output is what it decided
Retrieval Query text, document IDs and versions returned, scores, the permission context used Shows whether a wrong answer came from wrong search results
Tool call Tool name, full arguments, full result or error, identity used, read or write, idempotency key, target record IDs The only reliable account of what changed in a system of record
Guardrail or policy check Which check, input, verdict, the rule that fired Shows what was blocked and why, and what was allowed through
Human approval Who was asked, what they were shown, what they decided, when Separates the agent's decision from the person's
Run end Final outcome, stated reason, total cost, total steps, how it ended (complete, handed off, step limit, error) Makes runs countable and comparable

Three of these fields are often missed.

The versions of prompt and tools belong on the trace because a prompt edit is in effect a deployment. Without them you cannot say when a behavior started, which is usually the first question in an incident.

The write flag should mark every tool call as a read or a write, and each write should list the IDs of the records it touched. After a failure the most urgent question is what has to be undone, and a query over the write spans answers it.

The way the run ended matters because an agent that stops at its step limit without an error looks like a success on a dashboard counting only errors.

Trimmed to the fields that matter, a tool-call span looks like this:

{
  "trace_id": "run-7f3a",
  "span_id": "s-06",
  "parent_span_id": "s-05",
  "kind": "tool_call",
  "tool": "erp.create_credit_note",
  "tool_version": "2.3.0",
  "effect": "write",
  "acting_identity": "svc-credit-agent (on behalf of user 4471)",
  "arguments": {"customer_id": "C-10482", "invoice_id": "INV-88213", "amount": 412.50},
  "idempotency_key": "run-7f3a:INV-88213:credit",
  "result": {"status": "created", "credit_note_id": "CN-5521"},
  "records_touched": ["CN-5521", "INV-88213"],
  "duration_ms": 640
}

Some models also produce a reasoning summary, which is worth recording if it is labeled as the model's own account, because it is generated text that may not reflect what actually drove the output. The recorded inputs and actions are the facts.

The credit note that went to the wrong customer

Consider a mid-size distributor that uses an agent to handle claims for short shipments. When a customer emails to say an order arrived two cases short, the agent reads the email and looks up the customer and the invoice in the ERP before checking the warehouse dispatch record. It issues a credit note if the claim is below a set value and passes larger claims to a person.

One morning a customer phones about a credit note they never asked for, while another customer with a similar name is still waiting for theirs.

With this trace, the investigation is a single read through one run. The customer lookup span shows that the agent searched on the company name from the email signature, and its result shows two matches for a parent company and a subsidiary with almost identical names. The next model span shows the agent picking the first match, and the tool-call span shows a write against the wrong customer ID. The version stamps on the run show that the lookup tool had changed the week before to return a list instead of a single best match.

The record points directly to the fix. The lookup tool goes back to requiring an exact customer number or returning an explicit "ambiguous" result, and the agent is instructed to hand the claim off whenever it receives one. A query over the write spans, filtered to runs since the tool version changed in which the lookup returned more than one match, lists every other credit note that needs checking. The run itself becomes a case in the nightly test set. This is why tracing and evaluation belong together, since production traces are the natural source of test cases, as we argue in the test set that runs every night.

Four readers, four views

In raw form a trace is a tree of spans holding large blocks of text, which few people outside engineering will read. Everyone who has to act on a trace needs a view designed around their question.

The engineer wants to know what the agent saw at the step where it went wrong. That calls for the full span tree with the complete prompt and response for each model call, along with the ability to replay a step with the same inputs. Replay works only when the inputs were stored in full, which is the main argument against truncating them.

The process owner wants to know whether the agent is doing its job, a question answered by outcomes more than spans. They need to see how many runs completed or were handed off and why, which step limit or tool error ends the most runs, and what each run cost. This is an aggregate view built from the run-end records.

The auditor or risk reviewer asks what was done and on whose authority, and whether a control worked. They need a readable timeline of a single run showing the request, the records read, the action taken under a given identity, and who approved it at what time. If your agent includes an approval step, the trace must also show what the approver was shown, because approving a misleading summary gives little real control. How to design that step is covered in designing human approval into agent systems.

The support agent asks what happened to a particular customer's request, and needs to search by customer or case number instead of by run ID, which works only if business identifiers are attached to each run from the start.

All four views have to read from the same underlying record. If the auditor's timeline and the engineer's span tree are built from different sources, they will eventually disagree.

Traces hold sensitive data, so design for that

When a trace records full inputs and outputs, it holds everything the agent read, including customer names, account details and contract text, which makes the trace store one of the more sensitive systems you operate.

Four practices keep this manageable:

  1. Redact at capture, field by field. Mask or tokenize any field holding personal or regulated data before the span is written, because redacting afterwards means the raw data sat in the store first.
  2. Separate access by view. Message content is needed only for the engineer's replay, so limit that access to a small named group whose reads are logged.
  3. Set retention according to purpose. Full content for debugging may be needed for a few weeks and the record of actions for years, so store them so that one can expire without the other.
  4. Keep secrets out of the trace entirely. Tools should get their credentials from the runtime instead of the model's context, so they never appear in arguments. This is one more reason to give an agent one job and only the keys it needs.

The tension here does not resolve cleanly, because the full content that makes debugging possible is also what makes the store sensitive. Our default is to capture in full, redact known sensitive fields and restrict access tightly, since a trace too thin to explain a failure is of little use.

Where to start

If you are building or reviewing an agent that acts in enterprise systems, these steps are in priority order:

  1. Give every run a single ID and pass it to every tool call and downstream API, so the agent's trace joins your existing service traces.
  2. Record the full inputs and outputs of model calls and the full arguments and results of tool calls. Add the read or write flag and the records touched.
  3. Stamp every run with the agent, prompt, model and tool versions.
  4. Record how each run ended (including step limits and handoffs) and make the counts visible to the process owner.
  5. Take a real past incident or invent a plausible one, then try to explain it from the trace alone. Anything you had to look up elsewhere points to a missing field.
  6. Ask someone outside engineering to find out what happened to one customer's request, and if they cannot, build the timeline view before widening the agent's permissions.
  7. Document the redaction rules and who may read content, along with how long each part is kept, as part of the plan for running the agent in production alongside the rest of your observability and incident response.

The fifth step tells you the most, because a trace is good enough once someone who was not involved can explain the run from it.

Related services

Start a conversation.

A short paragraph is enough. A principal reads every message and replies within one working day.

Or email hello@farside.works. We use what you send only to reply. Privacy