Skip to content
Agentic AI for serious engineers
Part IV · Advanced
12 ·2026-03-25 ·2 min

Memory Management

Memory management for production agents: session memory, long-term learning, multi-agent coordination, and memory security.

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_memory/:

  • session_memory.py — Context management with importance scoring
  • long_term_memory.py — Persistent memory with worthiness filtering
  • shared_memory.py — Multi-agent state coordination

Get the full chapter

The complete chapter text is available in the book.

Get the book on Amazon