Memory and State
elizaOS provides a sophisticated memory system for storing conversational context, documents, and agent experiences. The Memory system handles long-term storage, while State represents the ephemeral context for a single interaction.Memory System
Memory Structure
Memory Types
Memory Type Details
Memory Type Details
MESSAGE: Standard conversational messages
- User messages
- Agent responses
- System messages
- Most common type
- Knowledge base articles
- Reference documentation
- Policy documents
- Imported files
- Auto-generated from DOCUMENT memories
- ~1000 token chunks
- Used for semantic search
- Links back to parent document
- User profiles
- Agent descriptions
- Entity summaries
- Relationship context
- Task definitions
- Approval requests
- Custom structured data
Memory Scope
Creating Memories
Basic Memory Creation
Memory with Attachments
Document Memory
Searching Memories
Semantic Search
Use vector embeddings for semantic similarity:Recent Messages
Filtered Search
Memory Metadata
Rich metadata for context and filtering:Using Metadata
Embeddings
Vector embeddings enable semantic search.Automatic Embedding
Embeddings are generated asynchronously:Manual Embedding
Generate embedding immediately:Queue Embedding
State Composition
State is the ephemeral context for a single interaction, composed from memories and providers.State Structure
Composing State
State with Specific Providers
Skip Cache
Providers
Providers inject dynamic context into state.Provider Types
Static Providers: Always includedProvider Ordering
Provider Results
Advanced Memory
The advanced memory plugin adds summarization and long-term memory.Enabling Advanced Memory
Features
Conversation Summarization- Automatically summarizes conversations
- Triggered periodically or on long conversations
- Summaries stored as memories
- Used to maintain context over long interactions
- Extracts important facts from conversations
- Stores as structured memories
- Retrieved when relevant
- Builds agent’s knowledge base
- Provides summaries of past conversations
- Injected into state automatically
- Helps maintain long-term context
Advanced Memory Schema
Memory Best Practices
Memory management guidelines
Memory management guidelines
Performance
-
Use semantic search efficiently
- Adjust match_threshold (0.7-0.9 typical)
- Limit match_count to what you need
- Use unique flag to deduplicate
-
Queue embeddings for bulk operations
-
Cache state appropriately
- State cache is automatic (200 entry LRU)
- Don’t compose state multiple times for same message
- Use skipCache sparingly
-
Manage conversation length
- Adjust based on token budget
- Use summarization for long conversations
- Consider conversation length vs. quality tradeoff
Organization
-
Use appropriate memory types
- MESSAGE for conversations
- DOCUMENT for knowledge base
- FRAGMENT for searchable chunks
- CUSTOM for specialized data
-
Scope memories correctly
- Use “private” for agent-specific notes
- Use “shared” for collaborative context
- Use “room” for conversation-specific data
-
Structure metadata
- Include platform context
- Add session information
- Store sender details
- Enable filtering and analysis
-
Organize knowledge
- Split large documents into focused files
- Use clear, descriptive titles
- Update when information changes
- Remove outdated content
Security
-
Respect privacy
- Use private scope for sensitive data
- Set agentId for agent-private memories
- Implement access controls in custom adapters
-
Sanitize content
- Use pre-evaluators for input validation
- Redact secrets from memory content
- Filter inappropriate content
-
Manage retention
- Implement memory expiration if needed
- Archive old conversations
- Comply with data retention policies
Next Steps
Runtime
Runtime memory operations
Providers
Building context providers
Database
Custom database adapters
Advanced Memory
Using advanced memory features