Vibe Engines
YouTube

Vibe Engines is free, interactive AI engineering & system design — runs in your browser. Pick a learning path

~8 min readBerkeley · 2023

MemGPT,
explained.

Your computer has 16 GB of RAM and runs programs that think they have terabytes — because the operating system quietly pages memory between RAM and disk. MemGPT asked: why not do the same for a language model? Treat the context window as RAM, external storage as disk… and make the model itself the operating system, paging its own memories in and out with function calls.

The delta

What changes against a memory stream: the model manages its own memory

Rung 5's agent has memory and no control over it. A retrieval policy picks what enters the context, scored by rules the designer fixed, and the agent is a passive recipient — it cannot decide that something matters, cannot choose to write a conclusion down, cannot go and look for what it knows it needs.

The change is an analogy carried through completely: treat the context window as RAM and external storage as disk, and make the model the memory manager. It reads and writes its own memory through ordinary function calls — page a document in, write a fact out, search the archive, edit its own working notes. When the context approaches full, memory pressure raises an interrupt and the model is given the chance to summarise and evict before anything is lost, rather than having the oldest content silently fall off the end.

Stated in the units the ladder compares on: rungs 1 to 5 have a bounded effective memory — whatever fits, plus whatever a fixed retrieval policy happens to surface. This has an unbounded one from a bounded context, in exactly the way a program addresses more memory than it has physical RAM. And the decision about what is worth keeping is made by the only component that knows what the task needs.

01

The goldfish problem

In 2023, the context windows most people used were around 4–8K tokens (GPT-4 Turbo reached 128K late that year), and even today every window is finite. The failure it causes is intimate: tell an assistant in January that you're vegetarian, and by March — three hundred messages later — it cheerfully recommends a steakhouse. The fact scrolled out of the window, and out of existence. Naive fixes each fail: bigger windows fill eventually (and degrade as they fill); summarizing everything blurs details; RAG over history retrieves but never updates — the model can look things up, but it can't remember that a fact changed.

What long-lived assistants need isn't a bigger window. It's memory management: deciding what stays instantly visible, what gets archived, what gets revised, and what comes back when relevant.

02

Steal the oldest trick in systems

Operating systems solved exactly this problem sixty years ago. Programs address vast virtual memory; the OS keeps hot pages in small fast RAM, parks cold pages on big slow disk, and swaps on demand. The program never knows. MemGPT maps the hierarchy one-to-one: main context (the window) is RAM; external context (a database) is disk; function calls are the paging mechanism.

The key idea

The radical part isn't the hierarchy — it's the manager. In an OS, dedicated kernel code decides what to page. In MemGPT, the LLM manages its own memory: it decides what's worth saving, what to revise, and what to search for, using its own judgment of relevance.

03

The tiers: what lives where

TierLivesHolds
Core memoryin-window, always visiblethe durable facts: user profile, persona, standing preferences — small and editable
Message bufferin-window, FIFOrecent conversation, evicted as it ages
Recall storageout-of-windowfull message history, searchable
Archival storageout-of-windowarbitrary saved knowledge, documents, notes

The split encodes a theory of importance: identity-level facts deserve permanent residence in the window ("vegetarian" should never need retrieval); everything else earns its way back in through search. Getting that boundary right is most of the art of agent memory to this day.

04

Memory as tools: the model edits itself

All of it runs on ordinary function calling. MemGPT hands the model tools like core_memory_replace, archival_memory_insert, conversation_search — and the system prompt teaches it to be its own librarian.

User: "By the way, I moved from Austin to Berlin last month."
function: core_memory_replace("lives in Austin" → "lives in Berlin")
function: archival_memory_insert("Moved to Berlin, June — misses Texas BBQ")
Assistant: "Big move! How's Berlin treating you?"

Note what happened: the fact wasn't appended, it was revised — the old value is gone from core memory. That's the operation RAG-over-history fundamentally can't do, and it's why MemGPT agents don't recommend steakhouses to vegetarians in March.

And the paging rule is exactly an OS's: when the in-window tokens exceed the budget, evict the oldest buffer messages to out-of-window recall until it fits again — core memory never evicts:

Recent chat ages out to searchable storage; identity facts and revisions stay in the window. The runnable version below pages, revises, and searches.

05

Interrupts, heartbeats, and memory pressure

The OS analogy runs deeper than storage. MemGPT is event-driven: user messages, timers, and function results all arrive as interrupt-like events that wake the processor (the LLM). A heartbeat mechanism lets the model chain multiple steps — search, then read, then answer — without the user prompting each one.

And when the message buffer nears capacity, the system raises a memory-pressure warning — the model is told, in-band, that eviction is coming, and it responds like a good process: summarizes what matters, writes the durable bits to archival storage, and lets the rest page out. Forgetting becomes a managed operation instead of a silent catastrophe.

