Skip to content

Chapter 3 of 8

Agent Memory and Knowledge

AI agents require memory to maintain context across interactions, learn from past experiences, recall user preferences, and avoid repeating mistakes. Memory is generally classified into several types: short-term memory, which is the active context window contents including the current conversation and recent tool results; long-term memory, which persists across sessions and includes user preferences, learned facts, and accumulated knowledge; episodic memory, which captures specific past events and interactions; semantic memory, which stores facts and concepts independent of specific episodes; and procedural memory, which holds learned workflows and successful step-by-step procedures. The context window serves as the agent's primary working memory but is limited in size and not persistent, creating the memory bottleneck problem: agents must selectively choose what information to keep, summarize, or retrieve on demand.

The memory lifecycle is governed by three core operations: write (storing new memories), read (retrieving relevant memories), and reflect (synthesizing and consolidating memories). The retrieval pipeline typically proceeds through query embedding, vector similarity search, reranking, filtering, context formatting, and finally injection into the prompt. Cosine similarity between memory embeddings is used to find stored memories most semantically similar to a query. Memory importance scoring assigns significance values so the agent can prioritize critical information, while memory decay mimics human forgetting by gradually reducing the priority of older memories. The recency-relevance tradeoff balances retrieving the most recent memories against the most semantically relevant ones.

Practical memory architectures draw from a rich design space. A memory stream is a chronological log of all observations and actions serving as raw data for retrieval and consolidation. Generative Agents research combined a memory stream with retrieval based on recency, importance, and relevance, plus reflection to form higher-level insights. Systems like MemGPT (now Letta) tier memory into main context, archival storage, and recall storage, inspired by operating system virtual memory. Other patterns include sliding window memory, hierarchical memory summarization at multiple levels of condensation, and hybrid memory architectures that combine context, retrieval, and parameter-based approaches. Memory pruning removes outdated or low-importance entries, deduplication merges redundant memories, and conflict resolution handles contradictions by preferring more recent or higher-confidence information.

All chapters
  1. 1Foundations of AI Agents
  2. 2Reasoning, Planning, and Tool Use
  3. 3Agent Memory and Knowledge
  4. 4Multi-Agent Systems and Inter-Agent Protocols
  5. 5Frameworks for Building Agents
  6. 6GitHub Copilot and AI Coding Tools
  7. 7Safety, Alignment, and Security
  8. 8Evaluation, Benchmarking, and Production Operations

Drill it

Reading is not remembering. These come from the AI Agents deck:

Q

What is a standalone AI agent?

An autonomous software system that perceives its environment, reasons about goals, and takes actions without continuous human intervention.

Q

What are the four core capabilities of an AI agent?

Perception (sensing environment), Reasoning (planning and deciding), Action (executing tasks), and Learning (improving over time).

Q

What distinguishes an AI agent from a simple chatbot?

An AI agent can autonomously plan, use tools, maintain state across interactions, and take multi-step actions, whereas a chatbot typically only responds to indi...

Q

What is the agent loop (observe-think-act)?

A cycle where the agent observes the environment, thinks/reasons about what to do, acts on that decision, then observes the result and repeats.