What is Memory?
Memory in Upsonic is a sophisticated system that allows your AI agents to remember and learn from previous interactions. Just like humans, agents need memory to provide personalized, contextual responses and maintain continuity across conversations. The Memory system provides three main types of memory capabilities:- Full Session Memory: Stores complete conversation history for context-aware responses
- Summary Memory: Maintains evolving summaries of conversations for long-term understanding
- User Analysis Memory: Builds persistent user profiles based on interaction patterns
Core Principles For Memory
When implementing Memory in your agents, ensure you understand these key concepts:- Storage Providers: Choose the right storage backend (in-memory, JSON, PostgreSQL, MongoDB, Redis, SQLite) for your use case
- Memory Types: Enable only the memory types you need to balance performance and functionality
- Session Management: Properly manage session IDs and user IDs for memory persistence
- Context Injection: Memory automatically injects relevant context into your agent’s prompts
Memory Configuration Options
The Memory system offers flexible configuration to suit different requirements: Memory Types:full_session_memory: Stores complete chat historysummary_memory: Maintains conversation summariesuser_analysis_memory: Builds user profiles
InMemoryStorage: Fast, ephemeral storage for developmentJSONStorage: File-based storage for simple applicationsPostgresStorage: Production-grade relational database storageMongoStorage: Scalable NoSQL storageRedisStorage: High-performance in-memory storageSqliteStorage: Lightweight local database storage
Let’s Create an Agent with Memory Capabilities
In this example, we’ll create an agent that remembers user preferences and maintains conversation context across multiple interactions.Advanced Memory Configuration
Using Different Storage Providers
Custom User Profile Schemas
You can define custom user profile schemas to structure how your agent learns about users:- Structured data collection for specific use cases
- Type-safe user profile management
- Better control over what information is tracked
- Easier integration with analytics and reporting systems
Memory with Model Provider
Memory Best Practices
1. Choose the Right Storage Provider
- Development/Testing: Use
InMemoryStoragefor fast iteration - Simple Applications: Use
JSONStoragefor file-based persistence - Production Web Apps: Use
PostgresStorageorMongoStoragefor scalability - High-Performance: Use
RedisStoragefor caching and speed
2. Configure Memory Types Appropriately
- Full Session Memory: Enable for chatbots and support agents
- Summary Memory: Use for long conversations to maintain context
- User Analysis Memory: Essential for personalized experiences
3. Manage Session Lifecycles
4. Monitor Memory Usage
Memory in Multi-Agent Teams
Memory can be shared across multiple agents in a team, allowing all agents to access the same conversation history and context:- All agents have access to the complete conversation history
- Context is preserved across different agent interactions
- Team coordination is improved through shared understanding
- User preferences and patterns are available to all team members
Troubleshooting Memory Issues
Common Problems and Solutions
-
Memory Not Persisting:
- Ensure storage provider is properly connected
- Check that session_id and user_id are set
- Verify memory types are enabled
-
Context Not Being Injected:
- Check that
context_formattedis being set - Verify memory manager is properly integrated
- Ensure storage operations are successful
- Check that
-
Performance Issues:
- Limit
num_last_messagesfor large conversations - Use appropriate storage provider for your scale
- Consider disabling unused memory types
- Limit
Debug Mode
Enable debug mode to troubleshoot memory issues:Need more advanced features?
The Memory system offers several advanced configurations to enhance your agent’s capabilities:- Custom Storage Providers: Integrate with various storage backends such as PostgreSQL, MongoDB, Redis, or SQLite to suit your scalability and performance needs.
- Selective Memory Types: Enable or disable specific memory types (full session, summary, user analysis) to optimize resource usage and functionality.
- Dynamic User Profiles: Utilize dynamic user profiles that adapt schema based on interaction patterns, allowing for personalized user experiences.
- Context Management: Configure the number of last messages to retain in context, balancing between context richness and performance.
- Memory Modes: Choose between ‘update’ and ‘replace’ modes for user profile management to control how new information is integrated with existing data.
- Tool Call Integration: Configure whether tool call results are included in memory storage for comprehensive conversation tracking.
- Debugging Tools: Activate debug mode to monitor memory operations, aiding in development and troubleshooting.

