Skip to content

Memory

Memory is a pattern where an agent stores information from past interactions and retrieves it when relevant to current tasks. Without memory, every conversation starts from scratch — the agent has no knowledge of previous interactions, decisions, or user preferences. With memory, the agent builds up context over time, becoming more useful and personalized with each interaction.

Memory isn’t one of Andrew Ng’s four agentic design patterns; the playbook adds it because any agent that works across sessions depends on it. Memory in AI agents borrows its terms from human memory, but it’s implemented through a combination of databases, embeddings, and retrieval mechanisms.

A stateless agent is like a colleague with amnesia — you have to re-explain everything every time. Memory transforms agents from one-shot tools into persistent collaborators that accumulate knowledge, learn preferences, and build on past work.

The Generative Agents paper (Park et al., 2023) gave 25 simulated characters a memory: a record of everything they experienced, summarized over time into reflections and retrieved when they planned. Told only that one character wanted to throw a Valentine’s Day party, the characters spread the invitations over two days, made new acquaintances, asked each other to the party, and turned up together at the right time. The authors’ tests showed that observation, planning and reflection each contributed critically to how believable the characters were.

Agent memory systems typically implement multiple types of memory:

The current conversation history and any documents loaded into the context window. This is what the agent can “see” right now. It’s limited by the model’s context window size.

Information stored outside the context window in a database or file system, retrieved when relevant. This includes:

  • Episodic memory — Records of specific past interactions (“Last Tuesday, the user asked about exchange policies and preferred email communication”).
  • Semantic memory — General knowledge extracted from interactions (“This user prefers concise responses” or “This customer is a VIP account”).
  • Procedural memory — Learned workflows and procedures (“When processing exchanges for this company, always check the VIP discount table first”).

When the agent starts a new task, it queries long-term memory for relevant context. Common retrieval methods include:

  • Keyword/semantic search — Finding memories related to the current topic using embeddings
  • Recency weighting — Prioritizing recent memories over older ones
  • Importance scoring — Surfacing memories that were flagged as significant
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Current │────▸│ Retrieval │────▸│ Enriched │
│ Task │ │ (search │ │ Context │
│ │ │ memory) │ │ │
└─────────────┘ └──────┬───────┘ └─────────────┘
│
┌──────▼───────┐
│ Long-term │
│ Memory Store │
└──────────────┘

A customer contacts support about an exchange. The agent retrieves from memory:

  • Episodic: “This customer contacted us 3 weeks ago about a defective Blue Widget. We sent a replacement. They mentioned they prefer phone updates over email.”
  • Semantic: “This customer has been with us for 4 years and has a lifetime value of $2,400. They’re in the VIP tier.”
  • Procedural: “VIP customers get free expedited shipping on exchanges and a courtesy discount on the replacement item.”

Armed with this context, the agent provides personalized service without the customer having to repeat their history.

A coding agent with memory:

  • Remembers the project’s architecture decisions from previous sessions
  • Recalls that the user prefers TypeScript over JavaScript and tabs over spaces
  • Knows which test framework the project uses without being told each time
  • Stores debugging insights (“The authentication module has a known issue with token refresh timing”)

Claude Code’s CLAUDE.md files and auto memory are a practical implementation of this pattern: instructions you write, and notes Claude writes itself, are loaded at the start of every session (How Claude remembers your project, accessed 2026-10-24).

  • Customer-facing systems where personalization improves the experience
  • Long-running projects where context accumulates over time
  • Agents that need to learn from mistakes (paired with Reflection)
  • Any workflow where repeating context to the agent is a friction point