TL;DR
Long-horizon LLM agents rely on external memory to remember past interactions, but existing systems slice conversations into arbitrary, fixed-length chunks or single turns—like tearing pages out of a book mid-sentence. E2Mem fixes this by grouping dialogue into natural, semantically coherent episodes, letting the agent "think-then-memorize" without rigid templates, and training it end-to-end with reinforcement learning (RL). On the LongMemEval benchmark, E2Mem compresses context by 2.7× while outperforming strong baselines by 4.1% to 47.0% in accuracy.
What Problem Does This Paper Address?
Large Language Models (LLMs) struggle in long conversations: they hit fixed context window limits and suffer from the "lost-in-the-middle" problem, where information buried in the middle of a long prompt gets ignored. To cope, agents use external memory modules to store and retrieve past experiences.
However, current memory systems—even recent RL-based ones—have two fundamental flaws:
- Rigid, unnatural boundaries: They slice dialogue by single turns or fixed token lengths. This ignores natural topic shifts, leading to redundancy (generating overlapping memories for the same ongoing topic) and logical disconnection (breaking causal links across turns).
- Rigid schemas: Many systems force agents into pre-defined templates (e.g., Profile, Facts, Episode), limiting how the agent can organize information for different situations.
Methods
E2Mem replaces rigid chunking and templates with a three-phase pipeline, trained end-to-end with multi-turn RL:
- Semantic Boundary-aware Segmentation (Phase 1): Instead of using expensive LLM calls to detect topic shifts, E2Mem computes a lightweight cosine similarity between consecutive dialogue turn embeddings. When similarity drops below an automatically tuned per-dialogue threshold, it marks a boundary. The resulting segments are roughly coherent episodes, and any minor boundary noise is handled downstream by the RL agent.
- Reasoning-driven Memory Generation (Phase 2): For each segment, the agent follows a "think-then-memorize" process. First, it generates a reasoning trajectory to plan what to keep and how to structure it. Then, it outputs a flexible triplet:
<Semantic Summary, Tag List, Memory Content>, where the content is an adaptively sized list of items rather than a fixed schema. - Topic-triggered Memory Updating (Phase 3): New memories aren't blindly appended. E2Mem compares their summaries and tags against existing memories; if the similarity exceeds a merge threshold, the agent synthesizes and re-summarizes them into an updated entry. Otherwise, it appends the memory as a new item.
End-to-End RL Optimization: The agent is trained using multi-turn Group Relative Policy Optimization (GRPO) with a bi-level reward:
- Sample-level Outcome Reward: Exact Match (EM) on the final question-answering task (stricter than LLM-as-a-judge to prevent reward hacking).
- Turn-level Process Reward: Immediate dense feedback combining Memory Quality (scored by an external LLM for completeness, consistency, and conciseness) and Token Efficiency (rewarding high compression ratios).
Datasets
- LongMemEval: The primary benchmark used to evaluate long-horizon conversational memory.
- LongMemEval-Oracle: Used as the training set for RL. Notably, its average context length is only 1/25th of the full evaluation set, meaning the agent trains on short rollouts and must generalize to 30–50 turn episodes at test time.
Key Insights and Ideas
- Rough semantic boundaries are good enough: You don't need an expensive LLM to parse topic boundaries. Lightweight cosine similarity achieves nearly identical accuracy to LLM-parsed segmentation (78.2% vs. 78.6%) without the massive computational overhead.
- Rigid schemas bottleneck RL: Removing pre-defined memory formats and letting the agent reason freely ("think-then-memorize") boosts accuracy from 72.8% to 78.2% while also improving compression.
- Dense rewards prevent sparse-reward failure: Training with only the final QA exact-match reward yields 72.6% accuracy. Adding turn-level quality and efficiency rewards gives the agent immediate guidance, balancing information retention with compact storage.
- Strong length generalization: Despite training on contexts 25× shorter than the test set, the RL policy scales smoothly to long-horizon evaluation.
Key Results
Evaluated on LongMemEval using Qwen3-4B:
- Accuracy & Compression: E2Mem-4B w/ RL achieves 78.2% accuracy while reducing memory tokens by 63.9% (42.1k tokens/sample, a 2.7× compression).
- Efficiency vs. Baselines: It outperforms FullText (60.6%), Naive RAG (60.4%), LightMem (71.6%), A-Mem (74.1%), MemAgent-7B (31.2%), and Mem-α-4B (41.2%). Compared to A-Mem, E2Mem cuts total I/O tokens and agent calls by 10× to 20× (54.7 vs. 989.3 calls/sample) and halves stored memory tokens.
Limitations and Future Work
- Coarse segmentation: Cosine similarity can miss subtle topic shifts in highly interleaved or implicit conversations. Future work could explore lightweight trained boundary encoders or adaptive thresholding.
- Dialogue-only evaluation: E2Mem was only tested on multi-turn chat (LongMemEval). Extending it to non-dialogue agentic tasks—like web browsing, coding, or embodied control—remains open.
- Model scale: Due to compute limits, RL training was only run on 4B-scale models (Qwen3-4B). Scaling end-to-end multi-turn GRPO to larger models (e.g., 32B or 72B) is left for future work.
Summary updated