Source-linked AI summary

CausalFlow: Causal Attribution and Counterfactual Repair for LLM Agent Failures

Akash Bonagiri, Devang Borkar, Gerard Janno Anderias, Setareh Rafatirad, Houman Homayoun

arXiv:2605.25338v1cs.LGcs.AI

TL;DR

Outcome-level feedback leaves unclear which step caused an agent failure, while heuristic retries do not establish causal responsibility or minimality. CausalFlow intervenes on steps in failed traces, generates and validates minimal counterfactual repairs, and forms reusable supervision pairs. Across four benchmarks, it converts 42.7% of failed executions into validated minimal repairs and improves downstream task success.

  • Problem

    Outcome-level feedback leaves ambiguous which intermediate decision caused an agent failure, while heuristic retries do not isolate the failure-inducing step or ensure minimal corrections.

    Source: §1 · p. 1
  • Method

    CausalFlow replaces candidate steps in failed traces, re-executes downstream computation to identify responsible steps, and generates minimally edited, validated repairs.

    Source: §1 · p. 2, §3 · p. 4, §4.1 · p. 4
  • Results

    Across four benchmarks and more than 3,000 problems, CausalFlow converts 42.7% of failed executions into validated minimal repairs and improves downstream task success.

    Source: §1 · p. 2
  • Takeaways & Limitations

    Causal intervention can support targeted repair without regenerating the whole trajectory and extract structured supervision from naturally occurring failures.

    Source: §8 · p. 9

    Retrieval-driven failures cannot be corrected through local reasoning modification when essential information is unavailable; retrieval-aware intervention remains an open challenge.

    Source: Limitations · p. 9

Abstract

from arXiv · show

Large language model (LLM) agents frequently fail on multi-step tasks involving reasoning, tool use, and environment interaction. While such failures are typically logged or retried heuristically, they contain structured signals about where execution broke down. We introduce CausalFlow, an interventional framework that converts failed agent traces into minimal counterfactual repairs and reusable supervision. CausalFlow models execution traces as sequential chains of dependent steps and computes Causal Responsibility Scores(CRS) via step-level counterfactual intervention to identify failure-inducing steps. For these steps, we generate minimally edited repairs that flip the final outcome to success, producing validated contrastive pairs of the form (wrong step, corrected step). CausalFlow supports two complementary uses: targeted test-time repair that recovers from failures with minimal behavioral drift, and training-time supervision suitable for offline preference optimization or reward modeling. Across four benchmarks spanning mathematical reasoning, code generation, question answering, and medical browsing, CausalFlow converts failed executions into validated minimal repairs with high minimality and causal-consensus scores, and demonstrates that causal attribution is necessary for reliable improvement across diverse agent tasks, outperforming heuristic refinement in complex retrieval settings while producing more localized repairs throughout. These results demonstrate that interventional analysis over structured execution traces provides a principled and scalable mechanism for transforming agent failures into reliability gains and learning-ready supervision.

1 Introduction

CausalFlow addresses ambiguous outcome-only feedback by intervening on individual steps in failed traces, then turning successful minimal corrections into validated repairs and reusable supervision. Across four domains and more than 3,000 problems, it converts 42.7% of failed executions into validated minimal repairs.

1 Introduction

  • Outcome-level feedback leaves the responsible intermediate decision ambiguous, limiting systematic repair and learning from failed executions.Existing retries, critique-driven rewriting, and full regeneration do not explicitly test causal responsibility or guarantee minimal corrections.Source: §1 · p. 1
  • CausalFlow replaces candidate steps and re-executes downstream computation to identify interventions that flip a failed outcome to success.This defines the Causal Responsibility Score (CRS) for identifying responsible steps.Source: §1 · p. 2
  • Across four domains and more than 3,000 problems, CausalFlow converts 42.7% of failed executions into validated minimal repairs and improves downstream task success.The evaluation spans mathematical reasoning, code generation, question answering, and medical browsing.Source: §1 · p. 2
  • For responsible steps, CausalFlow generates minimally edited repairs, validates them by re-execution or outcome prediction, and forms wrong-step/corrected-step pairs.Figure 1 summarizes attribution, repair generation, and validation.Source: §1 · p. 2, Figure 1 · p. 2
  • The validated contrastive pairs support deploy-time repair and learning-ready examples for offline preference optimization or reward modeling.Deploy-time repair requires no parameter updates.Source: §1 · p. 2
  • CausalFlow formulates logged failures as reusable step-level supervision without requiring manual annotation of every intermediate step.The framework is intended to support offline learning from naturally occurring failures.Source: §1 · p. 2

2 Related Work

Prior work improves agent reliability through refinement, tool use, search, and preference learning, but typically leaves responsibility ambiguous at the intermediate-step level. CausalFlow instead focuses on interventional attribution and validated repair in structured traces.

Iterative refinement and self-repair

Step-level supervision and preference learning

Failure diagnosis and causal intervention

  • CausalFlow differs from diagnosis and intervention work by targeting single-agent sequential traces without checkpoint infrastructure, directly intervening, and producing minimal validated contrastive pairs.MAST taxonomizes failures, Who&When reports 14.2% step-level accuracy from logs alone, and concurrent DoVer targets multi-agent systems [Cemri et al., 2025, Zhang et al., 2025b, Ma et al., 2026].Source: §2 · p. 3
  • Other causal-tracing and causal-reasoning work studies internal model behavior rather than explicit execution traces [Meng et al., 2022, 2023, Chi et al., 2024, Kıcıman et al., 2024, Geiger et al., 2025].Source: §2 · p. 3

3 Problem Setup

The problem setup treats an agent run as a structured sequence of dependent reasoning, tool, and environment steps, with task success assessed by a verifier. The goal is to identify a step whose intervention changes failure to success and yields a minimal repair.

3 Problem Setup

  • An execution trace contains reasoning steps, tool invocations, and environment observations, and induces a task output assessed by a task-specific success verifier.Source: §3 · p. 3
  • Each step may depend on earlier outputs, so intervening on a step requires re-executing subsequent steps; runtime logs record dependencies among reasoning, tool, and environment steps.Source: §3 · p. 3
  • Given a failed trace, the goal is to find a step intervention that flips the outcome to success and produces a minimal repair that remains successful under re-execution.Source: §3 · p. 4

4 The CausalFlow Framework

CausalFlow models dependent execution steps, attributes failures through step-level interventions, selects minimal successful repairs, and validates attributions through multi-agent review. Its repair procedure yields contrastive supervision pairs.

4 The CausalFlow Framework

  • CausalFlow comprises trace modeling, interventional attribution, counterfactual repair, and multi-agent validation.Source: §4 · p. 4

4.1 Causal Attribution via Interventions

  • For a failed trace, CausalFlow replaces a candidate step and re-executes subsequent steps while leaving earlier steps unchanged, localizing the intervention and its downstream effects.CRS is 1 when at least one replacement flips the verifier outcome from failure to success; affected descendants are recomputed.Source: §4.1 · p. 4

4.2 Counterfactual Repair

  • For steps with CRS=1, CausalFlow ranks successful interventions by token matching with a length penalty and selects the repair maximizing minimality.Higher position-wise token-match scores indicate smaller edits, and each validated repair yields a contrastive supervision pair.Source: §4.2 · pp. 4–5

4.3 Multi-Agent Validation

  • Three-agent validation has agents propose, critique, and meta-critique causal attributions; agreement labels and confidence scores determine consensus, with a default retention threshold of 0.5.Source: §4.3 · p. 5

5 Experiments

CausalFlow is evaluated as a step-level repair framework across four benchmarks, with structured traces enabling interventions and comparison against refinement baselines.

5 Experiments

  • The experiments assess causal attribution, validated counterfactual repair, and task-performance improvement across four domains.The benchmarks span mathematical reasoning, program synthesis, web-based question answering, and medical browsing.Source: §5 · p. 5

