Memory as Code: Declarative Retrieval over Codified Long-Term Memory
Aoting Zeng, Yuxin Du, Jianwei Wang, Yizhang He, Shan Jiang, Xuemin Lin, Kai Wang
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.
Create a lesson
Related papers
MOSAIC: An Omni-Modal Benchmark for Long-Term Memory and Cross-Modal Reasoning in Conversational Agents
Shared title terminologycs.CLHong Ting Tsang, Boyi Zhang, Haoyu Huang et al.
ContextFact: Remembering Facts in Context for Long-Term Conversational Agents
Shared title terminologycs.CLJiayu Huang, Yichao Cai, Xinyu Li et al.
Learning What to Ask for Tomorrow: Active Preference Acquisition for Long-Term Personalized Web Agents
Shared title terminologycs.CLYiqi Wang, Zizhi Zeng, Jiaqi Zhang et al.
OptionWorld: A Benchmark for Diagnosing Failures of LLMs as Long-Term Personal Assistants
Shared title terminologycs.CLRuoyu Zhang, Zhaocen Liu, Weiyi Tian et al.
MERIT: Experience-Guided Memory for Long-Horizon Persona-Specific Persuasive Dialogue
Shared title terminologycs.CLRohan Kirti, Akash Ghosh, Pratik Amrit et al.
Uni-Mem: Learning a Long-Horizon Agentic Memory Manager with Unified Online Policy Optimization
Shared title terminologycs.CLZhiqian Xia, Jielong Tang, Ling-An Zeng et al.