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 neededThe 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.
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.
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 messWhich 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 roomHands-On: Compact a Conversation
The current conversation (messages, tool calls/results) - coherent but fills the window fast
Info that persists across sessions: preferences, conventions, past summaries - pulled in when needed
Summarize the old conversation and restart the window with the summary; keep decisions, drop redundant tool output
The agent writes notes to a file outside the window (NOTES.md) and re-reads them - same idea as a state file
Isolate messy deep work in a sub-agent's own window; the main agent gets only a tidy summary
Compaction for chats, note-taking for milestone tasks, sub-agents for big parallel research