Self-Generated In-Context Examples Improve LLM Agents for Sequential Decision-Making Tasks

Vishnu Sarukkai, Zhiqiang Xie, Kayvon Fatahalian

Introduction

Large Language Model (LLM) agents for sequential decision-making tasks—such as navigating virtual environments or generating complex code—typically rely on extensive "knowledge engineering." This process involves human developers hand-crafting prompts, designing specialized observation spaces, and providing curated examples to guide agent behavior. However, this reliance on human intervention creates a fundamental bottleneck: scaling agent performance currently requires a proportional scaling of human effort.

This paper proposes a data-centric alternative where agents autonomously bootstrap their performance by building and curating a database of their own successful past experiences. By shifting the burden from human engineering to autonomous data collection and refinement, the authors demonstrate that agents can achieve state-of-the-art results across diverse benchmarks without manual intervention.

Methodology: Autonomous Trajectory Bootstrapping

The researchers build upon a standard ReAct-style (Reasoning + Acting) agent framework, introducing three hierarchical layers of autonomous improvement:

1. Trajectory Bootstrapping (Naive Accumulation)

In the initial phase, the agent attempts a set of training tasks. Whenever it successfully completes a task, the entire trajectory—comprising the goal, high-level plans, intermediate reasoning steps, and actions—is saved to a database. During inference (test time), the agent uses Retrieval-Augmented Generation (RAG) to pull the most relevant past experiences into its prompt to guide its current decision-making.

2. Database-Level Curation (+DB-Curation)

To ensure the quality of the retrieved examples, the authors implement a strategy inspired by Population-Based Training (PBT). They maintain multiple parallel databases of trajectories. Periodically, these databases are evaluated based on the agent's success rate. The "weakest" performing databases are replaced with copies of the "strongest" ones, allowing high-performing collections of examples to propagate through the system.

3. Trajectory-Level Curation (+Exemplar-Curation)

Not all successful trajectories are equally instructive; some may succeed through luck despite suboptimal choices. The authors introduce a quality metric, $Q(\tau)$, which serves as a value function for individual trajectories. This metric measures how frequently a specific past example was retrieved during other successful tasks versus failed ones. The agent then filters its database to retain only the most "empirically useful" exemplars, preventing the learning of "bad habits."

Multi-Key Retrieval

The retrieval mechanism is optimized for sequential tasks using multi-key retrieval. Instead of a single search query, the system matches context based on three distinct keys: the global goal, the current high-level plan, and the specific reasoning step. This ensures the agent receives the most contextually relevant memory at every decision point.

Experimental Evaluation

The method was evaluated on three benchmarks requiring complex sequential reasoning:

  • ALFWorld: A text-based environment for household navigation and object manipulation.
  • InterCode-SQL: An interactive environment for writing SQL queries to answer database questions.
  • Wordcraft: A multi-step crafting task where agents combine basic elements to create target objects.

Key Results

The self-generation approach significantly outperformed baseline agents and rivaled human-engineered systems:

  • ALFWorld: Success rates increased from a 73% baseline to 93% with full curation, surpassing "AutoManual," a state-of-the-art approach using hand-crafted observation spaces.
  • Wordcraft: Performance rose from 55% to 72%.
  • InterCode-SQL: Success increased from 75% to 82%.
  • Efficiency: The authors found that a single-attempt agent using a bootstrapped database performed as well as a baseline agent given 3 to 5 independent attempts (Pass@k equivalence).

Key Insights

The "Experience Boost"

One of the most significant findings is that "practicing" on 100 tasks using a smaller, more efficient model (gpt-4o-mini) provided a larger performance boost than simply switching to a more powerful model (gpt-4o) without an experience database. This suggests that for agentic tasks, domain-specific experience can be more valuable than raw model scale.

The Necessity of Curation

While naive accumulation of successful trajectories provides an initial boost, it eventually hits diminishing returns. Without the $Q(\tau)$ metric and database-level curation, the agent's memory can become "polluted" with mediocre examples that lead to suboptimal behavior in complex scenarios.

Training-Time vs. Test-Time Compute

This approach effectively shifts the computational burden to a "training" phase of trajectory collection. At test time, the agent remains efficient, performing simple RAG lookups rather than the expensive multi-call search processes required by other high-performance agent frameworks.

Limitations and Future Directions

Currently, the system only learns from successful trajectories. The authors acknowledge that failed attempts contain valuable information regarding what actions to avoid, but credit assignment—identifying the specific step that led to failure—remains a challenge. Additionally, while the prompts are task-agnostic, the agent still requires exposure to the specific distribution of tasks it will encounter at test time. Future work may explore fine-tuning models directly on this self-generated data to internalize these "memories" into the model weights.

Summary updated

BibTeX
@inproceedings{sarukkai2025self,
  author = {Vishnu Sarukkai and Zhiqiang Xie and Kayvon Fatahalian},
  title = {{Self-Generated In-Context Examples Improve LLM Agents for Sequential Decision-Making Tasks}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2025},
  url = {https://openreview.net/forum?id=WdL3O58gde},
}
Figure