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

International Conference on Learning Representations 2026 · Oral

Overview

The proliferation of large language models (LLMs) has underscored the critical importance of processing ultra-long input contexts for advanced reasoning and generation tasks. As the complexity and length of generated text correlate with perceived intelligence, the challenge of extending LLMs beyond their inherent context window limitations has become a central research frontier. This talk introduces MemAgent, a novel framework designed to address this challenge by endowing LLMs with robust memory capabilities through a unique combination of simple memory mechanisms and reinforcement learning (RL) training. Departing from conventional architectural modifications, MemAgent offers a token-to-token, text-level approach, enabling LLMs to handle arbitrarily long inputs without altering their core inference or training infrastructure.

Watch on SlidesLive

Visual summary for MemAgent: Reshaping Long-Context LLM with Multi-Conv RL-based Memory Agent by Hongli Yu, Tinghong Chen, Jiangtao Feng, Jiangjie Chen, Weinan Dai, Qiying Yu, Ya-Qin Zhang, Wei-Ying Ma, Jingjing Liu, Mingxuan Wang, Hao Zhou
Visual summary for MemAgent: Reshaping Long-Context LLM with Multi-Conv RL-based Memory Agent by Hongli Yu, Tinghong Chen, Jiangtao Feng, Jiangjie Chen, Weinan Dai, Qiying Yu, Ya-Qin Zhang, Wei-Ying Ma, Jingjing Liu, Mingxuan Wang, Hao Zhou

Key moments

  1. 1:00 MemAgent: Token-to-token approach, no model architecture modification.
  2. 2:15 MemAgent's two-stage design and multi-conversation DPO training.
  3. 4:00 Achieving near-lossless extrapolation to 35 million tokens.
  4. 5:00 Reinforcement learning is critical for effective memory processing.
  5. 6:00 Case study: MemAgent's iterative information processing and retention.
  6. 8:00 Q&A: Rationale for fixed 1024-token memory length.

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

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

Conference: ICLR 2026

YouTube: https://slideslive.com/39062200

Overview

The proliferation of large language models (LLMs) has underscored the critical importance of processing ultra-long input contexts for advanced reasoning and generation tasks. As the complexity and length of generated text correlate with perceived intelligence, the challenge of extending LLMs beyond their inherent context window limitations has become a central research frontier. This talk introduces MemAgent, a novel framework designed to address this challenge by endowing LLMs with robust memory capabilities through a unique combination of simple memory mechanisms and reinforcement learning (RL) training. Departing from conventional architectural modifications, MemAgent offers a token-to-token, text-level approach, enabling LLMs to handle arbitrarily long inputs without altering their core inference or training infrastructure.

Presented by Hongli Yu, a first-year PhD student and intern at ByteDance Seed, this work from ByteDance Seed, CLab, and Tsinghua University's AIR presents a compelling alternative to existing long-context solutions. The core innovation lies in training an LLM to intelligently manage context by processing information iteratively, summarizing relevant chunks into a fixed-length memory, and leveraging this compressed representation for accurate responses. The talk highlights MemAgent's ability to achieve near-lossless extrapolation to unprecedented context lengths, demonstrating its effectiveness across various tasks and underscoring the indispensable role of reinforcement learning in cultivating true memory processing capabilities within LLMs.

The significance of MemAgent extends beyond merely increasing context length; it redefines how LLMs interact with vast amounts of information. By focusing on what to memorize and how to utilize that memory effectively, MemAgent empowers models to discern critical information from noise, maintain focus, and overcome common pitfalls like "lost in the middle" or "information overwritten." This approach has profound implications for the development of highly intelligent, context-aware AI agents capable of tackling complex, real-world problems that demand deep comprehension of extensive documents and conversations.

Background

▶ Watch: MemAgent: Token-to-token approach, no model architecture modification. (1:00)

