Store facts across sessions so the agent remembers context over time.
Adding persistent memory transforms agents from stateless responders into systems that can maintain context and relationships across sessions.
Without Memory With Memory
────────────── ─────────────
Session 1: Session 1:
"I'm Alex" "I'm Alex" → Saved
"I love pizza" "I love pizza" → Saved
Session 2: Session 2:
"What's my name?" "What's my name?"
"I don't know" "Alex!" ✓
┌─────────────────────────────────┐
│ Agent Session │
├─────────────────────────────────┤
│ System Prompt │
│ + Loaded Memories │
│ + saveMemory Tool │
└────────┬────────────────────────┘
│
↓
┌─────────────────────────────────┐
│ Memory Manager │
├─────────────────────────────────┤
│ • Load from storage │
│ • Save to storage │
│ • Format for prompt │
└────────┬────────────────────────┘
│
↓
┌─────────────────────────────────┐
│ Persistent Storage │
│ (agent-memory.json) │
└─────────────────────────────────┘
1. Load agent-memory.json
2. Extract facts and preferences
3. Add to system prompt
4. Agent "remembers" past information
User shares information
↓
Agent recognizes important fact
↓
Agent calls saveMemory()
↓
Saved to JSON file
↓
Available in future sessions
Facts: General information
{
"memories": [
{
"type": "fact",
"key": "user_name",
"value": "Alex",
"source": "user",
"timestamp": "2025-10-29T11:22:57.372Z"
}
]
}
Preferences:
{
"memories": [
{
"type": "preference",
"key": "favorite_food",
"value": "pizza",
"source": "user",
"timestamp": "2025-10-29T11:22:58.022Z"
}
]
}
Base Prompt:
"You are a helpful assistant."
Enhanced with Memory:
"You are a helpful assistant with long-term memory.
=== LONG-TERM MEMORY ===
Known Facts:
- User's name is Alex
- User loves pizza"
Agent decides when to save:
User: "My favorite color is blue"
↓
Agent: "I should remember this"
↓
Calls: saveMemory(type="preference", key="color", content="blue")
Personal Assistant
Customer Service
Learning Tutor
Healthcare Assistant
Store specific events and conversations:
- "On 2025-01-15, user asked about Python"
- "User struggled with async concepts"
Store facts and knowledge:
- "User is a software engineer"
- "User prefers TypeScript over JavaScript"
Store how-to information:
- "User's workflow: design → code → test"
- "User's preferred tools: VS Code, Git"
Problem: Too many memories slow down agent Solution:
Problem: "User likes pizza" vs "User is vegan" Solution:
Problem: Sensitive information in memory Solution:
Memory survives:
Memories enhance system prompt:
Prompt = Base + Memories + User Input
Agent decides what to remember:
Important? → Save
Trivial? → Ignore
1. Stateless → Each interaction independent
2. Session memory → Remember during conversation
3. Persistent memory → Remember across sessions
4. Distributed memory → Share across instances
5. Semantic search → Find relevant memories
Feature Simple Agent Memory Agent
─────────────────── ───────────── ──────────────
Remembers names ✗ ✓
Recalls preferences ✗ ✓
Personalization ✗ ✓
Context continuity ✗ ✓
Cross-session state ✗ ✓
Memory transforms agents from tools into assistants. They can build relationships, provide personalized experiences, and maintain context over time.
This is essential for production AI agent systems.