Training Language Agents to Learn from Experience

Yuval Shalev, Zifeng Ding, Mateja JamnikOpenReview 2027 · Submission to ICLR 2027 · Withdrawn

This paper, a submission for ICLR 2027, tackles one of the most persistent hurdles in autonomous AI: moving from "fixing a mistake" to "learning a lesson." While current LLM agents are great at retrying a failed task until they succeed, they often fail to carry those hard-won insights over to the next challenge.

TL;DR

The authors introduce In-context Training (ICT), a framework where a "reflector" LLM learns to distill an agent's raw experiences into generalized system prompts. By training this reflector using reinforcement learning, they demonstrate that agents can achieve cross-task self-improvement, outperforming baseline models on entirely unseen task types across diverse benchmarks.

What Problem Does This Paper Address?

Most current "self-reflecting" agents operate on a trial-and-error basis within a single task instance. If an agent fails to find a key in a dungeon, it reflects on that failure and tries the same dungeon again. This is "instance-specific" learning.

The real world, however, rarely offers exact retries. If you burn a meal, you can’t "undo" the ingredients; you have to learn a general rule about heat management for the next meal. The authors identify a gap in research regarding cross-task generalization: can an agent observe its failures on Task A and generate a "lesson" (in the form of a system prompt) that makes it better at Task B?

Methods

The researchers propose a dual-LLM architecture consisting of an Actor (which performs tasks) and a Reflector (which learns from the Actor).

The In-context Training (ICT) Task

In the ICT framework, the process follows a "meta-loop":

  1. Interaction: The Actor attempts a batch of tasks using a system prompt.
  2. Reflection: The Reflector analyzes the Actor’s trajectories (successes and failures).
  3. Optimization: The Reflector generates a revised system prompt designed to improve the Actor's future performance.
  4. Evaluation: This new prompt is tested on a fresh batch of unseen tasks.
Figure 1: The In-context Training (ICT) task. At each meta-turn, the reflector uses the actor’s previous trajectories to revise its system prompt, after which the actor attempts a new batch of unseen tasks. Each prompt is subsequently evaluated on a fixed held-out set of tasks. In our experiments, we fine-tune the reflector while keeping the actor model frozen.

RL-Based Training Pipeline

To train the Reflector without needing human-labeled "good reflections," the authors use Group Relative Policy Optimization (GRPO). During training, the Reflector generates multiple candidate prompts. These candidates are "replayed" on the previous batch of tasks; the prompts that lead to the highest average reward are used to update the Reflector’s parameters. This allows the model to discover effective reflection strategies autonomously.

Figure 2: One reflector-training step on an ALFWorld-Cool and Place example. A system prompt and its episode batch are sampled from the dataset and fed into the reflector, which generates multi- ple candidate system prompts. Each candidate is scored by replaying the same tasks with the frozen actor and the resulting scores drive advantage estimation and parameter updates via GRPO.

Datasets

The authors evaluated their approach on two major agentic benchmarks:

  • ALFWorld: A text-based environment for household tasks (e.g., "put a cool apple in the garbage can").
  • MiniHack: A grid-world based on the game NetHack, requiring complex navigation and item interaction.

Crucially, they used Task Partitioning: the Reflector was trained on specific task types (e.g., "Clean and Place") and evaluated on completely different, held-out task types (e.g., "Cool and Place") to prove it wasn't just memorizing solutions.

They also introduced MetaGym, a new Python library designed to wrap standard Gym environments into "meta-environments" specifically for training self-improving agents.

Key Insights and Ideas

  • Learning to Learn is a Learnable Skill: The study shows that the ability to extract "reusable lessons" isn't just an emergent property of scale; it can be explicitly trained into smaller models (like Qwen2.5-7B).
  • Prompting as Policy: Instead of expensive gradient-based fine-tuning of the Actor for every new environment, the Reflector treats the system prompt as a "soft policy" that can be updated in natural language.
  • Transparency: Because the "learned experience" is stored as a natural language prompt, humans can inspect exactly what the agent thinks it has learned (e.g., "Remember to look for a fridge to cool items").
  • Cross-Model Transfer: A Reflector trained to help a Qwen actor can successfully improve a Llama actor, suggesting that the "lessons" discovered are somewhat model-agnostic.

Key Results

The trained reflectors consistently outperformed untrained baselines (LLMs prompted to reflect but not fine-tuned for it):

  • ALFWorld: The trained Qwen2.5 reflector improved success rates by +9.9% over the baseline; the Llama3.1 version saw a massive +17.4% jump.
  • MiniHack: Improvements were +3.9% (Qwen) and +13.5% (Llama).
  • Cross-Benchmark Generalization: In a surprising "aha" moment, a reflector trained only on MiniHack (grid worlds) still improved performance when tested on ALFWorld (textual house tasks) by 3.7%, proving the reflection strategies are highly transferable.
  • Horizon Extension: Even though the models were only trained on 4 "meta-turns" of reflection, they continued to improve the actor's performance when allowed to run for 10 turns during testing.
Success rates over meta-turns, showing continued improvement beyond the training horizon.

Limitations and Future Work

  • Compute Overhead: Running two LLMs (Actor and Reflector) simultaneously is memory-intensive. The authors suggest future work could explore "self-reflection" within a single model to save resources.
  • Validation Dependency: The current ICT loop relies on a fixed validation set to pick the "best" prompt. In a truly open-ended environment, such a set might not exist, requiring more robust online stopping criteria.
  • Long-term Stability: It remains unclear if prompts will eventually "drift" or degrade if the reflection loop continues indefinitely (lifelong learning).

Overall, this work moves the needle for AI agents from simple "patching" of errors toward a more human-like ability to build a repertoire of general strategies from past experiences.

Summary updated

Abstract

Language agents can adapt from experience in interactive environments, but current reflection-based methods primarily self-correct by retrying the same task instance. Whether such experience can be distilled into reusable lessons that improve performance on future unseen tasks remains unclear. We address this problem by introducing the In-context Training (ICT) task, a framework for evaluating cross-task self-improvement in language agents. In ICT, a reflector model observes actor trajectories and generates system prompts intended to improve the actor's performance on future unseen tasks. We also propose an RL-based pipeline for training reflectors directly from experience, without human-provided examples. Across ALFWorld and MiniHack, our trained reflectors outperform matched untrained baselines on all six held-out task types, showing that the ability to learn from experience can itself be learned. These gains extend across two model families and to a different actor, with initial evidence of cross-benchmark transfer. Finally, we introduce MetaGym, a Python library for constructing meta-environments for self-improving language agents.
BibTeX
@misc{shalev2027training,
  author = {Yuval Shalev and Zifeng Ding and Mateja Jamnik},
  title = {{Training Language Agents to Learn from Experience}},
  year = {2027},
  url = {https://openreview.net/forum?id=TGzO41uNoF},
  howpublished = {OpenReview},
  note = {Submitted to ICLR 2027},
}

Loading related content...

Figure