The ability of large language models (LLMs) to process and understand long input contexts is paramount for achieving sophisticated reasoning, summarization, and question-answering capabilities. In the first half of 2024, the field witnessed a significant surge in interest in Reinforcement Learning from Human Feedback (RLHF) and its variants, pushing the boundaries of what LLMs could achieve. Concurrently, the demand for LLMs to handle ever-longer inputs became more pressing, as the intelligence of a reasoning model is often perceived to increase with its ability to generate or process extended text.

Prior to MemAgent, several methodologies emerged to tackle the ultra-long context problem, broadly categorized into:

  1. Extrapolation Methods: These techniques aim to extend the effective context window of existing attention mechanisms, often by modifying positional encoding schemes (e.g., RoPE, ALiBi) to generalize to unseen lengths. While effective to a degree, they often face performance degradation when extrapolating significantly beyond their training context length.
  2. High-Efficiency Attention Mechanisms: Innovations like Sparse Attention, LongNet, FlashAttention, or Linear Attention reduce the quadratic computational complexity of standard self-attention, enabling processing of longer sequences. These methods typically involve architectural changes to the attention layer itself.
  3. Context Compression Methods: Approaches such as Retrieval-Augmented Generation (RAG) or summarization-based techniques pre-process the input to extract relevant information, which is then fed into the LLM. While effective, many of these are often external systems or require specific fine-tuning strategies.

A common characteristic of most existing long-context solutions is their reliance on modifications at the model architecture layer. This often necessitates changes to the LLM's inference engine or training infrastructure, adding complexity and potentially requiring re-training or significant fine-tuning of base models. For instance, modifying the attention mechanism requires deep integration with the underlying computational graph and hardware accelerators.

In parallel, "agent methods" for memory management have also been explored. These typically involve external tools such as writing documents or maintaining databases. However, many of these agentic approaches are either too trivial to integrate seamlessly with an LLM's training recipe or too complex to manage effectively in a dynamic, token-by-token processing environment. They often lack the integrated learning mechanism to truly teach the LLM how to manage its own context dynamically and intelligently.

MemAgent addresses these limitations by proposing a fundamentally different paradigm. Instead of modifying the model architecture, it operates at a token-to-token, text-level processing layer. The core idea is to train the model how to process context, rather than how to compute attention more efficiently or how to structurally extend its context window. This approach seeks a simpler, yet powerful, memory mechanism combined with reinforcement learning to empower the LLM itself to manage its context, mimicking human-like cognitive processes of summarizing and recalling information. The inherent challenge lies in training an LLM to manage context when the typical output is a sequential concatenation, whereas context management necessitates breaking the prefix cache and handling independent context segments effectively.

Key Findings

▶ Watch: Achieving near-lossless extrapolation to 35 million tokens. (4:00)

The research on MemAgent yielded several pivotal findings that challenge conventional approaches to long-context LLMs and highlight the transformative power of a memory agent trained with reinforcement learning:

  1. Near-Lossless Extrapolation to Ultra-Long Contexts: MemAgent demonstrated an unprecedented ability to extrapolate to extremely long input sequences, reaching up to 35 million tokens from a training context window of only 8192 tokens. This represents a near-lossless performance, significantly outperforming traditional long-context methods that suffer severe performance degradation when pushed beyond their trained context length. The iterative processing and fixed-length summarization strategy proved highly effective in maintaining performance across vast input sizes.
  1. Generalizability Across Diverse Tasks: The memory capability imparted by MemAgent is not confined to specific types of tasks. Experiments showed that the framework performs well not only in complex Question Answering (QA) tasks but also in summary tasks. This indicates that the acquired ability to "memorize what is needed and how to use it" is a generalized skill, making MemAgent a versatile solution for various long-document understanding applications.
  1. Reinforcement Learning as the Critical Enabler: A key finding was the indispensable role of reinforcement learning in MemAgent's success. Without RL training, a simple application of the MemAgent mechanism (e.g., iterative summarization) showed limited effectiveness, especially in tasks requiring high information density or very long iterative processing. The LLM, without RL, "doesn't know how to memorize the critical things" or "how to process them iteratively." RL is crucial for enabling smooth extrapolation and intelligent context management, teaching the model to discern and retain vital information.
  1. Robustness Against Information Loss Challenges: The study specifically addressed common failure modes in long-context processing, such as the "information overwritten problem" (forgetting initial information) and the "lost in the middle problem" (missing information located in the middle of the context). Through proper RL training and by incorporating diverse context distribution patterns (e.g., shuffling context) in the training dataset, MemAgent demonstrated robustness against these corner cases. This suggests that the model learns to adapt its memory strategy based on the distribution of critical information within the input.
  1. Effective Memory Capability: The core contribution is the framework's ability to equip LLMs with a genuine "memory capability." This capability is defined as the ability to:
  • Remember what you need: Discerning relevant information from irrelevant noise.
  • Keep and maintain it: Retaining critical information across chunks without distraction.
  • Use them to answer the question: Effectively leveraging the accumulated memory to formulate accurate and contextually relevant responses.