5.1 Benchmarks

  • GSM8K, MBPP, SealQA Hard, and MedBrowseComp cover over 3,000 tasks with varied tool use, reasoning depth, and environment interaction.They respectively evaluate grade-school mathematics, Python program synthesis, web-search synthesis, and medical browsing.Source: §5.1 · p. 5

5.2 Agent Configuration

  • Agents use benchmark-suited models and tools, while structured traces log step types and dependencies needed for CRS interventions.Structured logging incurs a modest accuracy cost relative to unstructured baselines, which repair is designed to recover; comparisons use matched model checkpoints and temperatures.Source: §5.2 · p. 5

5.3 Intervention Protocol

  • CausalFlow uses K = 3 intervention proposals per candidate step and evaluates downstream outcomes by deterministic re-execution or predictive modeling.Baselines are evaluated on final outputs without step-level interventions.Source: §5.3 · p. 5

5.4 Evaluation Metrics

  • Evaluation measures repair rate, post-repair accuracy, minimality of edits, and CRS precision.Minimality uses position-wise token similarity, with higher scores indicating smaller edits; CRS precision measures the fraction of flagged steps with validated outcome-flipping interventions.Source: §5.4 · p. 6

6 Results

CausalFlow produces validated repairs across domains, improves accuracy on all four benchmarks, and generally localizes changes, while ablations identify conditions affecting repair and minimality.

6.1 Main Repair Performance

  • 42.7% of failed traces (555/1,299) become validated successful repairs overall, with CausalFlow repair rates ranging from 21.9% to 52.4%.GSM8K is highest at 52.4% and SealQA Hard lowest at 21.9%; on MBPP, Self-Refine and Self-Reflection exceed CausalFlow's repair rate, but have lower minimality scores.Source: Table 1 · p. 6, §6.1 · p. 6

6.2 Impact on Overall Accuracy

  • CausalFlow alone improves accuracy across all four benchmarks, gaining +30.8pp on MedBrowseComp and +12.6pp on SealQA Hard.On GSM8K, post-repair accuracy reaches 88.1%, matching Direct and recovering the 13.1pp initial-accuracy gap attributed to structured trace logging.Source: §6.2 · p. 7

6.3 Minimality and Localization of Repairs

  • Across benchmarks, CausalFlow's average minimality scores range from 0.79 to 0.87, and repairs typically modify only a small number of tokens or steps.Its MBPP and SealQA Hard scores are 0.82 and 0.79, respectively; qualitative inspection finds repairs often change one reasoning statement, tool argument, or conditional clause, producing localized contrastive supervision.Source: §6.3 · p. 7

6.4 Error Pattern and Skill Decomposition

  • Causal-step clusters expose domain-specific skill deficits, from arithmetic and coding errors to query formulation, synthesis, and medical reasoning.The authors suggest these signals could guide future curriculum-based training or targeted fine-tuning.Source: §6.4 · p. 7

6.5 Ablation Studies

  • Repair-rate gains diminish beyond K=3; minimality ranking improves localization without meaningfully changing repair rate, and metric agreement varies by domain.Lexical and edit-distance selectors agree on 88% of steps with multiple successful proposals, while semantic-cosine agreement falls from 90% on GSM8K to 52% on MedBrowseComp. Three GSM8K runs show repair-rate and post-repair-accuracy standard deviations of 6.81pp and 1.63pp; manual audits find browsing repair precision of 90.9% and 86.2%, and removing gold references costs 21pp on SealQA Hard and 6pp on MedBrowseComp but slightly improves MBPP by 6.4pp and changes GSM8K by 0.55pp.Source: §6.5 · p. 8

7 Discussion

The discussion argues that many agent failures are localized and that repair benefits depend on task structure. CausalFlow is positioned as a debugging layer for structured traces, not a universal replacement for refinement.

