Manuscript Offprint
arXiv:2610.25561Let Them Sleep: Recursive Self-Pruning Memory for Long-Horizon LLM Agents
Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.
Abstract
Agents that run for a long time have a memory problem, and it is not the one most systems optimize for. Storing every trace and retrieving the nearest neighbors works early and quietly stops working later: the store fills up with failures the agent then repeats, and with facts that were true fifty turns ago. RSPM (Recursive Self-Pruning Memory) borrows the fix biology already found. At intervals the agent sleeps. It clusters its recent failures, distills each cluster into a short rule, and deletes the raw episodes it just learned from. Rules decay unless something reinforces them, and rules that recur across many contexts get promoted into general ones. We tested this on three settings with little in common: 19,008 SWE-bench issues, temporal consistency across 12 conversational benchmarks, and long-horizon QA on LoCoMo. Performance rose by 7.6 to 11.9 points in each. More interestingly, three separately tuned experiments landed on nearly the same equilibrium, roughly 93% fewer retry loops and roughly 30% less stored memory, which suggests that knowing what to forget is a general property of agent memory rather than a benchmark-specific trick.
1 Memory debt
Long-running agents are now common. One works through GitHub issues at SWE-bench scale [Jimenez et al., 2024], another holds a conversation across thirty sessions, another answers questions pointing back to an arbitrary turn in dialogues of several hundred turns [Maharana et al., 2024]. The usual design assumption is that memory should only grow: keep every trace, retrieve the closest matches [Lewis et al., 2020]. Closest cousins either page memory across tiers [Packer et al., 2023], decay unused traces [Zhong et al., 2024], or store lessons alongside experience rather than in place of it [Shinn et al., 2023, Wang et al., 2024]—none consolidate then delete. In our experiments, the grow-only assumption broke down the same way in every domain.
The store bloats first, since entries accumulate linearly while the useful capacity of top-k retrieval does not, so a naive conversational baseline ends up holding 675 entries and surfacing five. Then the agent starts repeating itself: a failed approach is stored verbatim, looks relevant later, and gets tried again. We measure these retry loops at 5.9% to 6.7% of all attempts, in software engineering and in QA alike. Finally, the store goes stale. A note about a deprecated API, or a preference the user changed forty turns ago, still carries full weight, and baseline accuracy slides from about 70% to about 58% as a conversation runs past 100 turns. Biology settled this long ago: during slow-wave sleep the hippocampus replays recent episodes while the neocortex extracts the pattern, so the episode goes and the lesson stays [Stickgold, 2005, McClelland et al., 1995], and whatever is not consolidated decays on the Ebbinghaus curve [Ebbinghaus, 1885]. RSPM writes those two observations down as an algorithm.
37th Conference on Neural Information Processing Systems (NeurIPS 2023).
retrieval reweighted by surviving rules

