PromptsApr 8, 2026·3 min read

AI Agent Memory Patterns — Build Agents That Remember

Design patterns for adding persistent memory to AI agents. Covers conversation memory, entity extraction, knowledge graphs, tiered memory, and memory management strategies.

AG
Agent Toolkit · Community
Quick Use

Use it first, then decide how deep to go

This block should tell both the user and the agent what to copy, install, and apply first.

Simplest Memory: Conversation Buffer

from langchain.memory import ConversationBufferMemory

memory = ConversationBufferMemory()
memory.save_context({"input": "My name is Alice"}, {"output": "Hello Alice!"})
memory.save_context({"input": "I like Python"}, {"output": "Python is great!"})

# Later...
memory.load_memory_variables({})
# Returns full conversation history

What are Agent Memory Patterns?

Memory patterns define how AI agents remember information across conversations and sessions. Without memory, every conversation starts from scratch. With the right memory architecture, agents can remember user preferences, track ongoing tasks, accumulate knowledge, and provide personalized responses over time.

Answer-Ready: Agent memory patterns enable AI agents to remember across conversations. Key patterns: conversation buffer, summary memory, entity extraction, knowledge graphs, and tiered memory (core/recall/archival). Used by Mem0, Letta, Zep, and Claude Code's own memory system. Essential for production agents.

Best for: Developers building AI agents that need to remember. Works with: Any LLM, LangChain, LlamaIndex, custom agent frameworks.

Memory Patterns

1. Conversation Buffer

Store: Full conversation history
Best for: Short conversations
Limit: Context window fills up

2. Conversation Summary

Store: LLM-generated summary of conversation
Best for: Long conversations
Trade-off: Loses detail, keeps gist
from langchain.memory import ConversationSummaryMemory

memory = ConversationSummaryMemory(llm=llm)
# Automatically summarizes older messages

3. Entity Memory

Store: Facts about entities (people, projects, tools)
Best for: CRM-like agents, personal assistants
# Extracts and stores entity facts
entities = {
    "Alice": ["Python developer", "works at Acme", "prefers dark mode"],
    "Project X": ["deadline March 15", "uses FastAPI", "3 team members"],
}

4. Knowledge Graph Memory

Store: Entity relationships as graph
Best for: Complex domain knowledge
Alice --[works_at]--> Acme Corp
Alice --[leads]--> Project X
Project X --[uses]--> FastAPI
Project X --[deadline]--> 2026-03-15

5. Tiered Memory (Letta/MemGPT Pattern)

Core Memory (always in context):
  - User name, preferences, current task
  - ~2K tokens, editable by agent

Recall Memory (searchable):
  - Full conversation history
  - Vector-indexed, retrieved on demand

Archival Memory (long-term):
  - Facts, documents, accumulated knowledge
  - Unlimited size, agent decides what to store

6. Sliding Window + Summary

Recent: Last 10 messages (full detail)
Older: Summarized into 1-2 paragraphs
Ancient: Key facts only

Memory Tools

Tool Pattern Best For
Mem0 Entity + vector Simple persistent memory
Letta (MemGPT) Tiered (core/recall/archival) Self-managing memory
Zep Session + entity + graph Production chat apps
Graphiti Knowledge graph Complex relationships
LangChain Memory All patterns Framework integration

Implementation Guide

Step 1: Choose Your Pattern

Short conversations?Buffer
Long single-session?Summary
Multi-session personal?Entity + Vector
Complex domain?Knowledge Graph
Full autonomy?Tiered (Letta-style)

Step 2: Storage Backend

Backend Best For
In-memory Prototyping
SQLite Single-user apps
PostgreSQL + pgvector Production
Redis High-throughput
Vector DB (Qdrant, Pinecone) Semantic retrieval

Step 3: Memory Management

# Agent decides what to remember
def should_memorize(message):
    # Memorize: preferences, facts, decisions
    # Skip: greetings, confirmations, small talk
    triggers = ["my name", "i prefer", "remember", "important"]
    return any(t in message.lower() for t in triggers)

Best Practices

  1. Let the agent manage its own memory — Don't hard-code what to remember
  2. Separate facts from opinions — Store verified facts, not guesses
  3. Add timestamps — Memory without time context becomes stale
  4. Implement forgetting — Remove outdated or contradicted memories
  5. Test memory retrieval — Wrong memory is worse than no memory

FAQ

Q: Does Claude Code have built-in memory? A: Yes, Claude Code's auto-memory system stores user/project/feedback memories in ~/.claude/projects/*/memory/. It follows the entity + file-based pattern.

Q: Which pattern should I start with? A: Start with conversation buffer. Add summary when context fills up. Add entity extraction when you need cross-session memory.

Q: How do I prevent memory conflicts? A: Newer information overrides older. Always check timestamps. Let the agent update or delete stale memories.

🙏

Source & Thanks

References:

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets