← Dashboard

Memory & State

Chapter 6: How the Agent Remembers

Brain
Session 1
Session 2
Session 3
Session 4
?
Step 1

The Goldfish Problem

Each API call starts fresh. The model doesn't remember last session. It doesn't remember last week. Without memory infrastructure, every conversation starts from zero. The agent is a genius goldfish.

Step 2

Three Layers of Memory

Short-term: the current conversation. Medium-term: session files that persist across context resets. Long-term: patterns learned across many sessions. Each layer has different storage, different retrieval, different trade-offs.

Step 3

Crash and Resume

Watch: the agent works, a crash happens, and it picks up where it left off. The secret is the session log: a file that records every action and result. On resume, replay the log into context.

No log = start over. With log = resume in seconds.

Step 4

Files as Working Memory

A scratchpad for thinking-in-progress. A todo list for tracking tasks. Both files live on disk, injected into context each turn. The model reads them, updates them, and maintains state that survives context compaction.

Step 5

Learning Over Time

True long-term memory means the agent improves across sessions. It learns your naming conventions. Remembers which approaches worked. Knows your project structure. The curve is logarithmic. Biggest gains come early.

Step 6

Build Memory Bottom-Up

Start with session logging. Just append each action to a file. Then add working memory files (scratchpad + todo). Only add long-term storage when you have enough sessions to learn from. Premature memory systems add complexity without value.