These findings collectively establish MemAgent as a highly effective and architecturally lightweight solution for ultra-long context processing, with reinforcement learning serving as the lynchpin for its superior performance and adaptability.

Technical Deep Dive

▶ Watch: Reinforcement learning is critical for effective memory processing. (5:00)

MemAgent's innovative approach to ultra-long context processing is built upon a two-stage design coupled with a specialized reinforcement learning algorithm. Unlike methods that modify the underlying transformer architecture, MemAgent focuses on a token-to-token, text-level context management strategy.

MemAgent Design: A Two-Stage Memory Agent

The MemAgent framework is designed as a simple yet powerful agent that operates in two distinct stages:

  1. Memory Processing Stage:
  • Context Chunking: The initial ultra-long input context is first segmented into smaller, manageable text chunks. The specific size of these chunks is not explicitly stated but implied to be within the base LLM's standard context window.
  • LLM Summarization: For each text chunk, a large language model (LLM) is employed to summarize its content. The crucial aspect here is that this summary is constrained to a fixed-length memory, specifically no more than 1024 tokens. This fixed length is a deliberate design choice, aiming to compress information efficiently while maintaining a manageable memory footprint.
  • Iterative Processing: This summarization process is applied iteratively. The LLM processes one chunk at a time, incorporating its summary into an accumulating memory. This means that as new chunks are processed, the model's "understanding" of the overall context evolves, building upon previously summarized information.
  • Accumulated Memory: The output of this stage is a collection of summaries, representing the distilled essence of the entire ultra-long input. Critically, the total accumulated memory (i.e., the concatenated summaries) is also capped at no more than 1024 tokens. This strict limit forces the LLM to be highly selective and concise in what it retains, emphasizing the extraction of only the most critical information.
  1. Answering Stage:
  • Once all context chunks have been iteratively processed and the final accumulated memory has been formed, the LLM is then prompted to answer the given question. The answer generation is based solely on this accumulated memory, which, as established, is limited to 1024 tokens. This separation ensures that the LLM focuses its reasoning on the most pertinent information it has extracted and retained.

The elegance of this design lies in its simplicity and its ability to circumvent the quadratic complexity and memory constraints of processing ultra-long sequences directly. By compressing vast contexts into a fixed-length, relevant memory, MemAgent effectively transforms an intractable problem into a series of manageable sub-problems, each within the LLM's native capabilities. The fixed 1024-token memory limit, while seemingly restrictive, was shown to be sufficient for the tasks evaluated, suggesting that for many applications, the quality and relevance of information are more important than its sheer volume.

Reinforcement Learning for Memory Management

The success of MemAgent hinges critically on its reinforcement learning (RL) training, which teaches the LLM how to perform the memory processing effectively. Without RL, the LLM simply lacks the ability to discern critical information or manage the iterative summarization process intelligently.

