Level 8Lesson 69โฑ๏ธ 45 min

Pillar 3 - Memory

The model forgets everything between turns. Memory is how an agent stays coherent across a long task - and across days

The Two Kinds of Memory

By default, a model only "remembers" what's currently on the desk. Clear the desk and it's a blank slate. To run real tasks, agents need memory - and it comes in two flavors that solve two different problems.

SHORT-TERM MEMORY   the conversation so far (this session)
                    every message, tool call, and tool result
                    โ†’ problem: it fills up the desk fast

LONG-TERM MEMORY    info that survives across sessions
                    preferences, project conventions, past summaries
                    โ†’ lives in the filing cabinet, pulled in when needed
Analogy refresher: short-term memory is what's piled on the desk during today's work. Long-term memory is the filing cabinet you reach into across days. Context engineering manages the flow between them.

The Problem Memory Creates (and Solves)

Short-term memory is a double-edged sword. The agent needs the conversation history to stay coherent - but that history is exactly what fills the context window and triggers the rot from Lesson 66. A two-hour task generates far more conversation than fits on the desk.

So context engineering gives us three tools to manage memory over long tasks:

1. COMPACTION       - summarize the old conversation, start fresh
2. NOTE-TAKING      - write notes to a file outside the window
3. SUB-AGENTS       - give side-quests their own clean desk

Tool 1 - Compaction

Compaction is the first thing you reach for. When the conversation nears the desk's limit, you have the model summarize what happened so far, then start a fresh context window with just that summary. The agent keeps going with almost no loss of coherence.

How Claude Code does it: it summarizes the history but deliberately preserves the important stuff - architectural decisions, unresolved bugs, key implementation details - while throwing away redundant tool outputs. It then continues with that summary plus the few most recently touched files.

The art is in what you keep vs. discard. Too aggressive and you lose a subtle detail that mattered. The safest, easiest win: clear out old tool results - once a search has been read, the raw output rarely needs to stay on the desk.

Tool 2 - Structured Note-Taking

This is the same trick you learned as the state file in Level 7 - here it's a memory technique. The agent writes notes to a file outside the context window (a NOTES.md, a to-do list, a scratchpad) and pulls them back in when relevant. Simple, and shockingly powerful.

The Pokรฉmon example (really): when Claude was set loose to play Pokรฉmon over thousands of game steps, it kept its own notes - maps of explored areas, which attacks beat which enemies, progress toward goals ("Pikachu has gained 8 levels toward 10"). After its desk got cleared, it re-read its notes and kept going for hours. No human told it how to structure the memory; the ability to write notes outside the window was enough.

For your work, that's a NOTES.md tracking what's done, what's left, and the gotchas - exactly the spine of any long-running agent.

Tool 3 - Sub-Agents for Clean Desks

You met sub-agents in Level 7 (maker vs. checker). They're also a memory technique. The idea: a messy side-quest shouldn't clutter the main agent's desk.

Main agent: holds the high-level plan (small, tidy desk)
   โ”‚
   โ”œโ”€ sub-agent: "go research X"  โ†’ burns 40,000 tokens exploring
   โ”‚             on its OWN clean desk, then returns a
   โ”‚             1,500-token summary
   โ”‚
   โ””โ”€ main agent receives only the tidy summary - never sees
      the 40,000 tokens of mess
Why it's a memory win: the deep, messy work stays isolated in the sub-agent's window. The main agent's desk stays clean and focused on the big picture. This is how agents tackle research too big for one context window.

Which Tool, When

COMPACTION    best for: long back-and-forth conversations that
              need to keep flowing (chat-style work)

NOTE-TAKING   best for: step-by-step tasks with clear milestones
              (build this, then that - track progress on disk)

SUB-AGENTS    best for: big research/analysis where parallel
              deep dives each need their own room

Hands-On: Compact a Conversation

Hands-on (15 min): Take a long chat you've had with an AI (or make a quick one with several twists). Ask it: "Summarize everything we've decided so far - keep decisions, open questions, and key details; drop the chit-chat - so I could paste this into a fresh chat and continue seamlessly." Read the summary critically: did it keep the important things and drop the noise? That judgment - what survives the summary - is the core skill of compaction, and you just practiced it.
Lesson 69 Quick Reference
Short-term memory

The current conversation (messages, tool calls/results) - coherent but fills the window fast

Long-term memory

Info that persists across sessions: preferences, conventions, past summaries - pulled in when needed

Compaction

Summarize the old conversation and restart the window with the summary; keep decisions, drop redundant tool output

Structured note-taking

The agent writes notes to a file outside the window (NOTES.md) and re-reads them - same idea as a state file

Sub-agents as memory

Isolate messy deep work in a sub-agent's own window; the main agent gets only a tidy summary

Match tool to task

Compaction for chats, note-taking for milestone tasks, sub-agents for big parallel research

โ† Pillar 2 - Retrieval
Unlocks in ~12 min of reading