Plain Reckoner
English
← The blog

Agent workflows

AI Agent Failed? Find the First Bad Step With Tracing

Use AI agent debugging and LLM tracing to find unsupported decisions, tool errors and false completion claims. Keep private data out of your logs.

By Plain Reckoner Team · Release date: 2026-11-04

Selected source checked:

How do you debug a failed AI agent? Start with the expected outcome, then trace decisions and tool results to find where observed behavior first diverged. Record only the data needed for the investigation.

Imagine a support assistant tells a customer that a refund went through. The payment system shows no refund. The last message tells you what the assistant claimed; the next question is where the two accounts diverged. Was approval missing, a tool call rejected, or the payment status never checked?

A trace can connect the request to each decision and tool result. It also needs limits: a useful investigation does not require sending every customer message or payment detail to a logging service. The refund example in this guide is fictional; use it to practice following the evidence, not as a record of a customer incident.

Microsoft Research's AgentRx project studies how to identify critical steps in failed agent runs. Later in this guide, you can inspect a related example and a trace-privacy setting. Our checklist is separate guidance: a tracing tool can collect evidence, but someone still has to interpret what happened.

In this guide
  1. Start with the outcome that was wrong
  2. Connect each step to the same job
  3. Capture the boundary, not every secret
  4. Separate tool errors from empty answers
  5. Find the first unsupported transition
  6. Include timing and cancellation
  7. Track versions that can change behavior
  8. Build a replay that cannot repeat harm
  9. Compare a fix with the original failure
  10. Make dashboards answer specific questions
  11. Give every investigation a useful ending

Start with the outcome that was wrong

Before opening a dashboard, write one sentence describing the failure from the user's point of view. In our example, the assistant told a customer that a refund had been processed, but the payment system showed no refund. That is more useful than “the agent hallucinated.” It names an observable claim and an external state that disagrees with it.

Record the expected outcome too. Was the assistant supposed to issue a refund, prepare a request for human approval, or only explain the policy? Those are different tasks. If its instructions allowed only preparation, a completed refund would not even be the correct success condition. Debugging against an unclear goal can reward the wrong behavior.

Keep the first report short: request time, affected workflow, claimed result, observed result, and how that observation was checked. Use internal identifiers rather than copying the customer's message into an issue tracker. If you cannot yet establish the external state, label it unknown. An investigation should preserve uncertainty until evidence resolves it, especially when payments or other lasting changes are involved.

Connect each step to the same job

A useful trace has a stable job identifier that follows the request through the application, model calls, tools, and background work. Each step also needs its own identifier and a link to its parent. That relationship lets you distinguish a tool launched by this task from an unrelated request that happened at the same time.

For the refund example, the chain might include checking the policy, finding the transaction, requesting approval, submitting the refund, and checking its status. A flat stream of timestamps cannot always show which response belongs to which attempt. Parallel calls and retries make that ambiguity worse. Preserve the relationship explicitly rather than asking the investigator to reconstruct it from prose.

Choose identifiers generated by the application. A model-generated label can be useful for display, but it should not determine the underlying identity of a financial action. Keep the public support reference separate from sensitive internal identifiers when necessary. The goal is to connect evidence across systems with a controlled lookup, not to make every internal detail visible to everyone who receives a support link.

Capture the boundary, not every secret

For each tool step, record what operation was requested, whether validation accepted it, its start and end time, and the classified result. Record the tool version or contract version when it changes behavior. These fields often explain a failure more clearly than a large block of raw conversational text.

Avoid treating complete prompt collection as the default. Prompts may contain customer records, credentials accidentally pasted by a user, or documents that a tracing vendor should not receive. Decide which fields are necessary, redact before exporting, and set retention and access rules. A promise to clean sensitive data later does not prevent its initial disclosure.

In our example, an investigator may need to know that approval was missing, the request failed validation, and the refund status remained unchanged. They probably do not need the customer's full address or payment details. Where a payload must be examined, use a restricted evidence store and a reference from the trace. Test redaction with representative fake secrets so the privacy control is checked rather than merely documented.

Find the first unsupported decision
01
Define the failure
02
Connect the steps
03
Locate the break
04
Replay safely

Separate tool errors from empty answers

A search result containing zero records and a search operation that could not run must have different representations. If both become an empty list, the agent cannot reliably tell “nothing matched” from “I was not allowed to look.” The resulting answer may sound confident while resting on missing evidence.

Use typed outcomes such as success with records, success with no records, permission denied, invalid request, timeout, and upstream failure. The names are an application choice; the important property is that the caller can distinguish them. Preserve the original classified cause through wrappers instead of replacing every error with a generic fallback value.

Now revisit the refund example. A permission failure when reading the payment status should lead to an unresolved status, not a claim that no refund exists. A timeout while issuing the refund should lead to reconciliation, not an automatic claim of failure or success. Inspect how the agent interprets each outcome. Sometimes the right fix is a clearer tool contract, not another instruction telling the model to be careful.

Find the first unsupported transition

Work forward from evidence that you trust. At each step, ask whether the next decision follows from the information actually available at that moment. The first unsupported transition is often more useful than the final visible error. Later mistakes can be consequences of that earlier break.

Suppose approval was requested but never granted. The next step nevertheless submitted the refund, and the final answer said it succeeded. There are at least two problems: an authorization boundary and a completion claim. Fixing the final wording would leave the more serious control failure intact. A good investigation identifies both and prioritizes the boundary that should have prevented the action.