The RL algorithm employed is a variant of Direct Preference Optimization (DPO), specifically described as a GRPO-like RL algorithm. It is characterized as a multi-conversation version of DPO, designed to handle sequences of interactions rather than single turn preferences.

  • Multi-Conversation Context: In a typical chatbot or agentic scenario, the interaction involves multiple turns or "conversations." MemAgent's RL setup leverages this multi-turn structure.
  • Reward Signal: The key innovation for the reward mechanism is that the last conversation in a sequence is used to generate the reward signal. This implies that the model's overall performance in the final interaction, after processing a series of chunks and queries, dictates the learning signal.
  • Advantage Assignment: For all conversations within a single input-output pair (i.e., all iterative steps leading to a final answer), they are assigned the same advantage. This "single advantage" approach simplifies the reward propagation and ensures that the model learns to optimize the entire memory management trajectory, from initial chunk processing to the final answer, as a coherent unit.

This multi-conversation DPO variant provides a robust training signal for the complex, iterative memory management process. It teaches the LLM not just to summarize, but to summarize strategically, identifying and retaining information that will be critical for subsequent reasoning and final answer generation, even across many processing steps and potential distractions. The RL component essentially imbues the LLM with the ability to learn a policy for effective context management, transforming raw summarization into intelligent information curation.

Experimental Setup & Results

▶ Watch: Case study: MemAgent's iterative information processing and retention. (6:00)

To rigorously evaluate MemAgent, a comprehensive experimental setup was designed, encompassing specialized datasets for training and evaluation, comparisons against existing methods, and ablations to highlight the critical role of reinforcement learning.

Datasets

The development and evaluation of MemAgent relied on a combination of custom-built and adapted datasets:

  1. Ruler Dataset (Training & Evaluation):
  • Purpose: To create a context-length controllable data set for both training and evaluation, specifically designed to test the model's ability to handle varying and extremely long inputs.
  • Construction: This dataset is based on multi-hop Question Answering (QA) derived from Wiki item entities.
  • Composition: Each QA instance is constructed with:
  • Golden items: Directly relevant information needed to answer the question.
  • Hard negative items: Seemingly relevant but ultimately misleading information.
  • Irrelevant items: Distractor information added to artificially extend the context length.
  • Controllability: By adjusting the number of irrelevant items, the researchers could generate contexts of arbitrary length, enabling precise testing of extrapolation capabilities. This dataset was crucial for demonstrating MemAgent's ability to scale to 35 million tokens.
  1. Qianwen L1 (DocQA RL) (Generalization Training):
  • Purpose: To enhance the model's generalization capabilities to a broader range of tasks beyond the synthetic Ruler dataset, ensuring high-quality QA performance.
  • Adaptation: The training set of Qianwen L1 (DocQA RL) was adapted. This dataset is known for its high-quality question-answering pairs, providing a rich source of real-world knowledge and reasoning challenges.
  1. Needle In A Haystack (Evaluation):
  • Purpose: A standard benchmark for evaluating the ability of long-context models to retrieve specific, critical information ("the needle") embedded within a vast amount of irrelevant text ("the haystack"). This directly tests the model's robustness against the "lost in the middle" problem.
  1. LongBench (Evaluation):
  • Purpose: A comprehensive benchmark suite designed to evaluate long-context LLMs across various tasks, including summarization, question answering, and code generation. MemAgent was tested on "other test sets of LongBench," indicating a broad assessment of its capabilities.

Baselines

While specific baseline models or architectures were not explicitly named, the presentation contrasted MemAgent's performance with "traditional long context methods." These methods were characterized by a "very severe performance degradation in the out of the training length or out of the context length." This implies a comparison against transformer-based models that attempt direct context extension or more naive summarization techniques without the benefit of RL-trained memory management.

Headline Results & Ablations

