Skip to main content
Back

Shanghai AI Lab's RetroAgent Teaches AI to Learn From Its Own Failures

RetroAgent teaches LLM agents to learn from their own mistakes using dual intrinsic feedback, beating GRPO baselines by up to 27% across four agentic benchmarks.

Pro

  • RetroAgent is an online RL framework for LLM agents that generates its own training signals through hindsight self-reflection after each episode.
  • Two intrinsic feedback signals: a numerical capability-evolution reward for partial progress, and natural-language lessons stored in a retrievable memory buffer.
  • Novel SimUtil-UCB retrieval balances semantic relevance, historical utility, and exploration to prevent over-reliance on a narrow set of memories.
  • Beats GRPO baselines by +18.3% on ALFWorld, +15.4% on WebShop, +27.1% on Sokoban, and +8.9% on MineSweeper; sets new SOTA across all four benchmarks.
  • Reaches GRPO's peak performance 46% faster (in-context variant) with strong out-of-distribution generalization to unseen task variants.
  • Code is publicly available at github.com/zhangxy-2019/RetroAgent; tested on Qwen-2.5-7B and Llama-3.1-8B.

When a reinforcement learning agent fails a task, standard RL does one thing: penalize the outcome and try again. It doesn't ask why it failed, it doesn't write down what it learned, and it certainly doesn't consult its own history before the next attempt. The result is agents that plateau early, locked into the first strategy that worked, with no mechanism for genuine improvement over time. A new paper from Shanghai AI Lab introduces RetroAgent, an online RL framework that gives LLM agents something closer to human retrospective learning: the ability to reflect on past episodes, generate their own training signals, and build an explicit memory of reusable lessons.

The two-headed problem with standard RL agents

Standard RL for LLM agents optimizes a single signal: did the task succeed or fail? This approach prioritizes isolated task completion over continual adaptation, causing agents to converge to suboptimal policies due to limited exploration, while accumulated experience remains implicitly trapped within model parameters, hindering its explicit reuse for guiding future decisions.

Prior work has attacked these two problems separately. One camp improves exploration through meta-RL or entropy-based rewards. Another equips agents with external memory banks. While effective in isolation, these approaches fail to tightly couple exploration with explicit experience reuse to support continuous adaptation. RetroAgent tackles both at once with a single mechanism: hindsight self-reflection.

Reflect, score, remember

Inspired by human retrospective self-improvement, RetroAgent trains agents to master complex interactive environments not only by solving tasks, but by evolving under the joint guidance of extrinsic task rewards and retrospective dual intrinsic feedback. After every episode, the agent looks back at its own trajectory and produces three outputs bundled into a reflection tuple:

  • A scalar potential score (0–1) estimating how many subtasks were completed, even if the overall task failed
  • A binary success prediction , did the agent think it succeeded or failed?
  • A natural-language lesson distilled from what went right or wrong

These three outputs feed two distinct feedback channels that jointly augment the standard RL objective.

RetroAgent RL training loop showing policy updates, trajectory generation, environment feedback, and reward computation

Signal 1: Intrinsic numerical feedback

The potential score becomes a shaped intrinsic reward called the capability-evolution reward. The key idea is that an agent deserves credit for partial progress, even when the final task fails. For example, if a shopping agent successfully locates the right product category but fails to complete the purchase, that partial success should be reinforced.

The reward is computed as the rectified gain of the current potential score over a historical baseline , the best average success rate seen so far for that task. Formally: R_int = max(0, potential_score - historical_best). Because the baseline can only rise, the agent must keep improving to keep earning intrinsic rewards. This prevents the agent from gaming easy partial completions and pushes it toward genuine capability growth.

Signal 2: Intrinsic language feedback and SimUtil-UCB

The natural-language lesson gets stored in a persistent reflection memory buffer. Each memory entry tracks not just the lesson, but also a utility score (how helpful this lesson has been in past retrievals), an access count, and the outcome of the originating episode.

At the start of each new training episode, the agent queries this buffer using a novel retrieval strategy called SimUtil-UCB (Similarity and Utility-Aware Upper Confidence Bound). The retrieval score balances three criteria:

  • Semantic relevance: cosine similarity between the current task and stored task embeddings (using all-MiniLM-L6-v2), with a hard cutoff at 0.4
  • Historical utility: an exponential moving average of task success scores observed when that lesson was retrieved
  • Exploration bonus: a UCB term that rewards accessing under-used lessons, preventing the agent from over-relying on a narrow set of memories

The final score is a convex combination: S = α * relevance + (1-α) * UCB_utility. The retrieved lesson is appended to the task prompt, giving the agent explicit guidance from its own past experience before it even takes its first action.

Two variants, one framework

