Est.

From Ad Hoc Prompt Tweaks to a Systematic Trace-Driven Improvement Process

Trace records, not prompt rewrites, locate where agent failures begin.

· 8 min read
Cover illustration for “From Ad Hoc Prompt Tweaks to a Systematic Trace-Driven Improvement Process”
Trace-Driven Agent Improvement Workflows · November 15, 2026 · 8 min read · 1,841 words

A production trace-driven harness engineering workflow uses live execution records to locate failures, apply layer-specific fixes, and validate changes against historical traces before deployment. Ad hoc prompt tweaks fail because what goes wrong often shows up far from its cause. Systematic improvement requires a closed loop of instrumentation, evaluation, failure grouping, diagnosis, replay testing, and deployment, with each diagnosed case retained as a regression test.

Why engineers default to prompt tweaks even when the prompt is not the problem

Engineers rewrite prompts when an agent returns an unsupported answer, makes an inconsistent decision, or fails a tool call. The prompt is available for inspection, and the final response offers an immediate target for revision. That choice is understandable given the available evidence. Without the execution history, an instruction that appears insufficient can be difficult to distinguish from an instruction applied to already corrupted context.

AgentDebugX identifies this separation between symptom and origin as a central debugging problem. A failure can surface after many apparently reasonable actions, although its cause was an earlier planning omission, stale memory retrieval, invalid assumption, or incorrect handoff. Each subsequent step may propagate the original error without introducing it. The final prompt then looks defective because the failure becomes visible in its output.

Teams intervene at the most accessible layer, leaving the layer responsible for the failure untouched. A team rewrites its system prompt while a misconfigured tool schema or missing termination condition remains untouched. The difficulty is not insufficient attention to the prompt, but insufficient evidence about what happened before the prompt produced the visible failure.

What makes agent failures genuinely hard to attribute without traces

Long agent trajectories scatter the evidence needed to judge a single action across distant instructions, observations, and prior context. TRAJDEBUG establishes that identifying a local error can therefore require reconstructing relationships that are not visible at the step itself. A tool call may look reasonable on its own. Whether it was appropriate depends on the task constraints, the information available when it was made, and the earlier decisions on which it relied.

Even after an error is identified, its causal role remains unresolved. Failed trajectories can contain errors that were repaired, errors that remained harmless, and errors that propagated into the final outcome. The first local mistake may not be the one that caused the failure, and the error closest to the terminal failure may just reveal damage done much earlier.

Who&When Pro finds that LLMs perform well at detecting symptoms but struggle with root-cause attribution, especially in complex, long-trace scenarios. They tend to blame visible reasoning failures rather than trace their origins to planning or verification. LongRCA Bench research found that the best of the baselines it tested reached just 13.2% exact root-step accuracy on long trajectories. Even its proposed RCTA method recovered fewer than one quarter of reference roots exactly. These results establish why passing an unstructured history to a model is not a substitute for an attribution process.

Without a structured record, the distinction between a repaired error and a propagating one may be unavailable altogether. Logs that show events on their own cannot show the full error lifecycle. The search requires evidence of relationships.

Where failures actually originate — the layer map engineers need

A useful layer map separates the place an error appears from the part of the harness that requires a change. Prompt, tool, workflow, memory, and coordination failures present different intervention targets. Verification provides another important diagnostic category because an agent can end a run believing it succeeded.

At the workflow layer, relevant patterns include step repetition, unawareness of termination conditions, and failure to obey task specifications. At the coordination layer, they include communication breakdowns, context loss during handoffs, and format mismatches between agents. Memory can introduce stale retrieved context. Tool and action failures include invalid arguments, while an action can also inherit an upstream error and propagate it through execution.

Verification failures include premature task ending, incomplete verification, and incorrect verification. These differ from a failure to perform the task itself because the check can incorrectly accept an unsuccessful result. The distinction changes the repair target. A workflow termination failure requires a changed stopping condition, while a handoff format mismatch requires a schema correction.

Who&When Pro uses an 18-failure-mode taxonomy spanning perception, reasoning, planning, action, verification, and coordination across single- and multi-agent topologies. Its step-level annotations locate the decisive error within those executions. Such a taxonomy supplies a vocabulary for grouping failures, but a category alone does not establish causality. TRAJDEBUG separates error detection, error-state classification, and critical attribution precisely because finding an error and proving it decisive are different operations.

What systematic, trace-driven improvement actually requires from the execution record

A trace suitable for attribution links actions to their causal antecedents and preserves what happened to errors after they appeared. A record that merely confirms a run failed cannot do that work. Step-level structure is the minimum useful granularity. It makes it possible to examine the instruction behind an action, the context that made it erroneous, and whether later execution repaired or propagated the error.

TRAJDEBUG uses multi-granularity history compression to make long trajectories searchable without treating every inspection as a fresh reading of the entire history. Evidence-based error identification then connects each candidate trigger to the context that establishes the mistake. Resolution-status tracking records whether that mistake was still active. Without this last distinction, a self-correction can be mistaken for an unresolved defect, directing engineering effort toward a step that no longer explains the outcome.

RCTA also distinguishes between errors that start during execution and errors that come from upstream instructions. Supporting that distinction requires handoff records linking actions to the instructions that authorized them. Otherwise, an action can receive blame for faithfully executing a faulty instruction. The repair would then target the recipient of the faulty instruction, leaving its source unchanged.