The experiments yielded compelling evidence for MemAgent's effectiveness:

  1. Ultra-Long Context Extrapolation:
  • Headline Number: MemAgent, trained with an effective context window of 8192 tokens, demonstrated the ability to scale up to 35 million tokens of input context.
  • Performance: This extrapolation was described as "near lossless," indicating that the model maintained high performance even at these extreme lengths, a significant improvement over traditional methods which typically fail far earlier.
  1. Generalization Across Tasks:
  • MemAgent proved effective not only in QA tasks (as primarily evaluated by Ruler and Qianwen L1) but also in summary tasks (likely evaluated on parts of LongBench). This highlights the versatility of its learned memory capabilities.
  1. Crucial Role of Reinforcement Learning:
  • Ablation Study: A direct comparison between MemAgent with and without RL training revealed that RL was "the key point to keep the extrapolation smoothly works."
  • Observation: Without RL, the LLM "just don't know how to memorize the critical things and don't know how to process them iteratively especially in the very very long process." This confirms that the multi-conversation DPO algorithm is essential for teaching the model intelligent context management, rather than just raw summarization.
  1. Robustness to Information Distribution Patterns:
  • Challenge: The talk addressed concerns about "information overwritten" (forgetting early information) and "lost in the middle" problems.
  • Solution & Result: By training MemAgent with a "proper way" including shuffling the context and incorporating "all of this distribution patterns concluded in your training data set," the model showed improved generalization and better performance across different patterns of context distribution. This indicates that the RL training enables the model to strategically manage memory regardless of where key information is located.

Case Study: Memory Capability in Action

A qualitative case study provided insight into how MemAgent processes information:

  • Chunk 1: The model identifies information that "looks like relevant about the question but it's actually not." It decides to "keep tracking on it to see if it works," demonstrating a cautious and exploratory memory strategy.
  • Chunk 2: Finding "nothing relevant," the model "maintain[s] my memory unchanged," showcasing its ability to avoid distraction and conserve memory resources.
  • Final Chunks: Upon encountering "some really relevant message," the model "keep[s] them" and also retains the initial (though less relevant) message from Chunk 1.
  • Outcome: The model successfully "collect[s] all the things it need to get to the answer," illustrating its ability to accumulate and synthesize critical information from disparate parts of a long document. This demonstrates the learned capability to remember what's needed, maintain it without distraction, and ultimately use it to answer questions.

Overall, the experimental results unequivocally support MemAgent's effectiveness as a novel, RL-driven solution for ultra-long context processing, demonstrating significant advancements in extrapolation, task generalization, and robustness.

Practical Implications

▶ Watch: Q&A: Rationale for fixed 1024-token memory length. (8:00)

MemAgent presents several significant practical implications for practitioners, infrastructure teams, model builders, and deployers working with large language models, particularly in scenarios demanding ultra-long context understanding.

  1. Democratization of Ultra-Long Context Processing: The most profound implication is the ability to process truly ultra-long inputs (up to 35 million tokens) without requiring modifications to the core LLM architecture or its underlying inference engine. This is a game-changer for many organizations. Historically, extending context windows meant significant engineering effort, potentially re-training costly models, or relying on specialized hardware. MemAgent offers a text-level, token-to-token solution that can be applied on top of existing LLMs, making advanced long-context capabilities more accessible.
  1. Reduced Infrastructure Complexity: For infrastructure teams, MemAgent simplifies the deployment and scaling of long-context applications. By compressing vast inputs into a fixed-length memory (max 1024 tokens) for the final LLM inference, it alleviates the memory and computational burden associated with feeding extremely long sequences directly into the model. This can lead to more efficient GPU utilization, lower latency for long-context queries, and potentially reduced hardware requirements compared to methods that require massive context windows.
  1. Enhanced Model Capabilities for Real-World Applications: Model builders can leverage MemAgent to create more intelligent and capable AI agents. Tasks such as summarizing lengthy financial reports, analyzing legal documents, processing extensive academic papers, or maintaining context in prolonged multi-turn conversations become more feasible and robust. The learned memory capability, which involves discerning critical information and ignoring noise, leads to more accurate and relevant outputs, even in the presence of significant distractors.
  1. Flexibility in Context Management: MemAgent's approach allows for dynamic context management. Instead of a rigid context window, the model learns to adaptively summarize and retain information. This flexibility means it can handle varying information densities and distributions within long documents, mitigating issues like "lost in the middle" or "information overwritten" that plague fixed-window models. The ability to generalize across different patterns of context distribution (e.g., shuffling in training) implies a more robust and adaptable system.

