Chapter 12: Memory Management for Production Agents¶
Every agent we build in this book forgets. The Document Agent answers a question and starts fresh. The Incident Runbook Agent resolves an incident and loses the context. In production, this amnesia is the difference between a demo and a product.
What this chapter covers¶
- Session memory -- surviving the context window with importance-weighted truncation and compaction
- Long-term memory -- learning from corrections, avoiding repeated mistakes, two-pass retrieval
- Shared memory -- multi-agent coordination with scoped state stores and optimistic concurrency
- Production frameworks -- Mem0, Zep, and Letta compared with current benchmarks
- Memory security -- poisoning attacks, validation, and the GDPR compliance tension
- Learned forgetting -- when and how to retire memories that no longer serve
Code companion¶
The working code for this chapter is in src/ch12/:
session_memory.py-- Context management with importance scoringlong_term_memory.py-- Persistent memory with worthiness filteringshared_memory.py-- Multi-agent state coordination
Get the full chapter¶
The complete chapter text is available in the book.