07

Why it still matters

MemGPT wrote the vocabulary of agent memory. Core vs recall vs archival tiers, memory-exposed-as-tools, summarize-on-pressure, the agent as its own memory manager — that architecture is now visible in nearly every serious agent framework and every "the assistant remembers you" product. The project itself became Letta, a runtime built around persistent self-editing agents.

The deeper legacy is the framing: LLM limitations are systems problems. The model is a processor; intelligence about memory, scheduling and I/O can live in the architecture around it. That lens — the LLM-as-OS-process view — now shapes agent memory design, context engineering, and the whole harness discipline.

Read next

The mechanism it runs on: Toolformer and tool calling. The production blueprint: Design an Agent Memory System. The discipline it seeded: Context Engineering.

How it works

How MemGPT manages its context window, step by step

MemGPT treats a fixed-context model as a processor and builds an operating-system-style memory around it. The paper's experiments use GPT-4 (an 8,192-token window), GPT-4 Turbo (128,000) and GPT-3.5 Turbo (16,385) as that processor.

main context: the whole prompt 70%: warning 100%: flush System read-only Working context edited by calls Summary recursive m1 m2 m3 m4 m5 m6 Archival storage documents, notes New summary old + evicted Recall storage all messages, searchable insert, search oldest ~50% evicted heartbeat: run again after a call evicted, not deleted: still searchable
MemGPT's main context: read-only system instructions, an editable working context, and a FIFO queue headed by a recursive summary. At 70 percent of the window the model is warned; at 100 percent the oldest messages, about half the window in the paper's example, move to recall storage and are folded into a new summary.
  1. Divide the prompt into three regions. System instructions are read-only and describe the control flow, the memory tiers and the function schemas. Working context is a fixed-size block of text the model can change only through function calls; in conversation it holds key facts about the user and the persona the agent plays. The FIFO queue holds the rolling message history, including system messages such as memory warnings and the inputs and outputs of function calls, and its first slot is a recursive summary of everything already evicted.
  2. Keep two stores outside the prompt. Recall storage is a database of every message the system has processed. Archival storage is a read-write database for text of any length, such as documents or facts the agent decides to save.
  3. Run the queue manager on every message. It appends the new message to the queue, assembles the prompt, triggers inference, and writes both the input and the output to recall storage.
  4. Warn at 70 percent. When the prompt passes a warning threshold, 70 percent of the window in the paper's example, the queue manager inserts a memory-pressure system message, giving the model a chance to save what matters to working context or archival storage.
  5. Flush at 100 percent. When the prompt reaches the window, the manager evicts a block of the oldest messages, half the window in the example, and generates a new recursive summary from the old summary and the evicted messages. The evicted messages leave the prompt but stay searchable in recall storage.
  6. Execute the model's function calls. Output is parsed as a function call and its arguments checked; valid calls run, and results and errors, such as trying to write to a full working context, come back as messages so the model can correct itself. Searches return paginated results so one call cannot overflow the window.
  7. Chain steps with heartbeats. A call can set request_heartbeat=true, and the processor runs again as soon as the function returns. That is how the agent searches, reads a page of results, searches again and only then answers. Without the flag the call is a yield, and the agent waits for the next event: a user message, a system alert such as a document upload, or a scheduled timer.

Apart from the forced eviction at the limit, nothing moves unless the model decides to move it, which is what the paper means by self-directed memory. The paper's example conversation shows the agent replacing a stored fact about the user when the user's situation changes, instead of keeping both versions side by side. The paper calls the editable block working context; the released code, now part of Letta, calls it core memory.

The math

MemGPT's context budget, eviction rule and heartbeat

tokens(system) + tokens(working context) + tokens(summary + queue) ≤ W
tokens(prompt) > 0.7·W ⇒ append a memory-pressure warning to the queue
tokens(prompt) ≥ W ⇒ evict the oldest messages (≈ 0.5·W) · summary′ = LLM(summary, evicted) · recall ← recall ∪ evicted
after a function call: request_heartbeat = true ⇒ infer again now; otherwise yield until the next event
  • W — the backbone's context window, 8,192 tokens in the GPT-4 runs.
  • 0.7, 1.0, 0.5 — the paper's example warning, flush and eviction fractions.
  • summary′ — the new recursive summary, which folds the old one together with what was evicted.
  • recall — the message database; eviction moves messages out of the prompt, never out of the system.

The fractions set the trade-offs. Warn too late and there is no room left to save anything before the flush; evict too little and the system flushes and re-summarizes constantly, compounding the loss in each summary of a summary. Since nothing is deleted, the cost of a bad summary is not forgetting but searching: a fact that survives only in recall storage is used only if the model thinks to look for it.

