chapter four

4 Memory: What your agent remembers shapes what it becomes

 

This chapter covers

  • Diagnosing production amnesia as the critical infrastructure gap
  • Building Hierarchical Retention for multi-tier memory management
  • Implementing RAG for knowledge retrieval
  • Designing Failure Journals that turn errors into learning assets
  • Upgrading Argus with cross-session memory
"Experience is not what happens to you, but what you do with what happens to you."

—Aldous Huxley

Session 3 was going well. The agent was refactoring an authentication service, migrating from a monolithic auth.py to three separate modules, and it had just discovered something important: the UserSession model had a circular import dependency with PermissionCache. You could not move one without the other. The agent wrote a detailed analysis: the dependency traced through four files, the only clean solution was to extract a shared types.py module first, and attempting to move UserSession alone would break 43 test cases. That analysis cost 12,000 tokens of careful reasoning. It was correct.

4.1 What is memory? State, persistence, and knowledge across sessions

4.1.1 The memory hierarchy analogy

4.1.2 The memory lifecycle

4.1.3 How production agents handle memory today

4.1.4 Measuring memory quality

4.2 Pattern: Hierarchical Retention

4.2.1 Three tiers and the eviction question

4.2.2 In production: Claude Code's six-tier hierarchy

4.2.3 Building it

4.2.4 Before and after: What eviction looks like

4.2.5 Argus integration

4.2.6 When it breaks

4.3 Pattern: RAG (Retrieval-Augmented Generation)

4.3.1 Three pipelines: Index, retrieve, generate

4.3.2 In production: Claude Code's tool-based retrieval

4.3.3 Building it

4.3.4 Production vector database landscape

4.3.5 When it breaks

4.4 Pattern: Progress tracking

4.4.1 The checkpoint chain

4.4.2 In Production: Three approaches compared

4.4.3 Building it

4.4.4 When it breaks

4.5 Pattern: Failure journals

4.5.1 Fix vs. heuristic: Two levels of learning

4.5.2 In Production: Claude Code's auto memory as implicit failure journal

4.5.3 Building it

4.5.4 The ExpeL evolution

4.5.5 When it breaks