Skip to main content
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:
  1. Storage: Agent stores important facts, preferences, and context during execution
  2. Indexing: Memories are indexed using vector embeddings for semantic search
  3. Retrieval: Agent automatically recalls relevant memories based on current context
  4. Integration: Retrieved memories are injected into agent context for informed responses
  5. Updates: Memories can be updated, deleted, or marked as outdated over time
  6. 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

Memory Storage Guidelines

Be Specific: Store concrete, actionable information rather than vague generalizations. “User prefers meetings at 10am” is more useful than “User likes mornings.”

Privacy and Compliance

PII Handling: Be mindful of storing personally identifiable information (PII). Implement proper data retention policies and provide users with memory deletion capabilities.

Memory Retrieval Optimization

Integration with Other Primitives

With Sessions

Combine session state with long-term memory:
Learn more: Sessions Primitive

With Multi-Agent Systems

Share knowledge across specialized agents:
Learn more: Multi-Agent Primitive

With RAG

Combine semantic memory with document retrieval:
Learn more: RAG Primitive

With Prompts

Guide memory usage with system prompts:
Learn more: Prompts Primitive

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

Storage Pricing: Memory storage is included in your plan up to limits. See pricing page for details.
  • Keep memories concise and factual
  • Delete outdated or irrelevant memories
  • Implement retention policies for automatic cleanup

Troubleshooting

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
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
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
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:

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
Remember: Memory is most powerful when it stores specific, actionable facts rather than general information. Focus on what will make future interactions more personalized and efficient.