7 Discussion

  • Across benchmarks, one or a few steps often account for outcome changes, making failed traces a source of step-level supervision beyond final-answer feedback.This can distinguish failure-inducing decisions from surrounding correct reasoning.Source: §7 · p. 8
  • Heuristic refinement can recover closed-form failures, sometimes with higher final accuracy, but retrieval-heavy tasks favor targeted intervention over global rewriting.Global refinement may discard correct reasoning or fail to distinguish retrieval gaps from reasoning errors.Source: §7 · p. 8
  • CausalFlow's value is in diagnosing structured traces, limiting behavioral drift, and generating interpretable skill signals that may support debugging or future training.The authors frame it as a causal debugging layer rather than a universal replacement for refinement.Source: §7 · p. 8

8 Conclusion

CausalFlow identifies failure-inducing steps by intervening on individual trace steps and re-executing downstream computation. Across four benchmark domains, it produces localized repairs and supervision, and many failures can be repaired without regenerating the full trajectory.

8 Conclusion

  • CausalFlow intervenes on individual steps and re-executes downstream computation to identify failure-inducing decisions.The paper presents this as causal debugging of LLM agent execution traces.Source: §8 · p. 8
  • Across four benchmark domains, CausalFlow identifies failure-inducing decisions and generates minimal validated repairs.The resulting localized contrastive pairs can support future supervision.Source: §8 · pp. 8–9
  • Many agent failures can be repaired without regenerating the entire trajectory, supporting inference-time reliability and structured supervision from naturally occurring failures.The paper describes this as a step toward more repairable, interpretable, and learning-ready agent systems.Source: §8 · p. 9

Limitations

CausalFlow's performance and attribution depend on its intervention proposals and dependency annotations, while trace logging and re-execution introduce practical costs. Its local repair approach also has a boundary when retrieval failures reflect unavailable information.

Limitations

  • Intervention quality depends on the LLM generating meaningful corrective proposals; invalid alternatives may leave causally responsible steps unidentified.In that case, those steps may be under-identified.Source: Limitations · p. 9
  • Computing CRS requires re-executing affected trace segments, and very long or tool-intensive traces may require approximation strategies.Empirical results indicate that small values of K are sufficient.Source: Limitations · p. 9
  • When essential information is unavailable, local reasoning modification cannot correct retrieval-driven failures.Integrating retrieval-aware interventions remains an open challenge.Source: Limitations · p. 9
  • CausalFlow's structured trace logging lowers initial GSM8K accuracy relative to plain chain-of-thought, 75.0% versus 88.1% for Direct.The repair mechanism fully recovers this gap, but the logging overhead is a deployment cost.Source: Limitations · p. 9
  • Incomplete or noisy dependency annotations may weaken intervention semantics and attribution reliability.Accurate dependency annotations are required for reliable causal attribution.Source: Limitations · p. 9

Impact Statement

CausalFlow's appendix describes its safety intent and implementation, including step-level scoring, typed trace logging, intervention prompts, and repair validation. The repair workflow uses deterministic execution where available and predicted outcomes for browsing tasks.

Impact Statement

  • The impact statement frames CausalFlow as supporting reliability and interpretability, while noting possible misuse for probing weaknesses or optimizing adversarial inputs.It states that the techniques add no attack capabilities beyond standard evaluation and stress-testing practices.Source: Impact Statement · p. 9

A.1 Causal Responsibility Scoring Algorithm

  • The causal responsibility scoring algorithm tests candidate-step interventions, re-executes the trace, and assigns a score when the verifier accepts the resulting outcome.It returns CRS scores for the candidate steps in the failed trace.Source: §A.1 · p. 12

A.2 Trace Logging and Step Typing

  • The trace logger records typed steps with step-specific content and explicit dependencies on earlier steps.Step types include reasoning, tool calls and responses, memory access, and final answers.Source: §A.2 · p. 13

A.3 Intervention Prompting

  • Intervention prompts provide the trace context, failed-step content, and failure feedback, with temperature-based sampling generating multiple proposals per step.Figure 2 presents the structured prompt template for generating interventions.Source: §A.3 · p. 13