The evidence

MemGPT on multi-session chat, document QA and nested lookups

The conversation tests extend Multi-Session Chat, in which crowdworkers kept consistent personas across five sessions of about a dozen messages each. In deep memory retrieval the user asks, in a new sixth session, a question that only an earlier session can answer. Answers are graded by an LLM judge for accuracy and by ROUGE-L recall. The fixed-context baselines see a lossy summary of the five past sessions; MemGPT sees none of them directly and must page them in by searching recall storage.

BackboneBaseline accuracyWith MemGPTROUGE-L, baseline → MemGPT
GPT-3.5 Turbo38.7%66.9%0.394 → 0.629
GPT-432.1%92.5%0.296 → 0.814
GPT-4 Turbo35.3%93.4%0.359 → 0.827

A second chat task scores the agent's opening message for a new session by its similarity to the user's persona facts; MemGPT's openers scored above the human-written one on two of the three similarity measures with every backbone, but below it on the third, which compares directly against the human opener; storing facts in working context was what made them work.

Document QA follows the multi-document setup of the lost-in-the-middle study over Wikipedia passages, with 50 sampled questions judged by an LLM. Fixed-context baselines are capped by how many retrieved documents fit and by the retriever itself; MemGPT pages through results in archival storage, so a larger document set does not cap it. Two weaknesses showed: it often stopped paging before exhausting the results, and with GPT-3.5 its accuracy dropped sharply because of weak function calling.

The nested key-value task packs 140 UUID pairs, about 8,000 tokens, into the context, and values can themselves be keys, up to four levels deep. GPT-3.5 fell to 0 percent at one level of nesting, usually returning the first value it found, and GPT-4 and GPT-4 Turbo reached 0 percent by three. MemGPT with GPT-4 was unaffected by depth. With GPT-4 Turbo or GPT-3.5 it beat the baselines but began failing at two levels by not making enough lookups, so the stronger GPT-4 Turbo baseline did not make the stronger MemGPT agent.

Since then

What the authors admit, and what happened next

The whole design rests on the model being good at paging decisions, which is a hard judgement badly served by the training these models get: knowing what will matter later is a prediction about a future the model cannot see. The characteristic failures are exactly what the analogy predicts — a fact that was never written out and is therefore gone, a summary that discarded the one detail that mattered, and search calls for something that was never stored.

It also costs calls. Memory management is itself model inference, so an agent spends part of its budget on bookkeeping, and that overhead is paid on every interaction whether or not anything needed remembering.

How it held up: the operating-system framing became the dominant way to talk about agent memory, which is a large contribution for an analogy — it supplied the vocabulary (working context versus archive, paging, eviction, pressure) that the field now uses by default, and it continued as a maintained system rather than staying a paper. Read rungs 5 and 6 as the same disagreement that operating systems had: automatic management is more reliable, explicit control is more powerful, and neither has won.

SOLVE IT YOURSELF

Page memory like an operating system

MemGPT's memory manager is small enough to hold in your hand. This is a tiny agent with a token-budgeted context window: core memory that stays resident and can be revised in place, a message buffer that ages out under pressure, and recall storage that keeps the overflow searchable. Watch it revise "Austin → Berlin" (the old value gone — the edit RAG can't make), then flood the window with messages and see the oldest page out to recall while the core facts never budge. Change the budget or the messages.

YOUR TASK

Write the body of add. Everything else in the file is already written; this is the function the paper is about. Press ▶ Run to check it against the 5 assertions below — they start red.

WHAT IT HAS TO SATISFY — 5 ASSERTIONS
  1. Core_memory_replace revises a fact in place (old value gone)
  2. The in-window size never exceeds the token budget
  3. Memory pressure pages the oldest messages out to recall
  4. A paged-out message stays searchable in recall
  5. Core memory survives eviction
CPython · WebAssembly
Questions

Questions people ask about MemGPT

How is MemGPT different from RAG?

Retrieval-augmented generation runs a fixed retrieval step on the model's behalf: the system embeds the query, fetches the top passages and puts them in the prompt, every time. MemGPT hands those decisions to the model. It decides when to search, what query to use, whether to page to the next set of results and what to write down, and it can edit its own working context, for example replacing an outdated fact instead of appending a contradicting one. In the paper's document QA test, fixed-context baselines were capped by how many retrieved documents fit in the window, while MemGPT could keep paging through archival storage; its weaknesses were stopping early and depending on reliable function calling.

What goes into MemGPT's main context, and in what order?

