Memory gives agents the ability to retain and recall information across sessions, enabling personalized interactions, context continuity, and intelligent decision-making based on historical data.
Overview
The Memory primitive empowers agents with persistent storage and retrieval of information across multiple sessions and interactions. Unlike session-based state that exists only within a single conversation, memory provides long-term retention of facts, preferences, conversation history, and learned patterns. Memory is essential for:- Personalization: Remember user preferences, habits, and historical interactions
- Context Continuity: Maintain conversation context across multiple sessions
- Knowledge Accumulation: Build up domain knowledge over time
- Relationship Building: Create more natural, personalized user experiences
- Efficient Workflows: Avoid asking users to repeat information
- Pattern Recognition: Learn from past interactions to improve future responses
Automatic Storage
Store important information automatically or explicitly during agent execution
Semantic Retrieval
Query memories using natural language with vector-based semantic search
Scoped Memory
Organize memories by user, session, or custom namespaces for multi-tenant applications
Temporal Awareness
Memories include timestamps for time-based retrieval and context
How Memory Works
When you enable memory for an agent:- Storage: Agent stores important facts, preferences, and context during execution
- Indexing: Memories are indexed using vector embeddings for semantic search
- Retrieval: Agent automatically recalls relevant memories based on current context
- Integration: Retrieved memories are injected into agent context for informed responses
- Updates: Memories can be updated, deleted, or marked as outdated over time
- Scoping: Memories are isolated by namespace (user ID, workspace, etc.)
Privacy & Control: Memories are scoped per user/namespace and can be deleted at any time. Agentbase provides full GDPR compliance for memory management.
Memory Types
User Memory
Store user-specific preferences and information:Conversation Memory
Maintain conversation context and history:Knowledge Memory
Store domain knowledge and learned information:Code Examples
Basic Memory Usage
Retrieving Memories
Explicit Memory Storage
Querying Memories
Memory with Time Filters
Deleting Memories
Use Cases
1. Personalized Customer Support
Create support agents that remember customer history:2. Executive Assistant
Build assistants that remember user preferences and context:3. Learning Companion
Create educational agents that track progress:4. Sales Assistant
Remember prospect interactions and preferences:5. Health & Wellness Coach
Track user goals and progress:6. Research Assistant
Accumulate knowledge across research sessions:Best Practices
Memory Scope Design
User-Level Namespaces
User-Level Namespaces
Organization-Level Namespaces
Organization-Level Namespaces
Project-Level Namespaces
Project-Level Namespaces
Hierarchical Namespaces
Hierarchical Namespaces
Memory Storage Guidelines
Store Facts, Not Conversations
Store Facts, Not Conversations
Add Metadata for Context
Add Metadata for Context
Update Stale Information
Update Stale Information
Privacy and Compliance
Memory Retrieval Optimization
Limit Retrieved Memories
Limit Retrieved Memories
Use Specific Queries
Use Specific Queries
Filter by Category
Filter by Category
Integration with Other Primitives
With Sessions
Combine session state with long-term memory:With Multi-Agent Systems
Share knowledge across specialized agents:With RAG
Combine semantic memory with document retrieval:With Prompts
Guide memory usage with system prompts:Performance Considerations
Memory Retrieval Latency
- Cold Start: First memory query in a session: ~200-500ms
- Warm Cache: Subsequent queries: ~50-100ms
- Optimization: Limit retrieved memories to top 5-10 most relevant
Token Usage
Memories consume input tokens when injected into agent context:Storage Costs
- Keep memories concise and factual
- Delete outdated or irrelevant memories
- Implement retention policies for automatic cleanup
Troubleshooting
Agent Not Recalling Memories
Agent Not Recalling Memories
Problem: Agent doesn’t use stored memories in responsesSolutions:
- Verify memory is enabled with
enabled: true - Check namespace matches between storage and retrieval
- Ensure memories are relevant to current query (semantic match)
- Add guidance in system prompt to use memory
- Query memories manually to verify they exist
Irrelevant Memories Retrieved
Irrelevant Memories Retrieved
Problem: Agent retrieves memories that aren’t relevantSolutions:
- Make memory content more specific and detailed
- Add category metadata for filtering
- Use more specific queries when retrieving
- Reduce the number of memories retrieved
- Delete outdated or low-quality memories
Memory Namespace Confusion
Memory Namespace Confusion
Problem: Memories leaking between users or contextsSolutions:
- Always use unique, consistent namespace identifiers
- Include user ID or tenant ID in namespace
- Validate namespace before storage/retrieval
- Implement namespace access controls
Duplicate or Conflicting Memories
Duplicate or Conflicting Memories
Problem: Multiple similar memories causing confusionSolutions:
- Query existing memories before storing new ones
- Update existing memories instead of creating duplicates
- Implement deduplication logic
- Add timestamps to identify most recent information
Advanced Patterns
Confidence Scoring
Track confidence in stored information:Hierarchical Memory
Organize memories in hierarchies:Memory Decay
Implement time-based memory importance:Related Primitives
Sessions
Maintain conversation state within a single session
RAG
Retrieve information from document datastores
Multi-Agent
Share memory across specialized agents
Prompts
Guide agents on memory usage patterns
Additional Resources
API Reference
Complete memory API documentation
Privacy Guide
GDPR compliance and data handling
Best Practices
Memory optimization patterns