Memory System Overview
TheMemory
class serves as a centralized module for managing different types of memory and respects the specific data formats and logic established in the original application design for handling chat history.
Key Features
- Session Memory: Full conversation history storage and retrieval
- Summary Memory: Automatic conversation summarization
- User Analysis Memory: Dynamic user profile building and trait analysis
- Flexible Storage: Support for various storage backends (SQLite, etc.)
- Context Injection: Automatic injection of relevant memory into system prompts
Setting Up Memory with SQLite
Here’s how to set up memory with SQLite storage:Memory Configuration Options
Basic Memory Setup
Full Memory Configuration
Memory Types Explained
Full Session Memory
Stores complete conversation history for context retrieval:Summary Memory
Automatically generates and maintains conversation summaries:User Analysis Memory
Builds and maintains user profiles based on interactions:Using Memory in Task Execution
Once configured, memory automatically integrates with your agent:- Inject relevant user profile information into the system prompt
- Include conversation summaries for context
- Provide full conversation history if needed
- Update user profiles based on the interaction
Memory Management Methods
Accessing Memory Data
Memory Configuration in Agent
Advanced Memory Features
Custom User Profile Schema
Dynamic User Profile Generation
Memory with Limited History
Best Practices
- Choose Appropriate Memory Types: Enable only the memory types you need to optimize performance
- Set Session IDs: Always provide meaningful session IDs for proper memory isolation
- User ID Management: Use consistent user IDs for proper profile building
- Model Provider: Provide a model provider for summary and analysis features
- Storage Backend: Choose appropriate storage backend based on your deployment needs
- Memory Limits: Use
num_last_messages
to prevent memory from growing too large - Debug Mode: Enable debug mode during development to understand memory behavior
- Tool Results: Consider whether to include tool call results in memory based on your use case