A.4 Additional Prompt Templates

  • The appendix includes representative causal-attribution prompt templates whose braced fields are instance-specific.Figure 3 shows a prompt asking whether the current step is the failure's root cause.Source: §A.4 · p. 13

A.5 Repair Validation and Re-Execution

  • Repairs are validated by deterministic re-execution or predictive outcome estimation, depending on whether the task has an executor.GSM8K and MBPP use deterministic execution; browsing tasks use LLM-based outcome prediction.Source: §A.5 · p. 13

A.6 GSM8K Experimental Setup

The experimental setups cover mathematical reasoning, code generation, web-based question answering, and medical question answering. They specify datasets, agent configurations, validation approaches, and runtime costs for the four benchmarks.

A.6 GSM8K Experimental Setup

  • GSM8K uses 1,319 grade-school math problems and a structured agent with reasoning, calculation steps, calculator calls, and final-answer extraction.The setup uses Gemini 2.0 Flash Lite and includes a structured prompt template for minimal counterfactual interventions.Source: §A.6 · p. 13, Figure 2 · p. 14

A.7 MBPP Experimental Setup

  • MBPP uses 974 programming problems, an LLM code-generation agent, and Docker execution with success requiring all test assertions to pass.The setup uses GPT-5 Chat and includes a prompt for causal attribution.Source: §A.7 · pp. 14–15, Figure 3 · p. 15

A.8 SealQA Hard Experimental Setup

  • SealQA Hard covers 254 complex web-search questions, using a BrowseComp agent with up to 15 steps and LLM-based answer grading.Web results are cached for reproducibility.Source: §A.8 · p. 15

A.9 MedBrowseComp Experimental Setup

  • MedBrowseComp covers 484 medical QA problems using the SealQA agent configuration with a reduced maximum of 10 steps.It uses web search and fetch tools and the same LLM-based grader template as SealQA.Source: §A.9 · p. 15

A.10 Runtime Analysis

  • Runtime includes baseline trace generation, three interventions per candidate step, sequential re-execution, and validation; total API cost was approximately $130.00.Reported per-benchmark runtime and cost were GSM8K (12 hours, $31.56), MBPP (6 hours, $9.72), SealQA Hard (1 hour, $16.36), and MedBrowseComp (2 hours, $27.05).Source: §A.10 · p. 16

B Future Work

The material outlines future extensions and summarizes accuracy, repair, dataset, skill-group, and attribution-reliability analyses across CausalFlow’s benchmarks.

B Future Work

  • Future work proposes step-level supervision for fine-tuning, reward modeling, or offline preference learning, alongside online monitoring for self-repair.It also identifies multi-agent causal debugging, approximate CRS computation, retrieval optimization or memory augmentation, and lower-overhead trace logging as directions.Source: B Future Work · p. 16

C.1 Per-Method Accuracy Before and After Refinement

  • Table 2 organizes each method’s initial and post-refinement accuracy; Direct receives no refinement, so its before-and-after values match.Negative deltas indicate performance degradation.Source: Table 2 · p. 16

C.2 Visual Summary of CausalFlow results

  • Figure 4 provides a visual summary of CausalFlow results across all four benchmarks.Source: Figure 4 · p. 17

C.3 Per-Model Breakdown

C.4 Dataset and Trace Statistics

  • Table 4 reports benchmark dataset and trace statistics, with totals for counts and macro-averages for rates.Accuracy is calculated as Passed/Total.Source: Table 4 · p. 17

C.5 Skill Group Details

  • The taxonomy groups failures into 16 GSM8K, 12 MBPP, 4 SealQA Hard, and 6 MedBrowseComp skill categories for targeted debugging and potential curriculum training.The categories are derived by clustering causal steps with LLM-based skill labeling.Source: §C.5 · pp. 17–18

C.6 Causal Attribution Reliability Metrics

  • CRS Precision counts flagged steps with a validated outcome-flipping intervention; Consensus Rate measures flagged steps retained after multi-agent validation, used only for GSM8K.Source: Table 5 · p. 18, §C.6 · p. 18

