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 up2. Conversation Summary
Store: LLM-generated summary of conversation
Best for: Long conversations
Trade-off: Loses detail, keeps gistfrom langchain.memory import ConversationSummaryMemory
memory = ConversationSummaryMemory(llm=llm)
# Automatically summarizes older messages3. 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 knowledgeAlice --[works_at]--> Acme Corp
Alice --[leads]--> Project X
Project X --[uses]--> FastAPI
Project X --[deadline]--> 2026-03-155. 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 store6. Sliding Window + Summary
Recent: Last 10 messages (full detail)
Older: Summarized into 1-2 paragraphs
Ancient: Key facts onlyMemory 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
- Let the agent manage its own memory — Don't hard-code what to remember
- Separate facts from opinions — Store verified facts, not guesses
- Add timestamps — Memory without time context becomes stale
- Implement forgetting — Remove outdated or contradicted memories
- 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.