RetroAgent ships in two flavors. The in-context variant uses a frozen reflection function with pairwise induction , the agent compares the current trajectory against a contrastive reference trajectory from an earlier step with the opposite outcome (success vs. failure). Contrasting the two helps the model precisely isolate what made the difference.

The RL-trained variant goes further: the reflection policy itself is jointly optimized alongside the decision-making policy using REINFORCE. The reflection reward is simple , the agent gets credit only when its success prediction matches the actual outcome. This co-evolution means the agent's self-assessment improves in lockstep with its task performance.

Both variants use GRPO (Group Relative Policy Optimization) for the decision-making policy and are implemented on top of the open-source Verl training library. Half of each training batch uses the memory-augmented policy; the other half uses the base policy without memory, preserving trajectory diversity and preventing premature convergence.

RetroAgent architecture diagram and benchmark comparison bar chart showing RetroAgent outperforming GRPO across ALFWorld, WebShop, Sokoban, and MineSweeper

Benchmarks and results

The team evaluated RetroAgent on Qwen-2.5-7B-Instruct and Llama-3.1-8B-Instruct across four agentic tasks that cover very different challenge types:

  • ALFWorld: text-based embodied household tasks (navigation + object manipulation)
  • WebShop: simulated e-commerce web navigation to purchase products matching specifications
  • Sokoban: irreversible box-pushing puzzles requiring multi-step planning
  • MineSweeper: logic-based mine identification using numerical clues

RetroAgent consistently achieves state-of-the-art performance across all four benchmarks, outperforming the GRPO baseline by +14.4, +12.0, +21.4, and +8.6 percentage points on ALFWorld, WebShop, Sokoban, and MineSweeper, respectively. The RL-trained reflection variant hits 95.6% on ALFWorld, 88.9% on WebShop, 82.3% on Sokoban, and 48.2% on MineSweeper.

MethodALFWorld (%)WebShop (%)Sokoban (%)MineSweeper (%)
GRPO (baseline)77.366.911.239.3
GiGPO (prior SOTA)90.872.821.941.1
RetroAgent (In-Context)91.778.932.647.9
RetroAgent (RL-Trained)95.682.338.348.2

A key finding from the ablations: RetroAgent markedly outperforms EvolveR (78.9–82.3% vs. 17.6% success rate on WebShop), which incorporates raw trajectories as in-context demonstrations to guide policy optimization. Distilled lessons beat raw trajectory replay by a wide margin , the noise in full trajectories actively hurts exploration.

The memory retrieval strategy matters more than you'd think

One of the more surprising findings is how much the retrieval strategy affects outcomes. When the team ablated SimUtil-UCB against pure similarity-based retrieval, they found that similarity-only retrieval actually degraded performance when combined with discounted returns. The reason: similarity-based retrieval concentrates access on a narrow subset of memories, with some entries retrieved 15+ times while most are ignored. SimUtil-UCB's exploration bonus distributes access more evenly, with most entries accessed around 5 times, which prevents the agent from over-relying on a few high-similarity lessons that may encode suboptimal behaviors.

Test-time adaptation and generalization

RetroAgent achieves near-perfect discovery rates within three attempts in both in-distribution (WebShop: 82.3% → 99.0%) and out-of-distribution (ALFWorld: 92.9% → 100.0%) settings, consistently outperforming the Meta-RL baseline LaMer across both. Crucially, removing memory retrieval at test time causes only a marginal drop in single-attempt performance, suggesting the dual intrinsic feedback is largely absorbed into the policy weights during training rather than being contingent on retrieval at inference time.

On MineSweeper, the team tested generalization by training on boards with 3 mines and evaluating on boards with 4 or 5 mines. RetroAgent showed the strongest robustness of all methods tested, with graceful degradation as difficulty increased.

Line graph comparing RetroAgent against GiGPO, GRPO, LaMer, and Zero-shot on MineSweeper discovery performance across 1-3 attempts, with RetroAgent achieving 49.2% at k=3

Training efficiency and limitations

Despite requiring more total compute than vanilla GRPO, RetroAgent reaches GRPO's peak performance substantially faster. The in-context variant matches GRPO's peak at step 65, and the RL-trained variant does so at step 73, corresponding to training time reductions of 46% and 32%, respectively.

The framework has real limitations worth noting. On Llama-3.1-8B, the RL-trained variant underperforms its in-context counterpart on ALFWorld and Sokoban , the authors attribute this to interference between the self-reflection and decision-making objectives during joint optimization. Scaling from 7B to 14B parameters yields only modest gains (+0.9% to +3.8% task score), suggesting that the bottleneck is the underlying reasoning capability rather than model capacity. And the dual feedback channels can sometimes interfere with each other: when both are active simultaneously, trajectory diversity can actually decrease compared to using either signal alone.

The code for both RetroAgent variants , in-context and RL-trained self-reflection , has been publicly released.