Tradeoffs and Limitations

While highly promising, MemAgent, like any technical solution, comes with certain tradeoffs and limitations:

  1. Fixed Memory Length (1024 tokens): The most notable limitation is the fixed memory size of 1024 tokens for the accumulated memory. While experiments showed this was sufficient for many QA and summarization tasks, the speaker acknowledged that "it will not be always available for ultra-long context if we have just only 1024 tokens." For highly specialized tasks that demand retaining an extremely high density of minute details from very long documents (e.g., reading a very long financial document where every number and clause might be critical), a 1024-token summary might lead to information loss. The speaker conceded, "there will be some case that you have to use a very very more information," and that "there is a space to improve" in this regard. This suggests a potential future direction for dynamically adjusting memory size or adopting a hierarchical memory structure.
  1. Reliance on Reinforcement Learning Training: The success of MemAgent is critically dependent on effective RL training. Implementing and fine-tuning RL algorithms can be complex, requiring careful data curation (like the Ruler dataset) and significant computational resources for training. Organizations without strong RL expertise might face a steeper learning curve to fully leverage MemAgent's potential.
  1. Potential for Information Compression Artifacts: The process of summarizing chunks into a fixed-length memory inherently involves information compression. While the RL training teaches the model to retain critical information, there could still be subtle nuances or less explicit connections that are lost in the summarization process, potentially impacting performance on tasks requiring very fine-grained understanding or highly abstract reasoning across vast distances.

Despite these limitations, MemAgent represents a significant step forward in making ultra-long context processing practical and accessible, offering a robust, RL-driven solution that effectively balances performance with architectural simplicity.

Key Takeaways

  • Ultra-Long Context Achieved Without Architectural Changes: MemAgent enables LLMs to process inputs up to 35 million tokens by employing a novel, text-level, token-to-token context management approach, avoiding modifications to the core model architecture or inference engine.
  • Reinforcement Learning is Critical for Memory Capability: The success of MemAgent hinges on a multi-conversation DPO (GRPO-like RL algorithm), which teaches the LLM how to intelligently summarize, filter, and retain critical information, achieving "near lossless extrapolation" where simple summarization fails.
  • Fixed-Length Memory for Efficiency: The framework compresses vast contexts into a fixed-length memory (max 1024 tokens total accumulated memory), demonstrating that intelligent information curation is more vital than raw memory capacity for many QA and summarization tasks.
  • Robustness to Information Loss: Through proper RL training with diverse context distribution patterns, MemAgent effectively mitigates common issues like "information overwritten" and "lost in the middle" problems, making it reliable for complex, long-document understanding.
  • Versatile Across Tasks: The learned memory capability generalizes well, proving effective in both complex multi-hop Question Answering (QA) and summarization tasks, evaluated on datasets like Ruler, Qianwen L1 (DocQA RL), Needle In A Haystack, and LongBench.
  • Practical & Accessible Solution: MemAgent offers a practical pathway for deploying ultra-long context LLMs, simplifying infrastructure requirements and enhancing real-world agent capabilities without the need for costly architectural re-engineering or model re-training.

About the Speaker(s)

The primary presenter for this work was Hongli Yu. He is currently a first-year PhD student and simultaneously serves as an intern at ByteDance Seed. Prior to his doctoral studies, Hongli Yu earned his bachelor's degree from the Harbin Institute of Technology.

In his spare time, Hongli Yu enjoys a diverse range of hobbies, including anime, J-pop idol culture, and playing the piano. His research interests are deeply rooted in the future of AI, specifically focusing on memory systems. He expressed a strong belief that agentic systems will represent the "next technical singularity," which drives his focus on memory capabilities for processing ultra-long contexts, identifying it as a "very very critical point for our coding agent and just all of them." His work on MemAgent directly reflects this visionary outlook on the future of AI.

Reviews

→ Top-rated talks at International Conference on Learning Representations 2026

All talks from International Conference on Learning Representations 2026