AgentDebugX converts framework-specific events into a portable trajectory representation before attribution begins. That normalization gives execution frameworks a shared form for their records, so diagnosis can work without depending on a vendor-specific span format. The record must preserve step-level evidence, instruction relationships, and error resolution in a form that supports investigation after the run ends.

How root-cause attribution works as an engineered process, not a one-pass inspection

With that record in hand, attribution moves through candidate detection, state classification, and causal investigation. TRAJDEBUG begins with error trigger detection, identifying steps where something went wrong and relating them to supporting evidence. It then classifies each error by its subsequent state. A repaired error, a harmless error, and an error that propagated to failure remain separate candidates with different diagnostic significance.

Critical attribution follows those classifications rather than replacing them with an overall impression. The investigation traces the decisive error back to its origin, using the trajectory to distinguish cause from consequence. This prevents chronology from becoming a shortcut for causality.

AgentDebugX’s DeepDebug component adds a multi-turn approach that works through global trajectory understanding, structure-guided investigation, and cross-examination. Global understanding establishes the context of the run, while the investigation examines possible origins within its structure. Cross-examination subjects the diagnosis to further scrutiny rather than accepting the first plausible explanation.

DeepDebug outperforms single-pass baselines on strict attribution accuracy in the Who&When benchmark, achieving higher exact agent-and-step accuracy on the tested open-weight backbones than the strongest single-pass method. Its GAIA results also show more failed tasks repaired in a single rerun than three decoupled self-correction baselines. These findings support staged attribution without making any implementation a prerequisite. The relevant comparison is not only diagnostic time, but the repeated work caused by fixing the wrong layer and encountering the same failure again.

Why the fix must be validated against historical traces before it ships

A correct diagnosis identifies where to intervene, but it does not establish that a proposed change is effective or safe for other cases. Those are separate questions requiring execution evidence. Replay validation tests the changed harness on past cases before deployment. The change must fix the target failure, and cases the previous harness got right must still succeed.

To make that validation concrete, a diagnosed termination failure becomes a regression case for the changed stopping condition. A diagnosed handoff mismatch becomes a case for the schema correction. The same changes are tested against the broader historical corpus.

Who&When Pro uses controlled error injection into successfully replayed prefixes, so that subsequent behavior is an authentic reaction to a deliberate fault. That benchmark construction illustrates the value of controlled execution when examining cause and effect. It is not itself proof that a proposed production fix works. Such proof must come from testing the actual change against the relevant replay corpus.

AgentDebugX makes execution after diagnosis explicit in its Detect, Attribute, Recover, Rerun loop. Recovery turns the diagnosis into a rerun-able fix, and Rerun tests it. The framework’s repair results support correction at an identified root-cause step rather than self-correction without a known error location. Attribution guides the intervention, but the rerun establishes whether recovery occurred.

Each diagnosed failure adds a real run to the suite, while cases that worked before help check for regression. This is the step an ad hoc tweak omits. Shipping after inspecting one improved answer leaves both the broader failure class and the effect on other cases untested.

Building the loop — how production traces systematically improve an AI agent

A continual process begins with instrumentation and evaluation of live runs, followed by grouping failures through a shared taxonomy. Those groups organize the diagnosis work without substituting for step-level investigation. Attribution then produces a layer-specific change, replay tests it, and deployment follows validation. The diagnosed trace remains in the corpus so that future harness changes must account for it.

The retained record serves more than one purpose. Its annotations preserve the evidence for the diagnosis, its regression case constrains later changes, and its failure category helps organize similar incidents. Each incident can therefore contribute to subsequent investigations. That accumulation distinguishes a production trace-driven harness engineering workflow from a sequence of unrelated debugging sessions.

AgentDebugX’s Error Hub takes this further by letting teams opt in to sharing scrubbed failure-diagnosis-repair bundles with other teams. A diagnosed failure class becomes debugging memory that later runs can use. A team can do the same within its own work without sharing across teams. Failures whose causes have been traced become annotated traces, which then become tests that keep what the team learned.

Who&When Pro spans multiple modalities and agentic frameworks, showing the execution diversity a failure taxonomy must accommodate. Continuous production evaluation builds coverage from the agent’s actual operating history rather than relying exclusively on a fixed synthetic suite. As that history grows, the replay corpus reflects more of the failures the harness must withstand. New cases are added to the existing tests.

The operational discipline resembles software reliability practice through instrumentation, monitoring, anomaly detection, root-cause analysis, repair, testing, and deployment. Traces without attribution leave engineers interpreting symptoms, while diagnoses without replay leave proposed repairs unproven. When tests are not kept, later validation can miss failure classes that have already been diagnosed.

Sources

  1. TRAJDEBUG: Tracing Error Lifecycle to Identify Critical Failures in Long-Horizon Agent Trajectories
  2. LongRCA Bench: Root-Cause Localization in Long-Horizon Agent Trajectories
  3. AgentDebugX: An Open-Source Toolkit for Failure Observability, Attribution, and Recovery in LLM Agents
  4. Published as a conference paper at COLM 2026

More in Trace-Driven Agent Improvement Workflows