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
Memory with Model Provider
Memory Best Practices
1. Choose the Right Storage Provider
- Development/Testing: Use
InMemoryStorage
for fast iteration - Simple Applications: Use
JSONStorage
for file-based persistence - Production Web Apps: Use
PostgresStorage
orMongoStorage
for scalability - High-Performance: Use
RedisStorage
for 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: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_formatted
is being set - Verify memory manager is properly integrated
- Ensure storage operations are successful
- Check that
-
Performance Issues:
- Limit
num_last_messages
for large conversations - Use appropriate storage provider for your scale
- Consider disabling unused memory types
- Limit