MemAgent: Reshaping Long-Context LLM with Multi-Conv RL-based Memory Agent

Hongli Yu, Tinghong Chen, Jiangtao Feng, Jiangjie Chen, Weinan Dai, Qiying Yu, Ya-Qin Zhang, Wei-Ying Ma, Jingjing Liu, Mingxuan Wang, Hao Zhou

Introduction

As Large Language Models (LLMs) are increasingly tasked with reading entire books, analyzing massive codebases, or managing long-term agent memories, they inevitably hit a "long-context bottleneck."

MemAgent is a novel agentic framework designed to solve this challenge. It allows LLMs with modest context windows (e.g., 8K tokens) to process documents millions of tokens long with minimal performance loss. By utilizing Reinforcement Learning (RL) to train a model to selectively update a fixed-length "memory" scratchpad, researchers have achieved superb results on 3.5-million-token tasks while maintaining linear computational complexity.

The Long-Context Bottleneck

Handling infinitely long documents without suffering a quadratic computation slowdown or severe performance degradation is a primary challenge in modern AI. Current solutions generally fall into three categories, each with distinct drawbacks:

  1. Length Extrapolation: Stretching the model's positional embeddings to accommodate more tokens. This often leads to a "performance cliff" where accuracy plummets beyond a certain length.
  2. Efficient Attention: Using sparse or linear attention mechanisms to reduce the standard $O(n^2)$ computational cost. However, this typically requires training a model entirely from scratch.
  3. Context Compression: Condensing information into fewer tokens. This process can be lossy and is often difficult to integrate smoothly into standard generation workflows.

The MemAgent Approach

To overcome these limitations, the authors introduce MemAgent, which shifts the burden of long-context handling from the model's underlying architecture to its learned behavior.

Comparison of standard long-context processing versus the MemAgent segmented memory approach.

Instead of attempting to ingest massive documents all at once, MemAgent employs a step-by-step workflow:

  • Segmented Processing: A massive document (e.g., 1M tokens) is broken down into manageable chunks (e.g., 5,000 tokens).
  • Fixed-Length Memory: The model maintains a compact, fixed-size "memory" scratchpad (e.g., 1,024 tokens). For each text chunk, the model reads the current memory alongside the new chunk and generates an updated memory state.
  • Overwrite Strategy: Crucially, the model is trained to proactively overwrite old memory with new, relevant information. This keeps the active context window fixed, ensuring that total computation scales linearly ($O(N)$) relative to the document length, avoiding the quadratic explosion of standard Transformers.

Training with Multi-Conv DAPO

For this system to work, the model must learn what is worth remembering and what can be safely forgotten. The authors found that simply prompting a model to manage memory is insufficient; RL training is the "secret sauce" needed to teach the model to be a smart editor.

To achieve this, the researchers extended the Direct Alignment Policy Optimization (DAPO) algorithm to a "Multi-Conv" setting. This allows the model to be trained end-to-end: it receives a reward based on the correctness of its final answer, and this reward propagates back to optimize every intermediate memory-update "conversation" that led to that answer. Because the model is optimized to produce a correct final output, it naturally learns to resist common pitfalls like the "lost-in-the-middle" phenomenon.

Key Results

The models (based on Qwen2.5-7B and 14B) were trained in two stages using synthetic QA instances and high-quality long-text QA instances. Evaluation across rigorous benchmarks (RULER-HQA, LongBench, and NIAH) revealed exceptional capabilities:

Performance comparison across context lengths up to 3.5M tokens.
  • Extreme Extrapolation: A model trained on sequences of only 60K tokens successfully handled a 3.5-million-token QA task with less than 10% performance loss. As shown in the figure above, baseline models suffer catastrophic failure at these lengths.
  • Needle Retrieval: MemAgent achieved over 95% accuracy on the 512K Needle In A Haystack (NIAH) test, significantly outperforming baseline models like QwenLong-L1-32B, which saw performance drop to near zero at similar lengths.
  • State-of-the-Art Summarization: On LongBench-SUM (GovReport and QMSum), MemAgent achieved SOTA results, proving that its learned memory management generalizes beyond simple fact retrieval to complex synthesis.

Limitations and Future Work

Despite its success, the authors identified three main failure patterns that highlight areas for future improvement:

  1. Information Overwritten: If the model fills its limited memory capacity with early, irrelevant information, it might lack space for crucial clues that appear later in the text.
  2. Missing Critical Info: In complex multi-hop questions, the model might discard an early "clue" because it doesn't yet realize its relevance to a second "clue" it hasn't encountered yet.
  3. Primacy Bias: The model sometimes clings to early assumptions (e.g., assuming a "country" refers to a nation when later context implies the countryside) even after seeing contradictory evidence.

Future work will likely focus on more advanced memory architectures and training strategies to handle these complex reasoning dependencies, further pushing the boundaries of infinite-context LLMs.

Summary updated

BibTeX
@inproceedings{yu2026memagent,
  author = {Hongli Yu and Tinghong Chen and Jiangtao Feng and Jiangjie Chen and Weinan Dai and Qiying Yu and Ya-Qin Zhang and Wei-Ying Ma and Jingjing Liu and Mingxuan Wang and Hao Zhou},
  title = {{MemAgent: Reshaping Long-Context LLM with Multi-Conv RL-based Memory Agent}},
  booktitle = {International Conference on Learning Representations},
  year = {2026},
  url = {https://openreview.net/forum?id=k5nIOvYGCL},
}
Figure