Three contiguous sections. First, read-only system instructions explaining the control flow, the memory tiers and how to call the memory functions. Second, working context, a fixed-size block of text the model can edit only through function calls, used in conversation for key facts about the user and the agent's persona. Third, a first-in, first-out queue of recent messages, which also holds system notices such as memory-pressure warnings and the inputs and outputs of function calls; its first entry is a recursive summary of everything evicted so far. Everything else lives outside the prompt, in recall storage, the full message history, and archival storage, a general read-write database.

When does MemGPT evict messages, and what happens to them?

In the paper's example settings, when the prompt passes 70 percent of the model's context window the queue manager inserts a memory-pressure warning, so the model can save important details to working context or archival storage. When the prompt reaches 100 percent, the manager evicts the oldest messages, about half the window's worth, and generates a new recursive summary from the previous summary and the evicted messages. Evicted messages are not deleted. They remain in recall storage, which the model can search with function calls and page back into context later.

What does request_heartbeat do in MemGPT?

It lets the model chain several steps without waiting for the user. MemGPT is event-driven: user messages, system alerts such as a document upload, and scheduled timers each trigger one round of inference. When the model calls a function with request_heartbeat set to true, the system runs the model again as soon as the function returns, with the result in context, so it can search, read a page of results, search again and only then reply. Without the flag the call is a yield, and the processor stays idle until the next external event. This is what makes the multi-hop lookups in the nested key-value task possible.

Is Letta the same thing as MemGPT?

Letta is what the MemGPT project became. The open-source MemGPT code was renamed Letta in 2024, when its authors started a company of the same name around it, and MemGPT now usually refers to the agent design in the paper: a model that manages tiered memory through function calls. The core ideas carried over directly, including an always-visible block of editable memory that the code calls core memory and the paper calls working context, a searchable message history and archival storage. Letta's current interfaces postdate the paper, so check its documentation rather than the paper for those details.

Which language models work best inside MemGPT?

In the paper, GPT-4. MemGPT depends on the backbone reliably choosing and formatting function calls, and weaker function calling showed up directly in the results. On document QA, MemGPT with GPT-3.5 was significantly worse than with GPT-4. On nested key-value lookups, MemGPT with GPT-4 was unaffected by nesting depth, while MemGPT with GPT-4 Turbo and with GPT-3.5 began failing at two levels because they did not issue enough lookups, even though GPT-4 Turbo was the stronger fixed-context baseline. On deep memory retrieval all three improved, but GPT-3.5 reached 66.9 percent against 92.5 and 93.4 for the GPT-4 models.

Check yourself

4 questions to test what you just read

Work each one out before you open it — a number, a prediction or a reason, not a definition. Producing the answer is what makes it stick. Your progress is kept on this device.

With GPT-4's 8,192-token window and the paper's example settings, at what prompt size does the memory-pressure warning fire, and roughly how many tokens does a flush free?

Show answer

0.7 × 8,192 ≈ 5,734 tokens triggers the warning. The flush comes at 8,192 and evicts about 0.5 × 8,192 ≈ 4,096 tokens of the oldest messages, which are folded into an updated recursive summary and stay searchable in recall storage.

In the nested key-value task all 140 pairs fit inside GPT-4's window, yet fixed-context GPT-4 hit 0 percent by three nesting levels. Why does MemGPT with GPT-4 succeed with the same data?

Show answer

The baseline has to chain every hop in a single answer and tends to stop at an intermediate value. MemGPT turns each hop into a separate search, linked by heartbeats, and checks whether the value it found is itself a key; it answers only when a lookup turns up nothing further.

A user mentions a peanut allergy in session 2, and the model never writes it to working context. What path must the fact take to affect a reply in session 6, and where can it be lost along the way?

Show answer

It stays in the FIFO queue until evicted, then lives in recall storage and possibly in the recursive summary. In session 6 it matters only if the model searches recall storage with a query that finds it. It is lost if the summary drops it, or if the model never thinks to search.

Why does MemGPT need the request_heartbeat flag if the model can already call functions?

Show answer

Without the flag a function call is a yield: the system waits for the next user message or timer before running the model again. A multi-step retrieval, search, read the next page, then answer, would need the user to prompt every step. The flag tells the scheduler to run the model again immediately with the result in context.

Where this sits

Agents that act

Give the model a tool, then a loop, then a memory, then a world. Ends on the 2026 paper measuring how badly the whole stack degrades over many turns.

  1. 1ReAct2023
  2. 2Toolformer2023
  3. 3Reflexion2023
  4. 4Voyager2023
  5. 5Generative Agents2023
  6. 6MemGPT2023
  7. 7LLMs Get Lost in Multi-Turn Conversation2026

All 110 papers, in 19 ladders →

Finished this one? 0 / 110 Paper Breakdowns done
NextLLMs Get Lost in Multi-Turn Conversation Next on the “Agents that act” ladder · rung 7 of 7

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More Paper Breakdowns