# Agent memory

> VI: https://5ac.vn/wiki/agent-memory/ · EN: https://5ac.vn/en/wiki/agent-memory/ · lang: en · spec_as_of 2026-10-18 (spec no formal spec) · cluster C4

The data layer an AI agent writes and reads across working sessions, kept outside the model's context window: short-term in context, durable facts outside, reloaded on demand.

---
## Definition

Agent memory is the data layer an agent writes to and reads from across working sessions, kept outside the model's context window: short-term state lives in context while durable facts live outside and reload at the right moments, so the agent remembers, reflects and resumes work instead of booting cold.

## Mechanism

The theoretical foundation is MemGPT (Packer et al., 2023): limited context windows box LLMs in, and the fix is borrowed from operating systems: hierarchical memory, where data moves between fast and slow tiers to create the appearance of more memory than there is. MemGPT calls this virtual context management: intelligently managing memory tiers to provide extended context inside the window's hard limit, using interrupts to steer control flow between agent and user. The paper proves the design in the two domains where the window hurts most — documents that exceed the context window, and multi-session chat, where agents must remember, reflect and evolve dynamically through long-term interaction.

The product line is Letta (f.k.a. MemGPT), whose README bills stateful agents with memory that can learn and improve over time; the active source now lives in letta-ai/letta-code (an agent harness with a terminal UI and an App Server). Letta's memory docs translate the paper's mechanism into three decisions: memory is part of the agent's state, living in a git repository the agent owns (MemFS), an edit becomes memory only once committed and pushed. Memory blocks (`persona`, `human`, custom labels) become markdown files keyed by label, with files under `system/` entering the system prompt every turn while the rest stays out of context. The agent sees the file tree and reads what it needs. Dreaming — background subagents that review recent conversations, consolidate lessons and update memory without interrupting active work.

| Tier | Contents | Behavior toward context |
| --- | --- | --- |
| In-context | system prompt + files under `system/` + conversation window | present and spending tokens every turn |
| MemFS outside context | other labelled memory files, the full tree | the agent reads on demand |
| Dreaming | a subagent reviewing recent conversations, consolidating | fires on trigger: step count or compaction |

Zhang et al. (2024) survey the whole field: what agent memory is, why agents need it, how memory modules get designed and evaluated, which applications lean on it, and where current work falls short.

Flow: Conversation → agent edits memory → commit into MemFS (its own git repo) → relevant memory reloaded into context → dreaming subagent consolidates and tidies

## Spec anchor

No committee spec exists for agent memory; this anchor pins verified source-document revisions: MemGPT at v2 (updated 2024-02-12) and the memory survey at v1 (submitted 2024-04-21), read from the arXiv API on 2026-10-18; Letta per its README (main branch) and the current memory docs page, fetched the same day. Letta's docs are mid-restructure and several older memory paths redirect elsewhere, so this entry pins only URLs verified to return 200 rather than guessing a canonicalized path.

Sources fetched for this entry:

- <https://arxiv.org/abs/2310.08560> — MemGPT abstract page (v2) — accessed 2026-10-18
- <https://arxiv.org/abs/2404.13501> — agent-memory survey abstract page (v1) — accessed 2026-10-18
- <https://export.arxiv.org/api/query?id_list=2310.08560,2404.13501> — arXiv API: verified IDs, authors, abstracts — accessed 2026-10-18
- <https://github.com/letta-ai/letta> — Letta repository (f.k.a. MemGPT) — accessed 2026-10-18
- <https://raw.githubusercontent.com/letta-ai/letta/main/README.md> — README: stateful-agents positioning, active source at letta-ai/letta-code — accessed 2026-10-18
- <https://docs.letta.com/agent-sdk/memory/index.md> — memory docs: MemFS, memory blocks, dreaming — accessed 2026-10-18

## Academic anchors

Both IDs sit in the frontmatter, verified through the arXiv API on 2026-10-18. *MemGPT: Towards LLMs as Operating Systems* (arXiv:2310.08560, Charles Packer, Sarah Wooders, Kevin Lin, Vivian Fang, Shishir G. Patil, Ion Stoica et al.; submitted 2023-10-12) is the foundational systems paper: the Mechanism section above is built from its abstract. *A Survey on the Memory Mechanism of Large Language Model based Agents* (arXiv:2404.13501 — Zeyu Zhang, Xiaohe Bo, Chen Ma et al.; submitted 2024-04-21) is the systematic map, with a living repository tracking newer work at nuster1128/LLM_Agent_Memory_Survey.

## FAQ

**How is agent memory different from the context window?** The context window is the working memory of one conversation turn — past its limit, older content gets truncated or compacted. Agent memory sits outside the window: durable across sessions, models and machines, pulled back in selectively when needed.

**How is agent memory different from RAG?** RAG retrieves documents to answer questions: the corpus belongs to the world. Agent memory stores the agent's own state (persona, lessons from past sessions, unfinished commitments) — the corpus belongs to the agent. They meet in one mechanism: loading external context into the window on demand.

**What is the relationship between MemGPT and Letta?** Letta is the project's current name — its README says "f.k.a. MemGPT." The 2023 paper defines virtual context management; Letta industrializes it as a stateful-agent product with MemFS and dreaming in the current docs.

**What is dreaming?** A Letta pattern where a background subagent, triggered by step count or context compaction, reviews recent conversations, consolidates lessons and updates memory — learning happens off the interaction path, without interrupting the user.

**Why should a business care?** An agent that forgets everything after one session re-learns from scratch every run: lost client context, broken commitments, repeated questions. Memory is what makes multi-session chat and long-running processes viable — exactly the two domains the MemGPT paper chose for its experiments.

## Related

- [What is a Multi-Agent OS?](/en/blog/what-is-multi-agent-os/)
- [YC open-sources QM — a multi-agent harness](/en/blog/yc-qm-open-source-multi-agent-harness/)
- [What is agentic RAG?](/en/wiki/agentic-rag/)
- [What is a sub-agent?](/en/wiki/sub-agent/)
