Failure knowledge is conditional knowledge
Most work on recursive self-improvement focuses on getting useful knowledge into the agent. A big part of that is failure experience, lessons from past mistakes that should help the agent do better next time. But we found that failure knowledge is actually "conditionally beneficial" for the agent. If it sits in the agent's main context, it can even distract the agent. And it only helps when the agent actually runs into the failure it describes.
Our framework, Sentry, is built around this idea and helps agents learn from failures and recover from them at test time. It keeps failure knowledge outside the agent and only steps in when a failure actually happens.
Where our research starts
We ran a Qwen3.5-9B agent on WebShop with ACE, which keeps a playbook of advice learned from past tasks. However, overall, the agent did not perform as well as expected. We checked the playbook that the agent obtained, and they were all helpful entries, so what went wrong?
When we dived deeper into the traces of this, we discovered that even if this failure knowledge was correct, it can become a distraction, because the agent can apply the advice in the wrong situation, and distinguishing when and where to apply the failure advice is relatively difficult for the agent itself. Here is an example:
On one task the agent ran search[women's pumps] twenty times and got nothing. ACE wrote three rules from that: if nothing fits, broaden the query; if page 1 has no match, check later pages; if results are still off, refine the query.
A few tasks later, the agent is asked for 20-inch hair extensions under $80. The first result is a 20-inch extension for $79.63. The agent even says so: "Item 1 fits the description perfectly. Let me also go through item 2, item 3, item 4 to make sure there is nothing better…" It never buys anything. Reward 0.
Each rule was correct and helpful, but the agent couldn't tell that they didn't apply here, so "check later pages" turned into "keep looking."
Then we turned to another line of methods, runtime intervention methods. These methods try to monitor agent failures and give guidance when failure happens. But they have the opposite problem. Their advice is too generic, they fix their recovery and detection strategies across different tasks, and some of these monitors' diagnoses are simply wrong.
For example, on one WebShop task, AgentGuard warns "no progress" whenever the page doesn't change. Sometimes that advice can help the agent break a real search loop. Other times the page doesn't change because the agent is picking a size and color, which is fine. The warning fires anyway, the agent leaves the page, and the options are gone. In this example, a fixed strategy cannot help the agent recover from its failures.
The idea
In practice, a failure lesson should be:
Kept across tasks, so a fix that worked once can be reused.
like context evolutionShowing up only when corresponding failures occur.
like runtime interventionSaved only if the fix worked. A lesson from a failed fix will misfire later too.
neither does thisWe introduce Sentry (Figure 3), a failure-management layer that runs alongside the task agent and handles failure knowledge along these three properties: it surfaces recovery lessons only when it diagnoses a failure, admits a lesson only after verifying the recovery, and learns by accumulating verified lessons across tasks. The complete playbook is maintained outside the agent's persistent background context; we refer to this as isolation. Isolation does not hide recovery knowledge from the agent: the few entries retrieved for a detected failure still enter the conversation during that intervention.
During execution, Sentry monitors the agent's recent trajectory. It routes invalid actions to hard repair, which asks the task agent for a valid replacement action, and routes progress and reasoning–grounding failures to soft repair, which combines the local diagnosis with relevant playbook entries to guide the agent's next step. After a soft repair, Sentry verifies whether the triggering failure has been resolved and adds only verified recovery lessons to the playbook for later interventions.
One run, step by step
This is a recorded AppWorld run with GPT-4.1 as the agent. The task: build a new Spotify playlist from songs in five existing ones. The agent starts calling account APIs before logging in.
planning_stall. P1Don't repeat an unchanged request P2Stop exploring; take the justified step P3Check docs before assuming a value · not retrieved Two of three entries match and go into the soft-repair prompt. P4 · When an authentication or authorization error is detected, inspect the API docs for required auth parameters, obtain or refresh credentials, and retry with proper authentication before proceeding.
Main results
Against runtime-intervention baselines, with Sentry starting from an empty playbook, Sentry wins on all four benchmarks. It's 37% better on average than the best baseline for each benchmark, and 77% better on WebShop. The runner-up is a different method on every benchmark.
| Method | WebShop reward | AppWorld test pass % | SWE-bench Lite accuracy | Mind2Web Replay completion |
|---|---|---|---|---|
| Base agent | 0.170 | 25.59 | 0.20 | 0.420 |
| AgentGuard | 0.258 | 25.09 | 0.22 | 0.450 |
| AgentForesight | 0.168 | 24.17 | 0.24 | 0.430 |
| AgentFixer | 0.171 | 26.69 | 0.22 | 0.687 |
| Wink | 0.264 | 27.56 | 0.18 | 0.370 |
| Sentry | 0.468 | 38.53 | 0.30 | 0.736 |
| gain over best baseline | +77.3% | +39.8% | +25.0% | +7.1% |
On held-out tasks, Sentry beats ACE by 48% on WebShop and 30% on Mind2Web Replay. Reflexion, AWM, and ReasoningBank all score below ACE. Even with the playbook frozen during evaluation, Sentry does better than with retrieval off (0.251 → 0.364 and 0.533 → 0.651), so the lessons carry over to new tasks.
The gains aren't just from fixing malformed calls. Without hard repair, Sentry still beats every runtime-intervention baseline on both benchmarks we tested. With GPT-OSS-120B instead of Qwen, it's still the best method, 51% above the top baseline on average.
Paired forks at 200 intervention points
final task score, Sentry branch vs. unaided branch from the same state
Local recovery after 10 steps: 33.5% unaided, 60.5% with Sentry. Paper Table 11.
Things We Learned
Where a lesson lives matters as much as what it says
We first deleted the failure lessons from the ACE playbook entirely, and the scores even went up on both benchmarks, which means that these lessons hurt more on average when they are situated in the agent's main context.
However, deleting these failure lessons also throws the valuable reflections on failure away, so we changed the setting to conditionally retrieving them. Two Sentry variants share the same frozen playbook, detector, and retrieval. One also puts the whole playbook in the agent's context. It still gets the right lessons on demand, and it still does worse. These experiments tell us that the lesson should live conditionally, and conditionality matters as much as its quality.
Same lessons, different exposure
held-out · WebShop avg. reward / Mind2Web Replay completion
Scales: WebShop 0–0.7, Mind2Web 0–0.9. Paper §2 and Table 4.
Knowing when to intervene is important
Of everything we ablated, the check for whether to intervene at all mattered most. Removing it cut performance by 55% on average across WebShop and AppWorld. On WebShop, a Sentry that steps in every time does worse than no Sentry. Always intervening will frequently disrupt the agent's reasoning progress, causing it to get confused and change its behavior, which will cause worse performance.
Intervening every step is worse than not intervening
online from scratch · WebShop avg. reward
Scale 0–0.6. Dashed line: base agent. Paper Table 3.
Right lesson > More lessons
With everything else fixed, we changed the retrieval of these lessons, and we discovered that the closer the guidance matches the diagnosed failure, the better performance the agent achieves. We retrieve the top k entries from the playbook with the same failure label and the same failure type. Even when you have the right diagnosis, it is important to use the right entries that can actually help with the problem, as we see that random retrieval degrades performance because it will often mislead the agent.
How lessons are picked
held-out · WebShop avg. reward
"label" = same failure type plus at least one shared label. Scale 0–0.6. Mind2Web Replay follows the same order: 0.55 / 0.61 / 0.66 / 0.70 / 0.73 / 0.69. Paper Table 14.
Task-level and failure-level learning are complementary
ACE provides task-level knowledge before execution; Sentry supplies failure-specific guidance when something goes wrong. Their playbooks remain separate.
The combination performs best among the evaluated methods on both benchmarks, suggesting that task-level and failure-level learning address different needs and work better together.
ACE and Sentry together
held-out · WebShop avg. reward / Mind2Web Replay completion
Scales: WebShop 0–0.7, Mind2Web 0–0.9. Paper Table 2.
Paper and code
This post is based on our paper, Sentry: Learning to Recover from LLM Agent Failures at Test Time. The paper has the full method, prompts, more ablations, and an example playbook.
The code is open source at github.com/nuglifeleoji/Sentry. If your agents keep getting stuck, give it a try. Stars, issues, and PRs are all welcome. There is also a short thread on X with the demo video.
Sentry is joint work with Amy Lu (equal contribution), Qizheng Zhang, and Kunle Olukotun at Stanford. Huge thanks to them as well as the Stanford Pervasive Parallelism Lab.
@article{ji2026sentry,
title = {Sentry: Learning to Recover from LLM Agent Failures at Test Time},
author = {Ji, Changxiu and Lu, Amy and Zhang, Qizheng and Olukotun, Kunle},
journal = {arXiv preprint arXiv:2610.02994},
year = {2026}
} Questions or feedback: leo0610@stanford.edu