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.
Figures & tables
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 2: Overview of MemFolder. (a) RecordFolder maps N records to K retrieval units through entity grounding, complementary anchor selection, entity-aware affinity, and Hungarian matching of temporal links. (b) ContextFolder compresses each group’s source records to a target token-retention ratio using a planner that prioritizes facts and prepares checks, a compressor that generates grammar-based candidates, and a blind verifier that tests recovery over up to three rounds. ContextFolder keeps the shortest candidate passing required checks; otherwise, weighted recovery guides selection, with a shorter candidate or source texts used when compression would expand the memory.
Method
LoCoMo
LongMemEval
Persona -Mem
Avg.
%
SH
MH
TR
OD
All
SU
SA
SP
MS
KU
TR
All
Mem0
66.0
56.0
53.9
42.7
60.2
90.0
21.4
23.3
54.9
79.5
44.4
55.2
67.9
61.1
100.0
Record-count reduction: 30%
+ Random Pruning
55.3
49.7
43.3
39.6
50.8
82.9
17.9
26.7
51.9
73.1
39.1
50.8
64.5
55.4
90.7
+ KMeans
61.1
54.3
52.7
40.6
56.8
84.3
17.9
20.0
51.9
75.6
41.4
52.0
65.7
58.2
95.3
+ DART
64.1
53.9
48.0
40.6
57.4
82.9
19.0
20.0
48.9
74.4
34.6
48.8
66.6
57.6
94.3
Table 1: Record compression on Mem0 cross compression ratios. All : overall accuracy; Avg. : mean accuracy across three benchmarks; % : Avg. retained relative to uncompressed Mem0. Best and second-best compressed results per column and ratio are bold and underlined , respectively.
Figure 3: Context compression results. Accuracy–tokens trade-offs at 50% record-count reduction. Colors and markers denote record and context compression methods. Upper left is better.
Method
LoCoMo
LongMemEval
Persona -Mem
Avg.
%
SH
MH
TR
OD
All
SU
SA
SP
MS
KU
TR
All
MemOS
84.5
70.2
78.8
56.2
79.0
91.4
100.0
66.7
55.6
78.2
71.4
74.0
60.3
71.1
100.0
Record compression ratio ↓50%
+ Random Pruning
70.5
65.2
57.3
46.9
65.3
67.1
64.3
63.3
28.6
52.6
43.6
47.8
55.9
56.3
79.2
+ KMeans
75.7
59.2
57.6
57.3
67.8
72.9
69.6
66.7
20.3
51.3
45.9
47.6
54.7
56.7
79.7
+ DART
76.5
68.1
58.9
58.3
70.1
62.9
82.1
50.0
20.3
35.9
33.1
40.8
53.7
54.9
77.2
Table 2: Record compression on MemOS across compression ratios.
Method
M3-Bench-robot
M3-Bench-web
Avg.
%
ME
MH
CM
PU
GK
All
ME
MH
CM
PU
GK
All
M3-Agent
30.9
29.4
29.6
41.1
22.6
30.3
44.9
25.6
44.8
58.6
53.7
47.9
39.1
100.0
Record compression ratio ↓50%
+ Random Pruning
28.4
25.9
27.3
38.7
19.6
28.1
35.6
23.0
34.9
52.3
44.2
41.2
34.7
88.7
+ KMeans
29.1
30.6
28.4
41.4
20.8
29.2
41.1
21.7
42.5
55.0
47.4
43.9
36.6
93.6
+ DART
28.9
25.9
29.4
39.1
22.0
29.1
39.9
23.6
39.4
52.9
47.2
43.1
36.1
92.3
Table 3: Record compression on M3-Bench across compression ratios.
Table 7
Figure 4: Retrieval efficiency under record compression. Mean and 95th-percentile latency with 100%, 50%, and 30% of records retained. Dotted lines indicate uncompressed mean latency. Keeping 30% yields 1.88–5.34 × mean speedups across five settings.
Appendix figures & tables5 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 5: Hyperparameter analysis on LoCoMo and LongMemEval. (A) Affinity-weight analysis (panels 1–2); (B) ContextFolder iteration analysis (panels 3–4), each ordered by LoCoMo then LongMemEval. Blue and green denote the benchmarks; solid circles show accuracy and dashed crosses show tokens per record. Higher accuracy and lower token usage are preferred.
#
Record
Tokens
1
User appreciates having people around who accept and support them
11
2
User appreciates their support network for love, guidance, and acceptance
13
3
User appreciates support and is grateful for sharing their journey and helping others
14
4
User appreciates the support of those close to them
10
Appendix
Table 10
#
Record
1
Volunteering is an important part of Caroline’s life
2
Caroline is carrying on volunteering at the youth center
3
Volunteering at the youth center is an important part of Caroline’s life
4
Caroline wants to keep making a difference
5
Caroline is carrying on volunteering at the youth center
6
Caroline wants to keep making a difference
Appendix
Table 11
#
Record
Date
1
Cares about mental health
27 Jun 2023
2
User is keen on counseling or working in mental health
27 Jun 2023
3
Values counseling and support groups
27 Jun 2023
4
Thinking about taking care of mental health
25 May 2023
5
Values taking care of mental health
25 May 2023
6
Interested in counseling and mental health
3 Jul 2023
Appendix
Table 12
#
Fact (level)
Question → expected answer
1
Cares about mental health (high)
What does the user care about? → Mental health
2
Keen on counseling or working in mental health (high)
Interest regarding career? → Counseling or mental health work
3
Values counseling and support groups (med)
What does the user value? → Counseling and support groups
4
Looking into counseling and mental health jobs (high)
Currently exploring? → Counseling and mental health jobs
5
Started looking into these options to help others (med)
Why? → To help others
6
Values sharing stories and giving others hope (med)
Agent memory systems have demonstrated significant potential in long-term dialogue, personalized assistants, and video understanding. However, continuously accumulated memory introduces substantial storage and retrieval costs during inference. To address this issue, we propose MemForest, a general memory compression framework adaptable to various agent memory systems. Specifically, MemForest partitions historical memory into event-centric units by leveraging global semantic similarity and local temporal continuity. For each unit, it constructs a maximum spanning tree, termed an EventTree, and progressively merges redundant memory nodes by selecting high-weight edges, reducing storage overhead. Furthermore, we introduce an anchor-guided propagation retrieval mechanism that retrieves relevant memory nodes from the temporal neighborhoods of key nodes, improving retrieval accuracy. Extensive experiments demonstrate the effectiveness of MemForest. Under the unimodal Mem0 framework, MemForest retains 97.1% of the original performance while compressing 50% of historical memory across three benchmarks (LoCoMo, LongMemEval, and PersonaMem), achieving a 1.89x retrieval speedup. Under the multimodal M3-Agent framework, it preserves 99.7% of the original performance with a 50% compression ratio across two benchmarks (M3-Bench-robot and M3-Bench-web), achieving a 2.24x retrieval speedup. \textcolor{RoyalBlue}{*Our code is available at https://github.com/Celina-love-sweet/MemForest.*}
Junxi Wang, Te Sun, Jiayi Zhu +9
Shanghai Jiao Tong University · Fudan University · Nanjing University +5
Long-horizon LLM agents must preserve information from past interactions to support future tasks. Existing memory systems typically rely on eager consolidation, invoking LLMs after each interaction to extract, summarize, or update memories. This design makes memory construction increasingly costly as conversations grow. Coarse summarization can reduce construction cost but risks discarding fine-grained contextual evidence, whereas larger retrieval contexts or multi-hop LLM reasoning shift the overhead to query time. We present LycheeMemory V2, an efficient long-term memory framework that replaces turn-level consolidation with semantic segment-level consolidation. Instead of consolidating every interaction, LycheeMemory batches multiple exchanges into segments and encodes each finalized segment into context-independent typed memory records. Segment-level batching lowers LLM encoding frequency, while semantic boundary detection helps preserve coherent event-level and temporal evidence compared with fixed-window batching. The resulting records are organized with lightweight structured indexes for query-planned evidence retrieval. Experiments using GPT-4.1-Mini show that LycheeMemory achieves state-of-the-art performance, reaching 89.22% on LoCoMo and 92.20% on LongMemEval-S. Compared with A-Mem, it reduces construction tokens by 86.0% on LoCoMo and 75.9% on LongMemEval-S without increasing query-time token usage. More broadly, our results suggest that the accuracy--cost trade-off of long-term agent memory depends not only on what information is retained, but also on the granularity at which it is consolidated.
Long-term memory enables LLM agents to leverage past interactions, but dialogue histories quickly exceed the context window, forcing agents to retrieve relevant subsets at query time. Because useful evidence is sparse and scattered across verbose conversations, retrieval faces a fundamental tension: broadening recall improves coverage but floods downstream reasoning with noise, while compressing memories at write time eases retrieval but irreversibly discards details that future queries may need. We introduce LazyMem, which resolves this tension by deferring all memory construction to query time. Given a retrieved candidate pool, a lightweight model processes it in overlapping parallel windows, selectively retaining and compressing only query-relevant content. The model is trained with supervised fine-tuning followed by reinforcement learning, using a reward that jointly encourages the identification of relevant messages and the generation of compressions that are faithful to the source and useful for answering the query. On LongMemEval, LazyMem-4B achieves an LLM-judge accuracy of 0.85, outperforming the strongest non-oracle baseline while using only 213 answer-context memory tokens, 21.0 times fewer than the baseline. It further generalizes to LoCoMo without target-domain training and reduces mean latency relative to the prior query-time baseline. Code is available at https://github.com/allacnobug/LazyMem.
Jing Yu, Yibo Zhao, Jiaming Zhang +1
School of Data Science and Engineering, East China Normal University