Memory as Code: Declarative Retrieval over Codified Long-Term Memory
Aoting Zeng, Yuxin Du, Jianwei Wang, Yizhang He, Shan Jiang, Xuemin Lin, Kai Wang
Key points
From the paper's conclusion- MaC couples codified construction, which establishes executable memory abstractions, with declarative retrieval, which translates queries into structured retrieval programs.
Abstract
In long-term memory systems, memories are constructed from interaction histories and retrieved in response to queries, enhancing the reasoning ability of LLM agents. In complex scenarios, facts are scattered across sessions and their relationships evolve over time, making it difficult for existing memory systems to compose them to adapt to diverse queries. Motivated by the modularity and composability of code, we propose Memory as Code (MaC), a unified memory framework that jointly designs memory construction and retrieval through a shared code abstraction. MaC couples codified construction, which establishes executable memory abstractions, with declarative retrieval, which translates queries into structured retrieval programs. Specifically, codified construction builds a three-layer executable memory structure that progresses from an atomic function layer, through a relational layer, to a modular composition layer. Declarative retrieval recasts retrieval from relevance-based fact selection into declarative query processing over memory. Experiments on LoCoMo and LongMemEval show relative gains of up to 15.91% in overall LLM-judge accuracy over the strongest baseline in each setting, while substantially reducing token consumption, highlighting the effectiveness of memory as code for long-horizon memory tasks.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- MemCode: Discrete Semantic Representations for Long-Term Agent MemoryarXiv · 2026
- MemCodex: Self-Programming Hierarchical Memory for Language AgentsarXiv · 2026
- From Retrieval to Reconstruction: Constructing Evolvable Cognitive Memory for Long-Term DialoguearXiv · 2026
- MGMem: An Efficient, Deterministic, and Provenance-Preserving Framework for Long-Horizon Agent MemoryarXiv · 2026
- REM: What to Store, When to Recall, What to Forget in Experience Memory for Coding AgentsarXiv · 2026
- Remember by Asking: Retrieval-Induced Memory Evolution for LLM AgentsarXiv · 2026