Overview
What is Memory?
Memory gives your agents the ability to remember. Without memory, every conversation starts fresh - your agent doesn’t remember what you talked about before or who you are. With memory, your agents can:- Remember conversations - Reference previous messages and maintain context
- Learn about users - Understand preferences, expertise level, and communication style
- Improve over time - Build a complete picture of each user across all interactions
- Reduce repetition - Never ask for the same information twice
How Memory Works
Memory works in two phases - before and after each conversation: Before Each Conversation:- Loads the user’s profile (if you’re using user analysis memory)
- Retrieves the conversation summary (if you’re using summary memory)
- Pulls up previous messages (if you’re using conversation memory)
- Gives all this context to your agent automatically
- Saves the new messages to history
- Updates the conversation summary
- Analyzes what the agent learned about the user
- Stores everything for next time
Attributes
TheMemory class provides the following key attributes:
Choosing Right Memory Types
What is The Selection Criteria?
Choose memory types based on your specific needs:| Memory Type | When to Use | Requirements |
|---|---|---|
| Conversation Memory | Customer support, tutoring, detailed conversations | session_id |
| Summary Memory | Long conversations, cost reduction | session_id, model |
| User Analysis Memory | Personalization, user preferences | user_id, model |
Making Combination of Memory
You can use one type or combine all three for the most powerful memory system:Use Case for Conversation Memory
- Customer Support: Maintain context across support tickets
- Tutoring: Remember what topics have been covered
- Long Conversations: Keep track of detailed discussions
- Debugging Sessions: Remember error states and solutions
Use Case for Summary Memory
- Long Sessions: Reduce token costs for very long conversations
- Meeting Notes: Automatically summarize key points
- Documentation: Create evolving summaries of complex topics
- Cost Optimization: Maintain context without full history
Use Case for User Analysis Memory
- Personalization: Adapt responses to user preferences
- Learning Systems: Track user progress and expertise
- Customer Profiles: Build comprehensive user understanding
- Adaptive Interfaces: Customize experience based on user traits
Memory Types
Conversation Memory
What is Conversation Memory?
Conversation Memory stores the complete chat history for a session, allowing your agent to reference previous messages and maintain context throughout the conversation.Usage
Params
full_session_memory: bool- Enable/disable conversation memorysession_id: str- Required identifier for the sessionnum_last_messages: int- Optional limit on conversation historyfeed_tool_call_results: bool- Include/exclude tool calls from memory
Summary Memory
What is Summary Memory?
Summary Memory maintains an evolving, condensed summary of key conversation points, reducing costs while preserving important context.Usage
Params
summary_memory: bool- Enable/disable summary generationsession_id: str- Required identifier for the sessionmodel: str- Required model for generating summaries
User Analysis Memory
What is User Analysis Memory?
User Analysis Memory learns about users across all conversations, building comprehensive profiles that enable personalization and adaptive responses.Usage
Params
user_analysis_memory: bool- Enable/disable user learninguser_id: str- Required identifier for the usermodel: str- Required model for analyzing user traitsuser_profile_schema: BaseModel- Optional custom profile schemadynamic_user_profile: bool- Let agent create custom fieldsuser_memory_mode: str- ‘update’ (default) or ‘replace’ mode
Storage Options
InMemoryStorage
Usage
Params
max_sessions: int- Optional limit on stored sessions (LRU cache)max_profiles: int- Optional limit on stored profiles (LRU cache)
JSONStorage
Usage
Params
directory_path: str- Path to directory for JSON filespretty_print: bool- Format JSON for readability (default: True)
SqliteStorage
Usage
Params
sessions_table_name: str- Name of sessions tableprofiles_table_name: str- Name of profiles tabledb_file: str- Path to SQLite file (None for in-memory)
PostgresStorage
Usage
Params
sessions_table_name: str- Name of sessions tableprofiles_table_name: str- Name of profiles tabledb_url: str- PostgreSQL connection URLschema: str- Database schema (default: “public”)
RedisStorage
Usage
Params
prefix: str- Key prefix for namespacinghost: str- Redis server hostname (default: “localhost”)port: int- Redis server port (default: 6379)db: int- Redis database number (default: 0)password: str- Optional password for authenticationssl: bool- Use SSL connection (default: False)expire: int- Optional TTL in seconds for keys
Mem0Storage
Usage
Params
api_key: str- Mem0 Platform API key (for hosted service)org_id: str- Organization ID for Mem0 Platformproject_id: str- Project ID for Mem0 Platformlocal_config: dict- Configuration for Open Source Mem0namespace: str- Application namespace (default: “upsonic”)infer: bool- Enable LLM-based inference (default: False)custom_categories: list- Additional custom categoriesenable_caching: bool- Enable ID caching (default: True)cache_ttl: int- Cache time-to-live in seconds (default: 300)
MongoStorage
Usage
Params
db_url: str- MongoDB connection stringdatabase_name: str- Name of the databasesessions_collection_name: str- Name of sessions collection (default: “interaction_sessions”)profiles_collection_name: str- Name of profiles collection (default: “user_profiles”)
Examples
Basic Memory Example
About Example Scenario
This example demonstrates a customer support agent that remembers conversations and learns about users across multiple sessions. The agent will maintain context within each support session and build a profile of each customer for personalized service.Memory Configuration
Full Code
- Remembers the conversation - References previous login issues
- Learns about the user - Builds a profile of the customer’s technical level and preferences
- Maintains context - Knows about password reset attempts from earlier in the session
- Persists across sessions - Recognizes the customer in a new session and recalls their history

