Long-term memory
📖 3 min readUpdated 2026-04-19
Long-term memory is everything the agent remembers across sessions. Without it, every conversation starts from zero. With it, the agent builds relationship, knows preferences, and remembers what worked.
What belongs in long-term
- User profile and preferences
- Past decisions that should inform future ones
- Accumulated knowledge about the domain
- Documented patterns the agent has learned
- Facts the user has shared once that should persist
Storage models
Key-value store
Structured facts: user_name, preferences, settings. Fast, bounded, simple.
Vector store
Embeddings of past conversations or artifacts. Retrieve by semantic similarity at query time.
Document store
Plain-text notes the agent writes to itself. Reviewed or summarized at intervals.
Graph
Entities and relationships (people, projects, decisions, dates). Query by traversal.
What and when to write
Not every utterance needs persisted. Good patterns:
- Explicit "remember this" requests from the user
- Significant decisions or preferences ("I'm allergic to peanuts")
- Recurring patterns ("You always ask for X context")
- End-of-session summaries of what happened
What not to write
- Every message verbatim (storage bloat + retrieval noise)
- Sensitive information without user consent
- Transient context that doesn't matter tomorrow
The retrieval problem
Long-term memory is only useful if the agent retrieves the right piece at the right moment. Patterns:
- Retrieve on session start (load the user profile)
- Retrieve on demand (agent tool:
recall_about(topic))
- Retrieve automatically on similarity match (vector search at each turn)
The staleness problem
User's preferences change. Facts become outdated. Have explicit update and expiry semantics, not just append-only.