Agent memory faces heterogeneous access needs: a single-hop question may require one piece of evidence, whereas a multi-hop question must combine evidence from multiple sources. Predefined memory workflows cannot adapt to these varying needs. Recent adaptive methods search or learn over memory components and their compositions, but the design space itself remains predefined. We introduce MemCodex, a self-evolving hierarchical memory system that organizes experience into executable memory programs for summaries, relational knowledge, reusable skills, and latent memory. Open-ended program evolution searches the open design space of layer programs by rewriting how each layer is constructed, indexed, retrieved, and routed, thereby adapting both within-layer implementations and cross-layer composition. At query time, reads traverse the hierarchy from coarse to fine and stop once sufficient evidence is found, descending to the original history when needed. We further develop MemArena, a unified runtime that places heterogeneous data and memory systems behind a common interface. MemCodex improves average task success by 10.1% relative to the strongest adaptive-memory baseline, while using 3.4x fewer context tokens and achieving 2.1x faster inference.
Figures & tables
Figure 1: MemCodex workflow. In the task loop (upper), MemArena writes the record and poses each query q to the task agent, which reads a context C from the layer hierarchy, stopping at the coarsest sufficient layer or descending to source turns, and answers a . In the program evolution loop (lower), run once per round, a parent is sampled from the archive of architectures g=(λ,ψ) , meta agent ρ rewrites one method of one layer program ψℓ , and validity checks and the acceptance test decide whether the child enters the archive.
Figure 2: Content and routing channels of MemCodex for a question about Caroline. Ctxt places summary x in C , omitting Paris, while Croute follows src(x) to the raw turn naming Paris.
Figure 3
Figure 3: The MemArena evaluation suite, with heterogeneous sources behind unified data and access interfaces and a metric suite.
Qwen3.5-27B
GPT-5.4-mini
Method
LoCoMo
LME
MAB
PMind
Avg.
LoCoMo
LME
MAB
PMind
Avg.
Tok/q
Full context
\second 61.8
57.6
43.9
51.2
53.6
\second 64.1
59.8
46.2
53.3
55.9
21.4
Dense RAG
48.9
55.1
40.7
45.8
47.6
51.2
57.3
43.0
48.1
49.9
\second 3.6
MemGPT
55.4
50.9
39.8
47.1
48.3
58.0
52.9
41.9
49.5
50.6
8.9
A-Mem
54.6
53.2
41.5
47.9
49.3
56.8
55.6
43.4
50.1
51.5
5.1
Mem0
56.4
54.1
42.2
48.8
50.4
58.7
56.4
44.5
51.1
52.7
4.2
Table 1: Quantitative results of MemCodex with Qwen3.5-27B and GPT-5.4-mini as task agents. Bold marks the best per column, underline marks the strongest baseline, and parentheses give MemCodex ’s margin over it. Tok/q counts thousands of prompt tokens per question, and LME, MAB and PMind abbreviate LongMemEval, MemoryAgentBench and PersonaMind.
Method
Avg. (%)
Rec. (%)
Tok/q (k)
Method
Avg. (%)
Rec. (%)
Tok/q (k)
MemCodex
60.8
88.4
2.0
Evolution
Hierarchy depth
No evolution
56.8 ( − 4.0)
82.6 ( − 5.8)
2.4
1 layer (raw)
54.1 ( − 6.7)
71.2 ( − 17.2)
1.8
Module selection
58.3 ( − 2.5)
84.9 ( − 3.5)
2.3
2 layers (+summary)
56.5 ( − 4.3)
78.9 ( − 9.5)
2.3
Layer rewrites
57.2 ( − 3.6)
80.9 ( − 7.5)
2.9
3 layers (+graph)
59.0 ( − 1.8)
84.6 ( − 3.8)
2.1
Program rewrites
56.7 ( − 4.1)
79.8 ( − 8.6)
3.2
Evidence channel
No acceptance test
58.1 ( − 2.7)
84.7 ( − 3.7)
2.6
Table 2: Ablations of MemCodex on hierarchy depth, evidence channel and evolution, with one change per row under the same search budget. Avg. averages the four benchmarks, Rec. denotes LoCoMo evidence recall, and parentheses give the change from MemCodex .
Figure 4: Evolution dynamics of MemCodex across three search seeds, as gain over round 0 on LoCoMo for the search-based systems (left), the fraction of test reads stopping at each layer under g⋆ by LoCoMo question type and by benchmark (middle), and LoCoMo test accuracy by question type under always-raw, stop-at-first-hit and adaptive reads (right). LME and PMind abbreviate LongMemEval and PersonaMind.
Round
Edit
Evolve
Test
Tok/q (k)
0
g0
63.6
63.4
2.31
1
summary . route
66.9
65.2
2.26
2
graph . admit
68.2
65.9
2.21
3
raw . score
68.5
66.1
2.13
5
summary . index
69.5
66.8
2.02
7
skill . route
69.9
67.0
1.94
Table 3: Accepted edits along the chain from g0 to g⋆ on LoCoMo, median seed, with the round of acceptance, the rewritten method, evolve-split and test accuracy, and thousands of prompt tokens per test question.
Method
LoCoMo
LongMemEval
MAB
PersonaMind
Avg.
AutoMem
59.6
57.3
45.5
52.2
53.7 ( − 0.4)
MemEvolve
60.0
58.0
46.1
52.9
54.3 ( − 0.4)
MemPro
60.7
58.4
46.6
53.5
54.8 ( − 0.4)
MemCodex (initial g0 )
\second 63.0
\second 59.7
\second 47.9
\second 55.1
56.4 ( − 0.4)
MemCodex
\best 65.6
\best 62.9
\best 51.4
\best 59.3
\best 59.8 ( − 1.0)
Table 4: Test accuracy under record-disjoint splits with Qwen3.5-27B, mean of three seeds, with the best per column in \best bold and the second \second underlined, and the change of the average against Table 1 in parentheses.
Figure 5: Evidence recall, question-type accuracy and cross-benchmark transfer of MemCodex , as evidence recall on LoCoMo and LongMemEval for every system of Table 1 (left), LoCoMo test accuracy by question type for MemPro, the initial architecture g0 and the evolved architecture (middle), and test accuracy of each g⋆ on each test split, darker for larger gains over g0 and bold on the diagonal (right).
Long-term memory is essential for LLM agents that operate across multiple sessions, yet existing memory systems treat retrieval infrastructure as fixed: stored content evolves while scoring functions, fusion strategies, and answer-generation policies remain frozen at deployment. We argue that truly adaptive memory requires co-evolution at two levels: the stored knowledge and the retrieval mechanism that queries it. We present EvolveMem, a self-evolving memory architecture that exposes its full retrieval configuration as a structured action space optimized by an LLM-powered diagnosis module. In each evolution round, the module reads per-question failure logs, identifies root causes, and proposes targeted configuration adjustments; a guarded meta-analyzer applies them with automatic revert-on-regression and explore-on-stagnation safeguards. This closed-loop self-evolution realizes an AutoResearch process: the system autonomously conducts iterative research cycles on its own architecture, replacing manual configuration tuning. Starting from a minimal baseline, the process converges autonomously, discovering effective retrieval strategies including entirely new configuration dimensions not present in the original action space. On LoCoMo, EvolveMem outperforms the strongest baseline by 25.7% relative and achieves a 78.0% relative improvement over the minimal baseline. On MemBench, EvolveMem exceeds the strongest baseline by 18.9% relative. Evolved configurations transfer across benchmarks with positive rather than catastrophic transfer, indicating that the self-evolution process captures universal retrieval principles rather than benchmark-specific heuristics. Code is available at https://github.com/aiming-lab/SimpleMem.
Long-horizon autonomous agents require memory systems to retain historical information, track evolving states, and reuse relevant knowledge beyond finite context windows. Existing agentic memory systems typically follow a memory construction-retrieval (MCR) pipeline, but often adapt mainly the memory bank while keeping the surrounding pipeline fixed after deployment. This fixed-pipeline design struggles to handle heterogeneous task-specific failure modes and can become misaligned with memory banks that evolve in scale and structure over time. To address these limitations, we propose MemPro, a system-level evolution framework that treats the entire MCR pipeline as an evolvable program rather than adapting only the memory bank or prompt text. MemPro maintains a version tree of runnable memory-system implementations, where an Evolving Agent iteratively selects promising versions, diagnoses recurring failures, and creates improved child versions through failure-mode-guided edit-debug refinement. Experiments on LongMemEval, LoCoMo, HotpotQA, and NarrativeQA show that MemPro consistently outperforms strong static and prompt-level evolving baselines within a few iterations, continues to improve with evolution, and achieves a favorable performance-cost trade-off. Code is available at https://github.com/wanghai673/MemPro.
Long-term memory remains a fundamental bottleneck for large language model (LLM) agents across sessions. Existing systems typically adopt a write-then-retrieve paradigm, storing context-dependent dialogue fragments and retrieving them via nearest-neighbor search in a continuous embedding space. This design yields unstable access units and systematically misses logically related but lexically distant evidence. We propose MemCode, a long-term agent memory framework that couples retrieval-oriented writing with discrete associative retrieval. MemCode rewrites dialogue into self-contained atomic memory units (AMUs), maps AMUs into a learnable codebook with isomorphic semantic quantization (ISQ), and uses codebook co-occurrence topology as a retrieval path complementary to vector search. For long-term memory stores, MemCode separates online atomic writes from asynchronous offline consolidation. On LongMemEval-S and LoCoMo with GPT-4o-mini and Qwen3-30B-A3B-Instruct-2507 backbones, MemCode achieves the best overall accuracy while keeping per-dialogue memory construction within roughly 40130 seconds, making it 321 times faster than LightMem and over an order of magnitude faster than A-MEM and MemoryOS.