Skip to main content

Memory Architecture Overview

In elizaOS, memory and state management are core responsibilities of the AgentRuntime. The system provides a unified API for creating, storing, retrieving, and searching memories, enabling agents to maintain context and learn from interactions. For runtime details, see Runtime and Lifecycle and Runtime Core.

Core Memory Concepts

Memory Interface

Every piece of information an agent processes becomes a Memory:

Memory Lifecycle

1. Creation

2. Storage

Memories are persisted through the IDatabaseAdapter:

3. Retrieval

Context Management

Context Window

The context window determines how much information the agent considers:

Context Selection Strategies

Recency-Based

Most recent messages are most relevant:

Importance-Based

Prioritize important memories:

Hybrid Approach

Combine recent and important:

State Composition

State composition brings together memories and provider data:

Memory Types

Short-term Memory

Working memory for immediate tasks:

Long-term Memory

Persistent storage of important information:

Knowledge Memory

Static and dynamic knowledge:

Memory Operations

Creating Memories

Best practices for memory creation:

Retrieving Memories

Efficient retrieval patterns:

Searching Memories

Advanced search capabilities:

Embeddings and Vectors

Embedding Generation

How and when embeddings are created:
Efficient similarity search:

State Management

State Structure

The complete state object:

State Updates

Managing state changes:

Performance Optimization

Memory Pruning

Strategies for managing memory size:

Caching Strategies

Multi-level caching for performance:

Database Optimization

Query optimization techniques:

Advanced Patterns

Memory Networks

Building relationships between memories:

Temporal Patterns

Time-aware memory retrieval:

Multi-agent Memory

Shared memory spaces between agents:

Best Practices

  1. Always provide embeddings: Pre-compute embeddings when creating memories for better search performance
  2. Use appropriate retrieval methods: Semantic search for meaning, recency for context, filters for precision
  3. Implement memory hygiene: Regular pruning and consolidation to maintain performance
  4. Cache strategically: Multi-level caching for frequently accessed memories
  5. Batch operations: Process multiple memories together when possible
  6. Index appropriately: Create indexes for common query patterns
  7. Monitor memory growth: Track memory usage and implement limits
  8. Preserve important memories: Mark and protect critical information from pruning
  9. Version memory schemas: Plan for memory structure evolution
  10. Test retrieval accuracy: Regularly evaluate search relevance

Troubleshooting

Common Issues

Memory Search Not Finding Expected Results

Memory Leaks

See Also

Character Interface

Define your agent’s character configuration

Personality & Behavior

Craft unique agent personalities

Runtime & Lifecycle

Learn how memory integrates with the runtime

Plugin Development

Build providers that contribute to state