MemFolder: Structure-Guided Memory Folding for More Efficient Agent Long-Term Memory

MemFolder uses structure-guided memory folding to compress both record count and context length.
The paper "MemFolder: Structure-Guided Memory Folding for Efficient Agent Memory Management" addresses the external memory cost of long-running AI agents by proposing a structure-guided memory folding framework. Existing pruning may discard useful evidence, and merging may produce fewer but longer retrieval units, making it hard to reduce both record count and context length. MemFolder lets RecordFolder and ContextFolder share the same memory groupings: the former uses entity grounding and anchor selection with semantic affinity, entity affinity, and temporal chains to merge compatible records into fewer retrieval units; the latter performs compact text encoding within groups and uses verification feedback to correct encodings that fail to recover key facts. On three text and two multimodal benchmarks, reducing records by 50% on Mem0 still retains 99.0% average performance, 1.9 percentage points above the strongest baseline.
Long-running AI agents continuously accumulate external memory through interaction, and the costs of storage, retrieval, and response generation rise accordingly. Efficiency is constrained by two coupled factors: a growing number of records drives up retrieval overhead, while longer retrieval contexts increase prefill computation and attention costs during decoding. Existing methods either prune or merge, but pruning may discard useful evidence, and merging may produce fewer yet longer retrieval units. The paper "MemFolder: Structure-Guided Memory Folding for Efficient Agent Memory Management" proposes a structure-guided memory folding framework that attempts to reduce both the number of records and the context length at the same time.

