Skip to main content

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:
  1. Loads the user’s profile (if you’re using user analysis memory)
  2. Retrieves the conversation summary (if you’re using summary memory)
  3. Pulls up previous messages (if you’re using conversation memory)
  4. Gives all this context to your agent automatically
After Each Conversation:
  1. Saves the new messages to history
  2. Updates the conversation summary
  3. Analyzes what the agent learned about the user
  4. Stores everything for next time
You don’t have to do anything - memory handles it all automatically.

Attributes

The Memory class provides the following key attributes:

Choosing Right Memory Types

What is The Selection Criteria?

Choose memory types based on your specific needs:

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 memory
  • session_id: str - Required identifier for the session
  • num_last_messages: int - Optional limit on conversation history
  • feed_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 generation
  • session_id: str - Required identifier for the session
  • model: 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 learning
  • user_id: str - Required identifier for the user
  • model: str - Required model for analyzing user traits
  • user_profile_schema: BaseModel - Optional custom profile schema
  • dynamic_user_profile: bool - Let agent create custom fields
  • user_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 files
  • pretty_print: bool - Format JSON for readability (default: True)

SqliteStorage

Usage

Params

  • sessions_table_name: str - Name of sessions table
  • profiles_table_name: str - Name of profiles table
  • db_file: str - Path to SQLite file (None for in-memory)

PostgresStorage

Usage

Params

  • sessions_table_name: str - Name of sessions table
  • profiles_table_name: str - Name of profiles table
  • db_url: str - PostgreSQL connection URL
  • schema: str - Database schema (default: “public”)

RedisStorage

Usage

Params

  • prefix: str - Key prefix for namespacing
  • host: 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 authentication
  • ssl: 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 Platform
  • project_id: str - Project ID for Mem0 Platform
  • local_config: dict - Configuration for Open Source Mem0
  • namespace: str - Application namespace (default: “upsonic”)
  • infer: bool - Enable LLM-based inference (default: False)
  • custom_categories: list - Additional custom categories
  • enable_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 string
  • database_name: str - Name of the database
  • sessions_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

This example shows how the agent:
  1. Remembers the conversation - References previous login issues
  2. Learns about the user - Builds a profile of the customer’s technical level and preferences
  3. Maintains context - Knows about password reset attempts from earlier in the session
  4. Persists across sessions - Recognizes the customer in a new session and recalls their history