C.7 Ablation Studies

This section provides supporting context for CausalFlow’s approach to localizing and repairing agent failures, covering ablations, reproducibility, baseline prompts, limitations, and released code and LLM components. It also states that the study involved no crowdsourcing or human subjects.

C.7 Ablation Studies

  • The captions cover stochasticity, per-run repair (T=0.7, K=3, critique disabled), minimality metrics (K=5) and selector agreement, judge accuracy, and paired no-gold prompts (K=5), but report no outcome values.No-gold per-proposal success rates are paired on traces where both arms produced proposals, with ∆ defined as No-gold − With-gold in percentage points.Source: Table 6 · p. 18, Table 7 · p. 19, Table 8 · p. 19

C.8 Code and Reproducibility

  • The complete implementation, including agent configurations, attribution and repair modules, and evaluation scripts, is publicly available in an anonymized repository.The checklist says experimental details include configurations, model identifiers, temperatures, dataset sources, validation methods, and prompt templates.Source: §C.8 · p. 19, §2 · p. 24

D.1 Localized Nature of Agent Failures

  • In many failed traces, only one to three steps receive CRS = 1, indicating that a small number of decisions determine the incorrect outcome.This localization pattern is reported for structured reasoning and browsing tasks.Source: §D.1 · p. 20

D.2 Causal Intervention as an Operational Tool

  • CausalFlow re-executes downstream steps after intervening on a failure-inducing step, aiming to reduce behavioral drift while preserving unaffected reasoning.The passage describes these targeted interventions as improving task accuracy without changing model parameters.Source: §D.2 · p. 20

D.4 Interpretability and Skill Signals

  • Clustering causally responsible steps reveals recurring weaknesses in arithmetic, boundary-condition logic, query formulation, and medical reasoning.The passage suggests these patterns could inform targeted training, curriculum design, or structured reward shaping.Source: §D.4 · p. 20

E Baseline Prompt Templates

  • The baseline appendix provides Self-Refine and Self-Reflection prompts, with refinement conditioned on generated solutions or a shared web-search run, respectively.Self-Refine uses iterative feedback and revision; Self-Reflection uses a single structured reflection pass.Source: E Baseline Prompt Templates · p. 20, Figure 5 · p. 21, Figure 6 · p. 22

D.3 Domain-Dependent Repairability

  • +12.6pp on SealQA Hard and +30.8pp on MedBrowseComp are CausalFlow gains; heuristic refiners decline or stay near zero on retrieval-heavy tasks.On closed-domain GSM8K and MBPP, heuristic refiners also improve accuracy, and Self-Refine achieves the highest final accuracy on MBPP.Source: §D.3 · p. 20, NeurIPS Paper Checklist · p. 23

2. Limitations

  • The authors identify proposal quality, re-execution cost, unavailable retrieval evidence, logging-related accuracy costs, and dependency annotations as limitations.Full error bars are absent for the main results due to computational cost; the checklist reports stochasticity-ablation standard deviations and judge-precision confidence intervals.Source: §2 · pp. 23, 26
  • The paper says its datasets and baseline methods are cited to their original papers and that datasets are loaded from public HuggingFace repositories.It also references the Serper and OpenRouter APIs in appendices.Source: §2 · p. 28
  • The CausalFlow codebase is released with documented agent configurations, attribution algorithms, repair modules, evaluation scripts, and example traces.The passage identifies it as a new asset and points to Appendix C.8.Source: §2 · p. 29
  • The paper states that it involved no crowdsourcing or human-subject research; its manual audit was an author-performed quality check on LLM-graded outputs.It therefore reports that IRB approval was not required.Source: §2 · p. 29
  • LLMs are core to CausalFlow, including intervention proposals, predictive re-execution, multi-agent validation, and grading for browsing benchmarks.The passage names Gemini 2.0 Flash Lite, GPT-5 Chat, and Gemini 3 Flash Preview for intervention proposals.Source: §2 · p. 30
Loading 2605.25338v1…