Two-Component Design: One Memory Grouping, Two Compression Paths
The core idea of MemFolder is to let two components share memory groupings, using cross-record structure to guide both evidence merging and compact representation. RecordFolder grounds entity mentions, progressively selects representative and complementary anchors, and combines semantic affinity, entity affinity, and temporal chains to merge compatible records into fewer retrieval units. ContextFolder encodes the raw records within these groups into compact text, and uses verification feedback to correct the encoding when key facts cannot be recovered.
The cleverness of this design lies in "folding" rather than "deleting": records are not discarded but organized into units with tighter structure and higher information density. Sharing groupings across the two components means structural information is computed only once yet serves both record-level and context-level compression.
RecordFolder: Selecting Anchors by Structure, Not Random Pruning
The key to RecordFolder is anchor selection. It first grounds entity mentions, then progressively picks anchors that are both representative and complementary. Semantic affinity judges content similarity, entity affinity captures shared entity relationships, and temporal chains ensure chronological coherence. Combined, compatible records are merged into fewer retrieval units rather than simply deleted. This explains why the performance retention rate remains high even when the number of records is halved—merged records still remain in the memory store in another form.
Entity Grounding: This refers to linking entity mentions appearing in text to definite entity identifiers in a knowledge base or memory store, thereby recognizing that different expressions point to the same object (e.g., "苹果公司", "Apple Inc.", and "AAPL"). After grounding, explicit entity associations can be established between records, forming a cross-record structural graph. MemFolder's RecordFolder first performs entity grounding, then computes entity affinity based on shared entity relationships and organizes records along temporal chains. Without grounding, entity affinity could only remain at the level of literal matching and could not reliably determine whether two records are talking about the same object, and anchor selection and record merging would lose their structural basis.
ContextFolder: Compact Encoding Plus Verification Feedback
ContextFolder performs compact text encoding of the raw records within each group, compressing the "expression length of retrieval units." More importantly, there is a verification feedback mechanism: when the encoded text cannot recover key facts, the system revises the encoding. This is effectively a fidelity check on the compression process, preventing irreversible information loss caused by over-compression.
Attention Costs in Prefill and Decode Stages: In Transformer-based generative models, inference is divided into two stages. The prefill stage processes the entire input context in parallel, with computation growing quadratically with context length; the decode stage generates output token by token, performing attention over the cached key-values (KV Cache) at each step, with cost growing linearly with context length. Therefore, the longer the retrieval context, the more significantly the computational overhead of prefill and the attention overhead of each decoding step increase. This is precisely the meaning of "longer retrieval contexts increase prefill computation and attention costs during decoding" in the text—even if the number of records stays the same, merely merging into longer retrieval units may incur higher costs on the inference side.
Recoverability of Key Facts: The lossy nature of memory compression is reflected in whether the compressed text still enables downstream models to answer questions supported by the original records. A common approach to recoverability checking is to extract or question key facts from the compressed text and compare them with the original records; if a key fact cannot be recovered after compression, the encoding is judged to be over-compressed and a revision is triggered. ContextFolder's verification feedback builds a closed loop around this metric—it does not pursue the shortest encoding but makes a dynamic trade-off between "length" and "fact recoverability." This principle also explains why performance is maintained after halving the records: compression is constrained by not losing key facts, rather than by minimizing character count.
Experimental Performance: Records Halved, Performance Barely Drops
The paper validates on three text memory benchmarks—LoCoMo, PersonaMem, and LongMemEval—as well as two multimodal benchmarks, M3-Bench-web and M3-Bench-robot. On Mem0, RecordFolder retains 99.0% of the original average performance across the three text benchmarks while reducing the number of records by 50%, with a performance retention rate 1.9 percentage points above the strongest baseline. When combined with ContextFolder, existing record compression methods can further shorten output records while retaining most of the performance.
These results demonstrate two things: structure-guided merging can substantially reduce the number of records while maintaining evidence integrity; and context-level compression can be layered on top of record-level compression to produce two levels of efficiency gains.
Implications for Agent Memory Management
The efficiency problem of agent long-term memory is rarely single-dimensional. The number of records and the context length are intertwined, and optimizing one alone often shifts the cost to the other side. The value of MemFolder lies in handling both under the same structural framework, using cross-record relationships to guide both "which records to merge" and "how to express them compactly."
From an engineering perspective, this shared-grouping approach also means that extra structural computation is needed only once, yet benefits are obtained at both the level of retrieval unit count and unit length. For long-running conversational assistants, personalized agents, or multimodal robot memory systems, this kind of structure-guided folding approach offers a direction that balances efficiency and fidelity.
The paper also highlights an easily overlooked point: compression requires a verification loop. ContextFolder's verification feedback shows that compact encoding is not a one-time deal but involves dynamic correction on key fact recoverability. This is a design principle worth borrowing for any system that performs memory compression.
One-line Summary
MemFolder uses structure-guided memory folding to compress both the number of records and the context length.
Paragraph Summary
The paper "MemFolder: Structure-Guided Memory Folding for Efficient Agent Memory Management" addresses the external memory cost problem of long-running AI agents and proposes a structure-guided memory folding framework. Existing pruning may discard useful evidence, and merging may produce fewer but longer retrieval units, making it difficult to reduce both the number of records and the context length simultaneously. MemFolder lets RecordFolder and ContextFolder share the same memory groupings: the former uses entity grounding and anchor selection, combined with semantic affinity, entity affinity, and temporal chains, to merge compatible records into fewer retrieval units; the latter performs compact text encoding within groups and uses verification feedback to correct encodings that cannot recover key facts. On three text and two multimodal benchmarks, reducing records by 50% on Mem0 still retains 99.0% average performance, with a performance retention rate 1.9 percentage points above the strongest baseline.
Related articles

ChatGPT Plus Subscription Pitfall Guide: Go/Plus/Pro Tier Comparison and Quick Activation
A complete ChatGPT Plus subscription guide based on a Bilibili tutorial: from registering an account, comparing Go/Plus/Pro tiers, to the practical steps for quickly completing your subscription.

GPT-6.2 Sol/Astra Released! A Step-by-Step ChatGPT Plus Subscription Guide and Tier Comparison
GPT-6.2 Sol/Astra is out—here's a ChatGPT Plus subscription guide: register an account, compare Go/Plus/Pro tiers, and subscribe in a minute.

Comparing Three Channels for Subscribing to GPT Plus in China: Is Website Top-Up the Easiest?
How to subscribe to GPT Plus in China? This article compares website top-up, credit card, and mobile top-up channels—process, cost, and risk—with steps and tips to help you choose wisely.