Do not assume the earliest unusual event caused the outcome. A slow search call may look suspicious but be unrelated. State your hypothesis and the evidence that would disprove it. For example: if the approval gate is the cause, a run with no approval should stop before the payment tool. That produces a concrete regression check instead of a narrative that merely fits the log.

Include timing and cancellation

Timing changes meaning. A tool can finish after the user cancels, after the parent request times out, or after another attempt has already completed the job. If the trace records only successful responses, you may miss the abandoned work that produced a duplicate action or an inconsistent interface.

Capture deadlines and cancellation requests separately from final outcomes. A cancellation signal is a request to stop; it is not proof that an external operation stopped. When a tool supports cancellation, record whether it acknowledged the request. When it does not, keep the pending operation visible until its state can be checked.

For our imaginary refund assistant, a page timeout must not erase the payment operation's identity. The application needs enough information to ask the provider what happened. Present a pending state if the outcome remains uncertain. This is a product design decision as well as an observability decision: the user needs a safe next step while the system resolves the ambiguity, and the investigator needs the same operation linked across that interval.

Track versions that can change behavior

A trace without version information can be difficult to reproduce. The same user request may behave differently after a prompt edit, a tool schema change, a model update, or a policy document refresh. Record the versions that your application controls and the model identifier returned or used by the provider.

Keep configuration references compact. A commit identifier, prompt revision, tool contract revision, and retrieval index version are often more useful than copying the entire configuration into every event. Store the referenced artifacts through an access-controlled process so the identifiers remain meaningful later. Do not include secret environment values in that snapshot.

Also record what you cannot pin. A hosted service may change behind a stable endpoint, and a replay may not reproduce the original model response. Say so in the investigation. Reproduction can still test a deterministic boundary, such as rejecting an unauthorized tool call, even when the original generation is not reproducible. Distinguishing those two goals prevents a model's variability from becoming an excuse to leave enforceable controls untested.

Build a replay that cannot repeat harm

Replaying a trace should not silently send another email, issue another refund, or overwrite production data. Separate investigation from execution. Replace external side effects with recorded responses or controlled test adapters, and make that mode explicit. A replay tool that defaults to live actions can turn a debugging session into a new incident.

Start with the smallest segment that demonstrates the suspected defect. In our example, feed the approval state and proposed refund call into the application gate. You do not need to regenerate every earlier message to check whether that gate rejects missing approval. Smaller reproductions are easier to understand and less likely to expose unrelated private data.

Use synthetic fixtures when sharing the case outside the team. Preserve the relevant structure while removing identifying content, and explain which details changed. A useful public reproduction includes the expected behavior, the observed failure, the controlled setup, and the limitation. It should let another developer inspect the reasoning without granting access to the original customer interaction or requiring a production credential.

Compare a fix with the original failure

After changing the code, rerun the failing case through the relevant boundary. Confirm that the old behavior is rejected and the intended behavior remains possible. A refund approval gate that blocks every request would stop the reported failure while breaking the feature. Include an authorized case alongside the unauthorized case.

Check neighboring cases that share the same cause: expired approval, approval for a different transaction, a cancelled request, and a delayed tool response. Keep the set focused. The purpose is to challenge the assumption behind the fix, not to generate a large test count that looks impressive in a report.

Then inspect the final user message. It should accurately reflect the operation's state and the evidence available. If the tool result remains pending, the answer should not say completed. If the system blocked an action, explain what the user can do next. A complete fix aligns the enforced workflow, the stored state, and the message shown to the user; correcting only one can leave the original confusion in place.

Make dashboards answer specific questions

Useful AI observability starts with questions your team actually needs to answer. Which tool fails most often? How many jobs remain unresolved after a timeout? Which release changed the rate of unsupported completion claims? A dashboard built around these questions is easier to act on than a wall of token counts and colored spans.

Define the denominator for every rate. Failed tool calls divided by all calls measures something different from jobs affected by at least one tool failure. A single job with twenty retries can dominate a call-based chart. Show the distinction when it matters, and avoid presenting a lower error rate as an improvement if traffic or task mix changed.

Keep samples available for investigation under appropriate access controls. Aggregate numbers tell you where to look; individual traces explain what happened. Neither replaces the other. Review whether instrumentation itself is dropping failed or cancelled requests. A dashboard that captures only completed jobs may look healthier precisely when the most difficult jobs are disappearing before they can be recorded.

Give every investigation a useful ending

Close an investigation with a small evidence package: the failed user outcome, the critical transition, the supporting trace references, the fix, the checks performed, and what remains uncertain. Name an owner for any unresolved follow-up. This makes the work reusable when a similar symptom appears later.

Avoid broad claims such as “hallucinations fixed.” State the boundary you changed: the application now rejects refund execution without matching approval, or the answer renderer no longer treats a timeout as confirmed completion. These narrower statements are easier to verify and less likely to mislead colleagues deciding whether another workflow is safe.

For your next debugging session, begin with one failing job and one clear outcome. Connect its steps, distinguish errors from empty results, find the first unsupported decision, and test that boundary with harmless fixtures. Add instrumentation where evidence is missing. That sequence gives tracing a purpose: reducing uncertainty about a real failure and showing whether a specific repair addresses it.