MemSearcher: Training LLMs to Reason, Search and Manage Memory via End-to-End Reinforcement Learning

Qianhao Yuan, Jie Lou, Zichao Li, Jiawei Chen, Yaojie Lu, Hongyu Lin, Le Sun, Debing Zhang, Xianpei Han

TL;DR

MemSearcher is a novel framework for LLM-based search agents that replaces the traditional, ever-growing interaction history with a compact, iteratively updated natural language memory. By utilizing a new multi-context GRPO reinforcement learning algorithm, MemSearcher achieves superior task accuracy over standard ReAct baselines while maintaining a flat, stable context length under 4K tokens across multi-turn interactions.

What Problem Does This Paper Address?

When large language models (LLMs) act as search agents, they typically follow the ReAct (Reasoning + Acting) paradigm. In a multi-turn interaction, a ReAct agent continuously appends the entire history of thoughts, tool actions, and raw search engine observations into the prompt context.

This design suffers from a fundamental bottleneck: as the number of interaction turns increases, the context length grows linearly ($O(n)$). For search agents, these prolonged contexts are dominated by noisy, irrelevant web snippets. This not only incurs massive computational and GPU memory overhead (scaling quadratically in total FLOPs) but also degrades the LLM's reasoning capabilities due to the "lost in the middle" phenomenon, where models struggle to extract salient facts from bloated inputs.

Methods

1. Iterative Memory Integration

Instead of concatenating the entire history, MemSearcher prompts the backbone LLM to act as an intrinsic memory manager. At any given turn $i$, the model receives only two succinct inputs: the user's original question $q$ and a compact natural language memory $m_{i-1}$ summarizing key facts from previous turns.

Comparison between ReAct and MemSearcher workflows

Once the search engine returns a new observation, the LLM overwrites the old memory with an updated version ($m_i$), strictly bounded by a predefined maximum length (e.g., 1,024 tokens). This keeps the context size per turn at $O(1)$ efficiency.

2. Multi-Context GRPO

Training an agent to manage its own memory via standard Supervised Fine-Tuning (SFT) is incredibly difficult and expensive because it requires token-level annotations of what the intermediate memory should look like. Reinforcement Learning (RL) is a natural alternative, but standard Group Relative Policy Optimization (GRPO) assumes a single, static context per trajectory.

Because MemSearcher discards raw history and updates its memory at every step, a single trajectory spans multiple turns under completely different LLM contexts. To solve this, the authors introduce Multi-Context GRPO. This algorithm computes a trajectory-level advantage based on the final answer's correctness and uniformly propagates it back to every individual turn, optimizing each turn independently as a distinct target.

Multi-context GRPO framework

Datasets

The authors evaluated MemSearcher across seven prominent public knowledge-acquisition and multi-hop question-answering benchmarks:

  • Natural Questions (NQ) & HotpotQA (used for both training rollouts and evaluation)
  • TriviaQA, PopQA, Bamboogle, Musique, and 2WikiMultiHopQA (used strictly for out-of-distribution evaluation)

Key Insights and Ideas

  • Less Noise, Better Reasoning: Compressing search results into a clean, factual memory prevents the model from getting confused by cross-turn entity relationships. In ReAct, long contexts often cause the model to misattribute relationships across different retrieved passages.

    Figure 2: Comparison between ReAct and MemSearcher. ReAct accumulates all intermediate content in the context, leading to an incorrect answer by confusing the character’s girlfriend with the actor’s on-screen relationship. In contrast, MemSearcher maintains an independent context for each turn via a compact memory storing only task-relevant facts, which helps disambiguate entities and relations across turns and yields the correct answer.
  • RL Autonomously Learns "What to Forget": While SFT distillation from a larger model (like Qwen2.5-72B) yields mediocre results due to the teacher model not being optimized for memory management, RL directly rewards final answer accuracy. This forces the model to independently discover what information is essential to retain and what is safe to discard.

  • Linear Compute Scaling: By capping the memory size, the total FLOPs required for an $n$-turn interaction scale linearly ($O(n)$) rather than quadratically ($O(n^2)$), making long-running search agents viable in resource-constrained environments.

Key Results

  • State-of-the-Art Efficiency: While ReAct-based agents (like ReSearch) see their context window explode to over 16,000 tokens by turn 10, MemSearcher maintains a nearly flat token count well under 4,000 tokens across all turns.

    Figure 4: Comparison of the average token numbers in the LLM context between MemSearcher and ReAct- based ReSearch (Chen et al., 2025b).
  • Punching Above Its Weight Class: MemSearcher consistently outperformed much larger ReAct baselines. Specifically, MemSearcher 3B achieved an average score of 43.8 across the seven benchmarks, outperforming multiple 7B baselines. Meanwhile, MemSearcher 7B scored 48.9, outperforming the 32B parameter ReSearch baseline (48.3).

Limitations and Future Work

  • Simple Memory Architecture: The current framework relies on a flat natural language block for memory. The authors note that integrating more sophisticated memory structures, such as structured knowledge graphs or RAG-style external vector databases, warrants further investigation.
  • RL Length Bias: Multi-context GRPO is susceptible to potential generation length biases during the RL rollout phase, indicating a need for advanced reward-shaping techniques to further stabilize training.

Summary updated

BibTeX
@misc{yuan2025memsearcher,
  author = {Qianhao Yuan and Jie Lou and Zichao Li and Jiawei Chen and Yaojie Lu and Hongyu Lin and Le Sun and Debing Zhang and Xianpei Han},
  title = {{MemSearcher: Training LLMs to Reason, Search and Manage Memory via End-to-End Reinforcement Learning}},
  year = {2025},
  eprint = {2511.02805},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2511.02805},
}
Figure