Using Production Traces to Prioritize Tool and Memory Improvements
Live agent traces show which tool and memory fixes matter most.

A production trace-driven harness engineering workflow uses live agent runs to locate failures, rank tool and memory improvements by frequency and downstream impact, and validate fixes against historical cases before shipping. It uses evidence from each layer in place of guesses about the prompt. Continuous sampling closes the loop by turning newly discovered failure patterns into standing regression tests.
Why agent failures in production resist diagnosis without trace data
An engineer reruns the prompt, gets a passing result, and closes the ticket. Days later, a different user reports the same failure. The apparent recovery supplied no explanation for the original defect, so the team changed nothing that would prevent its return. In a multi-step agent run, an intermediate step can fail while the final output still looks complete. The complaint identifies a bad outcome while leaving the step responsible for it unresolved.
Final-output evaluation catches severe corruption but can miss a wrong tool choice, stale context, or a silently skipped validation step. These partial failures can leave an answer plausible enough to pass inspection. Plausibility is not evidence of a sound execution path. Without the intermediate inputs, decisions, and results, each incident defaults to “the model is broken,” even when the defect belongs to a tool interface or the way context was loaded.
Evaluation scores behavior at a point in time, while observability exposes drift between those points. Both need access to the same trace data so that a failing score can be connected to the execution that produced it. Otherwise, teams can count bad outcomes without locating an actionable cause. That gap prevents reliable prioritization before any backlog decision begins.
What a trace must record to be useful for diagnosis
Each span needs the model version and prompt template version that apply to it. Without them, a regression after a provider update is indistinguishable from one caused by a prompt change. Version history is part of the diagnostic evidence. A trace that records the execution but omits its system context leaves competing explanations unresolved, even when the failing step is visible.
Each span also needs its input and output. Tool spans need the tool name, arguments, and return status, including partial failures. Timestamps and per-step latency reveal where execution slowed or timed out. Retrieval spans need the context used, its source, and a similarity score where available. These fields connect the agent’s behavior to what it actually received.
OpenTelemetry has a standard schema for structured span data across most agent frameworks, but that format alone does not ensure that the data has enough detail. TelemetrySuffBench separates failure detection from failure-origin localization and shows why that distinction is necessary. Its coarse telemetry views still have high detection scores, but their origin-step accuracy is at most 0.5%. Detailed span instrumentation from the start costs less than retrofitting it after an incident exposes missing evidence.
In multi-agent systems, that detail must link the agents through a shared trace ID. A visible failure may occur two or three agents after the span where it originated. Separate agent traces cannot reliably explain that propagation without correlation. The diagnostic record must preserve both the local step and its place in the larger execution.
The failure categories traces expose in tool and memory layers
Tool execution failures are the most common category in multi-step agents. A tool may return an error, time out, or produce a response outside its expected schema. The agent can then proceed as though execution succeeded, creating downstream errors that appear unrelated to the tool. Schema drift is especially deceptive because corrupted output need not produce an exception. Each tool span’s return status and response shape are needed to check for these failures, even when the final answer looks correct.
Memory failures follow a different forensic path. An agent may use information that was accurate earlier in the session but is no longer valid, while reasoning consistently from that stale context. Detection requires comparing the retrieval attached to the failing span with what a current retrieval of the same query returns. The reasoning can be coherent and still be wrong. What appears to be model drift may instead be a harness-layer failure in how context is loaded or retained.
Planning and workflow failures require another distinction. A plan can be generated and all tools can execute without error while the result remains wrong, directing investigation toward planning or prompt behavior. A workflow failure happens when required steps are skipped or run out of order. Validating the trace sequence against an activity schema exposes those omissions and ordering violations. This is particularly consequential in compliance workflows, where successful tool execution does not establish that the required process occurred.
TRAJDEBUG, from Tsinghua and Tencent, distinguishes local errors from errors causally responsible for terminal failure. Some local errors are fixed during the trajectory, while others do no harm. Their presence alone does not establish urgency. The critical error is not necessarily the first error observed or the one closest to the final failure. Prioritization depends on whether each error was resolved and what its downstream effects were.
How to read the signal and attribute a failure to a specific layer
The primary method is to align a failed trajectory with successful runs of the same task and inspect where their steps diverge. Per-step scores for task completion, tool selection accuracy, groundedness, and reasoning quality make that divergence filterable. Manual review can then focus on the relevant spans. A comparison against ten passing trajectories narrows the search from an entire run to a particular step and the prompt or tool input that differed.
At a tool span, the comparison should distinguish execution status from contract compliance. A non-error return with an output outside the expected schema points toward the tool interface, including a schema mismatch or argument validation gap. The comparison then tests whether the passing runs respected a contract that the failed run violated. That directs attention away from a broad prompt rewrite and toward the interface evidence.
If planning looks correct and tools run without error but the result is still wrong, planning or prompt behavior still needs to be checked for ambiguity or task reasoning failure. If failure emerges only after many turns of previously consistent reasoning, stale context accumulation or context budget exhaustion becomes a candidate. If only a downstream agent shows the symptom, the shared trace ID provides the path back toward the originating span. These attribution heuristics leave the verdict open.
The divergence point must be traced through the feedback and attempts to fix the error that come after it. TRAJDEBUG shows that the evidence needed to judge a step can be spread across distant instructions, observations, and earlier context, so it takes multi-granularity history compression to judge the step using more than the local span alone. A step that looks wrong may have been fixed later. The attribution task is to distinguish that recovered error from an unresolved error whose effects reached the final result. Without this causal check, even a span label that looks precise can point to the wrong thing to fix.
How to turn production trace failures into a prioritized improvement backlog
Frequency is the first filter for a usable backlog. Aggregate per-step evaluator scores across the production trace corpus and identify recurring failures around the same tool or span cluster. A failure that appears twice for different users on the same span is a pattern. The backlog item should group the reports of that recurring pattern so they are handled together.
A shift in which tool the planner selects can indicate schema drift or prompt ambiguity before failure rates spike. The distribution change gives the team a reason to inspect the affected spans, while their scores and outputs show whether an actionable pattern exists. The next decision concerns what happens after the failure.
For patterns that keep coming back, downstream blast radius sets the order in which they should be addressed. An error that the agent consistently repairs ranks below a less frequent defect that reliably produces a terminal incorrect output or an irreversible action. TRAJDEBUG’s distinction between repaired, harmless, and propagating errors supports this separation. Group attributed patterns by tool interface, memory, planning, or workflow, then rank within each layer using frequency and blast radius together.
Risk overrides that ordinary ranking and routes the case to human review first. Irreversible actions, access to sensitive data, and output that reaches an external system require review regardless of frequency. “Ghost actions,” meaning steps the agent executed without being asked, are high-risk by default. The resulting decision sequence uses frequency to filter noise, blast radius to rank the surviving patterns, and risk to override the order when consequences demand it.
Validating fixes against historical traces before shipping
A proposed fix is not an improvement if it repairs the targeted failure while breaking a previously passing case. Production runs that are risky or show typical behavior become evaluation cases, and the proposed change is replayed against them with the same per-step evaluators used to find the cause. This keeps validation connected to the original evidence.
Harness iteration requires one variable to change at a time. Changing system prompt wording and tool descriptions together conflates two possible causes of any score movement. An improvement cannot then be attributed to either change, and a regression becomes harder to isolate. The evaluation score supplies a gradient signal only when the experiment preserves that distinction.
Replay has a narrower role than a general-purpose evaluation. A recorded conversation was produced under a particular system context, and its state may no longer be reachable after prompts or tools change. Replay is therefore a regression gate for historical cases, while live sampling remains necessary to discover new failure modes. Treating historical replay as complete coverage would replace one form of guesswork with another.
Once a fix clears replay validation, the failure pattern it addressed should become a standing regression test. That test places the known defect inside the deployment gate rather than leaving its prevention dependent on memory of an incident. Without regression evaluation, the same root cause can return within weeks because nothing in the pipeline blocks it. Keeping the pattern in the evaluation suite lets the backlog shrink instead of filling up with reports of the same failure.
Closing the loop through continuous production trace sampling
Synthetic evaluations miss classes of failure that emerge only in production because QA inputs differ from what live users actually send. A trace-driven workflow therefore needs continuous sampling. Sampled spans are scored with automated per-step evaluators, and anomalies are surfaced for attribution. At production scale, collection is not the hardest part. Selecting the traces that warrant investigation is the central signal-processing task.
Anomaly detection can surface timeout spikes, schema-conformance drops, and tool-call distribution shifts before users escalate. Each signal shows where to look for a cause but leaves the diagnosis open. When a planner shifts toward another tool, selection behavior needs a closer look, while a rise in outputs that fail schema validation calls for a check of contract compliance. Even a small schema-conformance decline warrants investigation. Cost and latency drift also deserve monitoring because step timing anomalies can precede correctness failures.
The sampled corpus then feeds the same replay process used to validate fixes. Each newly found failure pattern becomes a regression case, so the evaluation suite grows to reflect the real distribution of production inputs as well as those expected during development. This makes live monitoring and release validation parts of one engineering discipline. Production traces determine which tool or memory improvement should come next, and historical cases test whether that change is ready to ship.