Figure 1: One sleep cycle. Raw episodes are clustered, compressed into a single rule, and then deleted (dashed arrow back to the store). Surviving rules are promoted upward when they generalize and decay away when nothing reinforces them.
3 What happened in three domains
We instantiated RSPM three times, each with its own notion of what makes an entry prunable: failure clustering, temporal supersession, and failure association.
Software engineering. On a difficulty-calibrated simulation over the SWE-bench splits [Jimenez et al., 2024], the solve rate on Full moves from 40.0% to 49.1%, a gain of 9.1 points (p=0.0003 over 10 seeds). The gain is not uniform. It grows with difficulty, from 5.4 points on issues rated under 15 minutes to 13.2 on issues rated over four hours, which is what we would expect if consolidation matters most under pressure. At 19,008 issues the hierarchy yields 3,438 repo-specific constraints, 24 error-class rules and 18 universal ones, on 30.6% fewer stored entries than the baseline.
Temporal consistency. Across 12 benchmarks and 1,363 items, RSPM with an LLM conflict detector reaches 92.5% temporal consistency. It beats naive RAG at 80.6%, which we expected, and it also beats an oracle given ground-truth conflict labels at 88.4%, which we did not. The oracle throws out any document containing a superseded value, including the one announcing the update, while the LLM detector reads the query first. The other surprise is negative: keyword detection scores 79.5%, slightly worse than doing nothing.
Long-horizon QA. On LoCoMo-10 [Maharana et al., 2024] (154 QA pairs per conversation, 3,850 evaluations) RSPM reaches 72.8% accuracy, 7.6 points over baseline RAG (p=0.0042). The aggregate understates it: every baseline decays as the conversation lengthens while RSPM does not, and its memory curve flattens near 472 entries against 675. Ablating the sleep cycle costs more than ablating anything else.
4 What we take from this
Pruning turned out to matter as much as retrieval. In all three settings, a smaller curated memory beat a larger uncurated one, and the sleep cycle was the mechanism we could least afford to lose. The convergence in the results is the part we find hardest to explain away: the three studies were built at different times, on different data, with separately tuned hyperparameters, none aimed at matching the others, yet they land on the same two numbers. We read that as an equilibrium of the mechanism rather than an artifact of tuning, and would like to be argued with on the point.
Forgetting also has a failure mode, and it is instructive. On one LoCoMo conversation with a 35% natural error rate, RSPM triggered 21 sleep cycles, pruned 43% of the store, and finished 19.5 points below baseline. Study 2 shows the same shape, with proactive archival hurting on datasets whose questions ask about historical states. Both share an assumption we made too casually, that a memory involved in a failure caused it. That holds when the memory is stale and breaks when the task is simply hard.
References
Hermann Ebbinghaus. Über das Gedächtnis: Untersuchungen zur experimentellen Psychologie. Duncker & Humblot, Leipzig, 1885.
Carlos E. Jimenez, John Yang, Alexander Wettig, Shunyu Yao, Kexin Pei, Ofir Press, and Karthik Narasimhan. SWE-bench: Can language models resolve real-world GitHub issues? In International Conference on Learning Representations (ICLR), 2024.
Patrick Lewis, Ethan Perez, Aleksandra Piktus, Fabio Petroni, Vladimir Karpukhin, Naman Goyal, Heinrich Küttler, Mike Lewis, Wen-tau Yih, Tim Rocktäschel, Sebastian Riedel, and Douwe Kiela. Retrieval-augmented generation for knowledge-intensive NLP tasks. In Advances in Neural Information Processing Systems (NeurIPS), 2020.
Adyasha Maharana, Dong-Ho Lee, Sergey Tulyakov, Mohit Bansal, Francesco Barbieri, and Yuwei Fang. Evaluating very long-term conversational memory of LLM agents. In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pages 13851–13870, 2024. doi: 10.18653/v1/2024.acl-long.747.
James L. McClelland, Bruce L. McNaughton, and Randall C. O'Reilly. Why there are complementary learning systems in the hippocampus and neocortex: Insights from the successes and failures of connectionist models of learning and memory. Psychological Review, 102(3):419–457, 1995. doi: 10.1037/0033-295X.102.3.419.
Charles Packer, Sarah Wooders, Kevin Lin, Vivian Fang, Shishir G. Patil, Ion Stoica, and Joseph E. Gonzalez. MemGPT: Towards LLMs as operating systems. arXiv preprint arXiv:2310.08560, 2023.
Noah Shinn, Federico Cassano, Edward Berman, Ashwin Gopinath, Karthik Narasimhan, and Shunyu Yao. Reflexion: Language agents with verbal reinforcement learning. In Advances in Neural Information Processing Systems (NeurIPS), 2023.
Robert Stickgold. Sleep-dependent memory consolidation. Nature, 437(7063):1272–1278, 2005. doi: 10.1038/nature04286.
Guanzhi Wang, Yuqi Xie, Yunfan Jiang, Ajay Mandlekar, Chaowei Xiao, Yuke Zhu, Linxi Fan, and Anima Anandkumar. Voyager: An open-ended embodied agent with large language models. Transactions on Machine Learning Research (TMLR), 2024.
Wanjun Zhong, Lianghong Guo, Qiqi Gao, He Ye, and Yanlin Wang. MemoryBank: Enhancing large language models with long-term memory. In Proceedings of the AAAI Conference on Artificial Intelligence (AAAI), pages 19724–19731, 2024.