From First Principles to Production Systems
Introduction
- The Problem with “Just Use a Larger Context Window”
- What Agent Memory Actually Is
- How This Book Is Organized
- Prerequisites
Chapter 1: Why Agents Need Memory
- The Context Window Is Not Memory
- What Happens When Agents Forget
- Defining Agent Memory vs Related Concepts
- The Cost of Forgetting in Real Systems
Chapter 2: A Taxonomy of Agent Memory
- Working Memory and Short-Term State
- Episodic Memory for Interaction Histories
- Semantic Memory for Facts and Knowledge
- Procedural Memory for Skills and Patterns
- Entity, User, Task and Environmental Memory
- Shared Multi-Agent Memory
Chapter 3: The Memory Lifecycle from Capture to Retrieval
- Observing and Capturing Candidate Memories
- Deciding What Is Worth Remembering
- Extracting Facts, Entities and Relations
- Structuring and Enriching Raw Observations
- From Capture to Storage: The Memory Pipeline
Chapter 4: Representing Memories: Schemas and Data Structures
- Designing a Memory Schema
- Generating Embeddings for Semantic Search
- Importance, Confidence and Decay Scores
- Deduplication and Consolidation Strategies
- Temporal Versioning and History Tracking
- Forgetting Policies and Expiration
Chapter 5: Storage Foundations from Files to Databases
- In-Memory Structures and File-Based Storage
- SQLite with Full-Text Search (FTS5)
- PostgreSQL for Structured Memory at Scale
- Vector Indexes and Approximate Nearest Neighbor
- Document Stores, Key-Value Stores and Object Storage
- Graph Databases for Relational Memory
Chapter 6: Retrieval Systems for Finding What Matters
- Lexical Retrieval with BM25
- Vector Similarity Search Internals
- Hybrid Retrieval: Combining Lexical and Semantic
- Metadata Filtering and Constrained Search
- Reciprocal Rank Fusion and Multi-Signal Ranking
- Rerankers and Cross-Encoders
- Temporal and Graph-Based Retrieval
Chapter 7: Context Engineering for Injecting Memories into Prompts
- Token Budgets and Context Constraints
- Relevance vs Recency in Memory Selection
- Dynamic Context Assembly Strategies
- Hierarchical and Recursive Summarization
- Memory Scopes, Namespaces and Isolation
- Prompt Construction with Retrieved Memories
Chapter 8: Memory Architectures for Agent Types
- Memory for Tool-Using Agents
- Coding Agents and Repository-Aware Memory
- Research Agents and Long-Horizon Reasoning
- Personal Assistants and User-Centric Memory
- Multi-Agent Systems and Shared Memory
- Autonomous Workflows, Plans and Checkpoints
Chapter 9: Frameworks, Integrations and Interoperability
- Vendor-Independent Memory Architecture
- Integrating with Model APIs and Tool Calling
- The Model Context Protocol (MCP) for Memory Tools
- Plugging into Agent Frameworks Without Lock-In
- Designing a Memory Service API
Chapter 10: Correctness, Reliability and Consistency
- Stale Memories and Knowledge Drift
- Contradictions and Conflicting Information
- Provenance, Attribution and Trust
- Deterministic vs Probabilistic Retrieval Guarantees
- Concurrency, Race Conditions and Consistency
- Backups, Migrations and Disaster Recovery
Chapter 11: Security, Privacy and Access Control
- Access Control and Tenant Isolation
- Encryption at Rest and in Transit
- Handling Secrets and Sensitive Data
- Prompt Injection Through Stored Memories
- Memory Poisoning and Malicious Content
- Deletion, Retention and Auditability
Chapter 12: Evaluating Agent Memory
- Retrieval Metrics: Precision, Recall and Ranking
- Task-Success Measurement with Memory
- Long-Horizon Benchmarks and Stability Tests
- Cost, Latency and Efficiency Metrics
- Ablation Testing and Causal Attribution
- Building Repeatable Evaluation Pipelines
Chapter 13: Observability, Debugging and Diagnostics
- Memory Traces and Retrieval Logs
- Ranking Explanations and Decision Auditing
- Token Accounting and Context Visibility
- Interactive Memory Inspection Tools
- Diagnosing Common Failure Modes
Chapter 14: Performance, Cost and Scale Engineering
- Embedding Costs and Optimization Strategies
- Query Latency and Indexing Performance
- Storage Growth Modeling and Cost Projections
- Caching, Batching and Throughput
- Partitioning, Sharding and Replication
- Token Cost Engineering
Chapter 15: Building a Production Memory System via a Staged Roadmap
- Stage 1: Minimal Memory with Conversation History
- Stage 2: Persistent Structured Memory in SQLite
- Stage 3: Lexical and Semantic Retrieval with Hybrid Ranking
- Stage 4: Consolidation, Forgetting and Temporal Reasoning
- Stage 5: Provenance, Evaluation, Observability and Security
- Stage 6: Scalable Multi-Agent Production Architecture
Conclusion: The Engineering Discipline of Agent Memory
- What We Know
- What Remains Uncertain
- When Simple Is Better
- The Path Forward