ReCast: Attribution-Oriented Step Representation Learning for LLM-Based Agent Systems
Organizations: Peking University, Beijing, China · Joy Future Academy, Beijing, China · Tsinghua University, Beijing, China
Abstract
In LLM-based agent systems, failures can originate from early steps whose effects propagate through subsequent interactions, making their origins difficult to identify. To trace such failures back to their origin, failure attribution has been formulated as the task of identifying the earliest step responsible for the failure. Recent methods leverage LLM internal signals for failure attribution, typically using hidden states as step representations. We therefore conduct an empirical study to evaluate how effectively these representations distinguish root-cause steps from other steps and find limited separation. Motivated by this observation, we propose ReCast, a step representation learning method that transforms hidden states from a frozen LLM into attribution-oriented step representations. ReCast first selects attribution-relevant layers, then constructs complementary pattern and deviation features, and finally learns contextualized step representations through an encoder trained with contrastive and ranking objectives. We also introduce ReCast-2K, a training dataset for failure attribution. ReCast achieves the best Hit@1 across four benchmarks, surpassing the strongest baseline by 5.65 and 9.19 pp on Who&When Algorithm and Handcrafted, respectively. Code is available at https://anonymous.4open.science/r/ReCast-5FB6 .
Figures & tables
| Category | Method | Who&When | TraceElephant | ||
|---|---|---|---|---|---|
| Algorithm | Handcrafted | Captain | Magentic | ||
| Heuristic | First | 16.13 0.00 | 1.72 0.00 | 7.06 0.00 | 6.67 0.00 |
| Random | 16.40 4.85 | 5.75 0.81 | 12.55 6.10 | 5.93 2.62 | |
| LLM-based | All-at-Once (Qwen) | 26.61 0.00 | 3.45 0.00 | 7.06 0.00 | 4.44 0.00 |
| All-at-Once (DS) | 22.04 0.76 | 10.34 2.44 | 12.55 1.11 | 9.63 0.52 | |
| All-at-Once (GPT) | 27.42 0.66 | 18.39 5.69 | 14.90 4.74 | 8.15 0.52 | |
| Category | Method | AFTraj-2K | Who&When Pro |
|---|---|---|---|
| Heuristic | First | 0.00 0.00 | 7.35 0.00 |
| Random | 11.45 0.77 | 25.69 0.69 | |
| LLM-based | All-at-Once (Qwen) | 20.86 0.00 | 21.10 0.00 |
| All-at-Once (DS) | 30.47 5.02 | 25.95 1.29 | |
| All-at-Once (GPT) | 19.02 0.87 | 33.33 1.27 | |
| Step-by-Step (Qwen) | 51.53 0.00 | 60.33 0.04 |
| Component | Variant | Hit@1 | Hit@1 (pp) |
| None | Full model | 41.58 1.04 | — |
| Layer selection | All 64 layers | 38.83 2.30 | |
| Uniform 8 | 38.10 2.55 | ||
| Last 8 | 37.55 0.93 | ||
| Random 8 | 37.18 0.69 | ||
| Global probe top-8 | 38.83 1.13 |
Appendix figures & tables13 assets
Supplementary material from the paper’s appendix.
Appendix
| Dataset | Representation | ARS | GRS | SI |
|---|---|---|---|---|
| Training | Text embedding | |||
| Hidden[-1] (Mean) | ||||
| Hidden[-1] (Last) | ||||
| Projected features | ||||
| ReCast | ||||
| Handcrafted | Text embedding |
| Task Category | # Trajectories | # Steps | # Tokens | ||||
|---|---|---|---|---|---|---|---|
| Total | Train | Test | Avg. | Max | Avg. | Max | |
| Embodied | 311 | 249 | 62 | 30.0 | 30 | 1,444.6 | 1,636 |
| STEM | 1,517 | 1,213 | 304 | 5.6 | 30 | 4,199.5 | 23,786 |
| Data Science | 2,446 | 1,958 | 488 | 3.7 | 17 | 609.1 | 6,861 |
| Deep Search | 1,641 | 1,313 | 328 | 5.6 | 31 | 1,551.9 | 21,948 |
| Coding | 342 | 273 | 69 | 3.0 | 3 | 3,127.6 | 7,490 |
| Benchmark | MAS | Model | Initial | Final Dataset | ||
|---|---|---|---|---|---|---|
| Runs | Succ. | Fail. | Total | |||
| AssistantBench | Captain-Agent | DeepSeek V4 Flash | 165 | 20 | 53 | 73 |
| GPT-4o-0806 | 165 | 14 | 38 | 52 | ||
| Qwen3-235B | 165 | 20 | 53 | 73 | ||
| Subtotal | 495 | 54 | 144 | 198 | ||
| GAIA | Captain-Agent | DeepSeek V4 Flash | 451 | 257 | 189 | 446 |
| Model | Type | # Trajectories | # Steps | # Tokens | ||
| Avg. | Max | Avg. | Max | |||
| DeepSeek V4 Flash | Successful | 454 | 15.7 | 61 | 7,005.5 | 59,153 |
| Failed | 500 | 21.6 | 55 | 10,603.5 | 74,773 | |
| GPT-4o-0806 | Successful | 225 | 18.5 | 60 | 4,460.0 | 22,757 |
| Failed | 515 | 32.0 | 61 | 7,996.1 | 29,094 | |
| Qwen3-235B | Successful | 359 | 18.5 | 62 | 4,568.5 | 21,378 |
| Component | Hyperparameter | Value |
| Backbone | Hidden-state dimension | 5,120 |
| Layer selection | Cross-validation folds | 5 |
| Layer budget | 8 | |
| Ridge ratio | 0.10 | |
| Selected layers | ||
| Projection | Dimension per branch | 2,048 |
| Method | LR | Weight decay | Batch | Budget |
|---|---|---|---|---|
| OAT | 32 | 300 epochs | ||
| StepFinder | 16 | 50 epochs | ||
| ASCon | 1 | 12 epochs |
| Backbone | # Layers | Hidden size | Selected layers |
|---|---|---|---|
| Qwen3.5-0.8B | 24 | 1,024 | 3, 5, 8, 11, 13, 18, 19, 22 |
| Qwen3.5-9B | 32 | 4,096 | 3, 7, 11, 16, 17, 23, 26, 31 |
| Qwen3.5-27B | 64 | 5,120 | 7, 15, 19, 32, 33, 47, 49, 57 |
| Evaluation population | Backbone | Hit@1 (%) | Hit@3 (%) | Hit@5 (%) | MRR (%) | AUROC (%) | AUPRC (%) |
|---|---|---|---|---|---|---|---|
| Who&When Handcrafted | Qwen3.5-0.8B | 30.46 2.15 | 41.95 2.15 | 55.75 0.81 | 41.80 1.07 | 80.00 2.12 | 19.09 0.84 |
| Qwen3.5-9B | 29.89 3.54 | 44.83 3.72 | 52.87 4.30 | 41.61 0.83 | 79.94 2.41 | 18.55 2.91 | |
| Qwen3.5-27B | 33.33 1.63 | 45.98 0.81 | 57.47 0.81 | 44.21 0.77 | 79.22 0.91 | 21.88 0.92 | |
| Who&When Algorithm | Qwen3.5-0.8B | 38.17 2.31 | 74.73 2.31 | 91.94 1.14 | 59.20 2.00 | 72.00 0.38 | 33.42 0.43 |
| Qwen3.5-9B | 38.98 0.38 | 74.46 2.01 | 92.74 2.37 | 59.85 0.67 | 73.64 1.58 | 35.10 0.47 | |
| Qwen3.5-27B | 45.43 2.01 | 72.31 1.01 | 92.47 1.66 | 63.28 1.42 | 74.75 1.00 | 38.52 1.84 |