Sample-Efficient Online Learning in LM Agents via Hindsight Trajectory Rewriting
Hu, Van Durme, Andreas et al.
Language model (LM) agents deployed in novel environments often exhibit poor sample efficiency when learning from sequential interactions. This significantly hinders the usefulness of such agents in environments where interaction is costly (for example, when they interact with humans or reset physical systems). While a number of existing LM agent architectures incorporate various mechanisms for experience storage and reflection, they make limited use of LMs' abilities to directly generate or reason about full counterfactual trajectories. We introduce ECHO (Experience Consolidation via Hindsight Optimization), a prompting framework that adapts hindsight experience replay from reinforcement learning for language model agents. ECHO generates optimized trajectories for alternative goals that could have been achieved during failed attempts, effectively creating synthetic positive examples from unsuccessful interactions. Our approach consists of two components: a hindsight rule that uses the language model itself to identify relevant subgoals and generate optimized trajectories, and an update rule that maintains compressed trajectory representations in memory. We evaluate ECHO on stateful versions of XMiniGrid, a text-based navigation and planning benchmark, and PeopleJoinQA, a collaborative information-gathering enterprise simulation. Across both domains, ECHO outperforms vanilla language agent baselines by up to 80%; in XMiniGrid, it also outperforms a number of sophisticated agent architectures including Reflexion and AWM, demonstrating faster adaptation to novel environments through more effective utilization of past experiences.
academic
Sample-Efficient Online Learning in LM Agents via Hindsight Trajectory Rewriting
Language model (LM) agents often exhibit poor sample efficiency when learning through sequential interactions in new environments. This severely limits the practical deployment of such agents in high-cost interaction scenarios (e.g., human-agent interaction or physical system resets). While existing LM agent architectures incorporate various experience storage and reflection mechanisms, they underutilize the LM's capacity to directly generate or reason about complete counterfactual trajectories. This paper introduces ECHO (Experience Consolidation via Hindsight Optimization), a prompting framework that adapts hindsight experience replay from reinforcement learning to language model agents. ECHO generates optimized trajectories for alternative goals that could have been achieved in failed attempts, effectively creating synthetic positive examples from unsuccessful interactions. The method comprises two components: hindsight rules that use the language model itself to identify relevant subgoals and generate optimized trajectories, and update rules that maintain compressed trajectory representations in memory.
Low Sample Efficiency: LM agents exhibit poor sample efficiency when learning in new environments, particularly in high-cost interaction scenarios
Limited Counterfactual Reasoning: Existing methods primarily focus on storing or synthesizing experiences without fully leveraging the LM's ability to reason about counterfactual trajectories
Sparse Reward Environments: Agents struggle to learn from failed experiences in reward-sparse settings
Practical Application Needs: Improving sample efficiency is critical in high-cost scenarios such as human-agent interaction or physical system resets
Adaptation Requirements: Agents need to rapidly adapt to new environments, such as conversational assistants learning information retrieval and communication strategies in new organizations
Consider an online setting where an LM agent sequentially processes a query sequence from time t=0 to T without access to true reward functions or demonstration data. The agent must learn through environment interaction and improve the efficiency of future decisions.
Andrychowicz, M., et al. (2017). Hindsight experience replay. NIPS.
Shinn, N., et al. (2023). Reflexion: language agents with verbal reinforcement learning. NIPS.
Wang, Z. Z., et al. (2025). Agent workflow memory. ICML.
Yao, S., et al. (2023). React: Synergizing reasoning and acting in language models. ICLR.
Overall Assessment: The ECHO framework proposed in this paper achieves important progress in sample-efficient learning for LM agents. The method is novel and experimental results are convincing. While certain limitations exist, it establishes a solid foundation for future development in this field and demonstrates high academic value and practical application potential.