MemGPT is an architecture for stateful language model agents that manages a limited context window the way an operating system manages memory, moving information between a fast in-context main memory and slower external storage through function calls the model issues itself. Among AI agents, it is the best-known design for long-term, self-editing agent memory, introduced in a 2023 research paper from the University of California, Berkeley titled “MemGPT: Towards LLMs as Operating Systems”.
In 2024 the open-source project and its maintainers moved under the name Letta, which now develops a framework and server for persistent agents built on the same ideas. The term MemGPT remains in use for the original memory architecture and its paging pattern.
How MemGPT applies virtual memory to a context window
A language model can only reason over the tokens in its fixed-size context window. MemGPT treats that window like physical RAM and treats databases outside the model like disk. The model is given functions to read, write and search the external tiers, so it decides itself what to load into context and what to evict, similar to how an operating system pages data between memory and storage.
This approach is called virtual context management. The agent appears to have an unbounded memory even though every single model call still fits within the token limit. Unlike a plain retrieval pipeline, where an outside component decides what to fetch, the model itself controls memory operations as part of its reasoning.
The table below maps the operating system analogy to the actual components of the architecture.
| Operating system concept | MemGPT counterpart | Role |
|---|---|---|
| Physical memory | Main context (prompt tokens) | What the model can see now |
| Disk storage | External context (databases) | Unlimited, searchable history and facts |
| Page in and page out | Memory function calls | Moving data into or out of context |
| Interrupts | User messages and system events | Triggers that start processing |
| Memory pressure warning | Warning near the token limit | Prompts the agent to save important data |
The memory tiers of a MemGPT agent
MemGPT divides memory into an in-context tier and two out-of-context tiers. The main context holds fixed system instructions, an editable working context and a first-in, first-out queue of recent messages. The working context, later formalized as core memory blocks, typically stores a persona for the agent and key facts about the user.
| Tier | Location | Contents | How it is accessed |
|---|---|---|---|
| System instructions | Main context, read-only | Rules and function descriptions | Always present |
| Core or working memory | Main context, editable | Persona and user facts | Append and replace functions |
| Message queue | Main context, FIFO | Recent conversation turns | Evicted when space runs out |
| Recall storage | External database | Full message history | Conversation search by text or date |
| Archival storage | External vector database | Documents and long-term notes | Insert and semantic search |
When the queue fills, a queue manager evicts older messages to recall storage and replaces them with a recursive summary, so the agent keeps a compressed trace of what it can no longer see in full.
Self-editing memory and the agent loop
Every interaction in MemGPT is a function call, including sending a reply to the user. This lets the agent chain several memory operations before it answers. A function can request a heartbeat, which immediately returns control to the model for another reasoning step instead of waiting for the next user event.
- core_memory_append and core_memory_replace update persona and user facts inside the prompt.
- archival_memory_insert and archival_memory_search store and retrieve long-term knowledge.
- conversation_search finds earlier messages that have been paged out of context.
- send_message delivers the visible answer to the user.
Because the model rewrites its own core memory, it can correct outdated facts, for example replacing an old job title after the user mentions a promotion. This self-editing behavior is the main feature that separates MemGPT from systems that only append history to a log.
MemGPT compared with other memory approaches
MemGPT is one answer to the broader problem of agent memory. The comparison shows how it differs from approaches that rely only on longer windows or on externally controlled retrieval.
| Approach | Who decides what is remembered | Strength | Weakness |
|---|---|---|---|
| MemGPT | The model, via function calls | Persistent, editable, unbounded memory | Extra calls and latency |
| Long context window | Nobody, everything is kept | Simple, no retrieval errors | Cost grows, attention degrades |
| Retrieval augmented generation | Fixed retriever outside the model | Cheap and predictable | No self-editing, static queries |
| Context compaction | Harness or summarizer | Keeps sessions running longer | Loses detail over time |
| Generative agents memory stream | Scoring by recency, importance, relevance | Rich reflection on experience | Designed for simulations |
In practice these patterns are often combined: a MemGPT-style agent may use a long-context model, retrieval over archival storage and periodic summarization of evicted turns.
The original paper evaluated the design in two settings. In multi-session chat, agents had to recall details from earlier conversations, and MemGPT answered consistency questions more accurately than fixed-context baselines. In document analysis, it handled collections larger than the context window and could follow nested key-value lookups that required several chained retrievals. Results depended strongly on the underlying model, with the strongest function-calling models performing best.
Limitations and practical considerations
MemGPT depends heavily on the model’s function calling reliability. Weaker models forget to save important facts, write vague memories or search with poor queries. Each memory operation adds a model call, so latency and token cost rise compared with a single prompt.
Persistent memory also raises privacy and governance questions. Stored facts about users must be inspectable, correctable and deletable, and memory written from untrusted input can carry prompt injection into later sessions. Production deployments therefore need memory review tools, access controls and clear retention policies.
In plain words
A chatbot can only look at a limited amount of text at one time. MemGPT gives it a notebook and a filing cabinet. The notebook sits on the desk and holds the most important facts. The filing cabinet stores everything else.
The assistant decides what to write down, what to file away and what to look up again. So it can remember you across many conversations, even though it never sees everything at once.
A real-world example
A language-learning app deploys a tutoring agent built on the Letta framework. Each learner gets a persistent agent with a core memory block describing the learner’s level, goals and frequent mistakes, plus archival storage that holds past lesson notes.
After three months and more than 150 short sessions, a learner returns and asks to practice past tense verbs again. The agent searches archival storage, finds that irregular verbs caused repeated errors in week six, and starts with those verbs. Its core memory already records that the learner prefers travel topics, so the exercises use airport and hotel scenarios. The result is a lesson that feels continuous, while each individual model call still stays well within the context limit.