Chapter 6: How the Agent Remembers
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.
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.
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.
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.
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.
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.