Manuscript Offprint

arXiv:2611.26427

MemFolder: Structure-Guided Memory Folding for Efficient Agent Memory Management

Xuyang Liu, Chenwen Lu, Junxi Wang, Siyu Ren, Xinying Lin, Siteng Huang, Hongli Sun, Linfeng Zhang, Honggang Chen

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Long-term agents accumulate large external memory stores as interactions unfold, increasing the costs of storage, retrieval, and response generation. Efficiency is constrained by two coupled factors: a growing record count increases retrieval overhead, while longer retrieved contexts increase prefill computation and decoding-time attention costs. Existing methods prune or consolidate records, but pruning can discard useful evidence, whereas consolidation may produce fewer yet longer retrieval units. We introduce MemFolder, a structure-guided memory folding framework that sequentially reduces record count and context length. The framework comprises two core components that share memory groups, using cross-record structure to guide both evidence consolidation and compact representation. RecordFolder grounds entity mentions, progressively selects representative yet complementary anchors, and combines semantic and entity affinity with temporal chaining to consolidate compatible records into fewer retrieval units. ContextFolder encodes the original records within these groups into compact text and uses verification feedback to revise encodings when key facts cannot be recovered. Experiments on the three text-based memory benchmarks LoCoMo, PersonaMem, and LongMemEval and the two multimodal benchmarks M3-Bench-web and M3-Bench-robot demonstrate the strong performance of our methods. Notably, on Mem0, RecordFolder retains 99.0% of the original average performance across the three text-based benchmarks with 50% fewer records, exceeding the strongest baseline by 1.9 percentage points in performance retention. Combined with ContextFolder, existing record compression methods further shorten their output records while retaining most of their performance.

1 Introduction

Advances in reasoning and tool use enable large language models (DeepSeek-AI et al., 2026; Kimi Team et al., 2026a; Kimi Team et al., 2026b) to support long-term agents operating across multiple sessions (Wu et al., 2025; He et al., 2026). These agents draw on earlier conversations, observations, and task states to inform later decisions. External memory systems (Chhikara et al., 2025; Xu et al., 2025; Liu et al., 2026a) index this growing history as natural-language records for retrieval. Our uncompressed stores contain 6,817 records totaling 61,273 tokens across all ten LoCoMo samples (Maharana et al., 2024), and 310,120 records totaling 3.7M tokens across LongMemEval (Wu et al., 2025).

This growth creates two coupled efficiency bottlenecks, as shown in Figure 1(1). A larger record count requires more storage, increases the size of the index, and expands the retrieval search space. Once the records have been retrieved, their combined context length determines how much memory text the agent processes per query. Even individually short records can form a long context when retrieved together, increasing both prefilling and decoding costs (Liu et al., 2025b).

Figure

Figure 1: MemFolder for efficient agent memory management. (1) More records increase retrieval costs, while longer contexts increase prefill and token overhead. (2) Existing methods target one axis, while MemFolder combines RecordFolder and ContextFolder to reduce both. (3) MemFolder preserves accuracy while accelerating retrieval and reducing context length.

Figure 1(2) plots record count NN on the horizontal axis and tokens per unit ℓ\ell on the vertical axis. Prompt compressors such as LLMLingua (Jiang et al., 2023; Pan et al., 2024) and BabelTele (Zhu et al., 2026) shorten the input to each call while leaving NN unchanged. StreamMeCo (Wang et al., 2026a) and MemForest (Wang et al., 2026b) reduce NN by pruning or consolidating records. Pruning can discard useful evidence. Consolidation preserves related content but can produce fewer, longer units, shifting the store toward the upper left in the figure. On LoCoMo (Maharana et al., 2024), when 50% of records are retained, units produced by MemForest and ToMe (Bolya et al., 2023) average 2.12×2.12\times and 2.48×2.48\times the original record length, respectively. At 30% retention, the ratios rise to 3.01×3.01\times and 3.87×3.87\times. Even concatenation without merging yields units 2.10×2.10\times the original length at 50% retention. With a fixed top-kk retrieval budget, fewer units can still yield a longer context. We aim to reduce both costs while retaining evidence an agent may need in later sessions.

This observation motivates two distinct compression decisions. At the record level, we determine which records can share a retrieval unit while preserving complementary facts and state changes. At the context level, we determine how to encode each group compactly, expressing shared content once while retaining dates and other record-specific details. Group assignments connect these decisions while allowing record count and context length to be optimized separately.

We address these two efficiency bottlenecks with MemFolder, a structure-guided memory folding framework with two complementary folding components. As shown in Figure 1(3), RecordFolder grounds entity mentions, progressively selects representative yet complementary anchors, and combines semantic and entity affinity with temporal chaining to consolidate NN records into KK retrieval units. Given these groups and their source records, ContextFolder generates compact encodings guided by a target token ratio while keeping one output unit per group. Verification feedback guides revisions when key facts are not recoverable. Given that it is independent of the grouping algorithm, ContextFolder can also shorten the contexts from record compression methods.

Experiments cover three text benchmarks and two multimodal settings. With 50% fewer records, RecordFolder retains 99.0% of average Mem0 performance across the three text benchmarks, compared with 97.1% for MemForest. Combined with RecordFolder, ContextFolder further cuts tokens per record by 40%, 38%, and 31% on LoCoMo, LongMemEval, and M3-Bench-robot, respectively, with limited accuracy loss. As a plug-and-play component, ContextFolder also shortens outputs from other record-compression methods, yielding more favorable accuracy–efficiency trade-offs than BabelTele and LLMLingua-2. Our work makes the following contributions:

  1. We introduce MemFolder, a structure-guided memory folding framework that jointly reduces the number of retrieval units and their context length for long-term agents.
  2. We develop RecordFolder to consolidate records through progressive anchor selection and entity-aware temporal chaining. ContextFolder then compacts each group’s content through budgeted encoding and factual recovery checks that guide revisions to the encoding.
  3. Experiments on three text benchmarks and two multimodal settings demonstrate strong performance under record compression, while context compression analyses show further reductions in retrieval unit length across multiple existing memory consolidation methods.

References (33)