Memory: Virtual Context and MemGPT

Context windows are finite. Conversations, documents, and tool traces are not. MemGPT (Packer et al., 2023) frames this as OS virtual memory — main context is RAM, external store is disk, the agent pages between them. This is the pattern every 2026 memory system inherits.

Build 1.3 hr Python (stdlib)

Prerequisites: Phase 14 · 01 (Agent Loop), Phase 14 · 06 (Tool Use)

#Learning Objectives

  • Explain the OS analogy MemGPT builds on: main context = RAM, external context = disk, memory tools = page in/out.
  • Implement the two-tier MemGPT pattern in stdlib with a main-context buffer, an external searchable store, and page in/out tools.
  • Describe how the agent issues "interrupts" to query or modify external memory and how the result is spliced back into the next prompt.
  • Identify the MemGPT design choices that carry into Letta (Lesson 08) and Mem0 (Lesson 09).
Full Access lesson

Keep going. The rest of this lesson is one step away.

Unlock all 503 lessons, video, code, quizzes and every future update. Pay in your own currency with Paystack.

The text and code of this lesson are based on AI Engineering from Scratch by Rohit Ghumare, MIT licensed.