AI Agents with Memory
PraisonAI provides comprehensive memory capabilities for AI agents, from simple file-based storage to advanced multi-agent RAG systems.Memory Types
Short-term Memory
Rolling buffer of recent context. Auto-expires when limit reached. High-importance items can be auto-promoted to long-term.
Long-term Memory
Persistent important facts sorted by importance score. Supports semantic search with RAG.
Entity Memory
Named entities (people, places, organizations) with attributes and relationships.
Episodic Memory
Date-based interaction history. Configurable retention period with automatic cleanup.
Storage Providers
In-Memory Storage with Size Limits
For lightweight memory with automatic eviction when limits are exceeded:The
InMemoryAdapter uses a monotonic ID counter that prevents ID collisions even after eviction. Once an ID is used, it’s never reused, ensuring data integrity.In-Memory Configuration Options
Memory eviction behavior:
- FIFO eviction: Oldest entries removed first when
max_sizeexceeded - Unique IDs: Monotonic counter prevents ID reuse after eviction
- Thread-safe: Safe for concurrent access
Quick Start - Single Agent (Zero Dependencies)
Enable persistent memory for agents without any extra packages. Memory is automatically injected into conversations.Single Agent Configuration
Storage Structure
Memory is stored in JSON files under.praisonai/memory/{user_id}/:
Quick Start - Multi-Agent Memory
For multi-agent workflows usingAgents, memory enables agents to share information and maintain context across tasks.
- Code
- No Code (YAML)
1
Install Package
2
Set API Key
3
Create a file
Create
app.py:4
Run
Multi-Agent Memory Configuration
Memory Methods
Store Memory
Retrieve Memory
Memory Management
Memory Deletion
Delete specific memories by ID or query. Essential for cleaning up image-based context to prevent context window overflow.Memory Quality Control (Multi-Agent)
Session Save/Resume
Save and resume conversation sessions for later continuation:Context Compression
Compress short-term memory to save context window space:Checkpointing
Create checkpoints before risky operations and restore if needed:Memory Slash Commands
Handle memory commands programmatically (useful for CLI/chat interfaces):Auto-Generated Memories
Automatically extract and store memories from conversations without manual intervention:Pattern-Based Extraction
AutoMemory uses fast pattern matching (no LLM calls) to extract:LLM-Enhanced Extraction
For better accuracy, enable LLM-based extraction:Direct FileMemory Usage
How Memory Injection Works
Whenmemory=True, the agent automatically:
- Loads existing memories from storage on initialization
- Builds a memory context string with important facts, entities, and recent context
- Injects the context into the system prompt before each LLM call
- Persists new memories to storage after interactions
Memory Tool Runtime Flow
When an agent uses memory tools (store_memory, search_memory), the request flows through the agent state to the storage backend. If memory is not configured, the tool returns a helpful message instead of crashing.
Memory and learning tools are safe to include in any default tool set because they gracefully degrade when not configured. The tool returns a user-friendly message that helps the LLM explain what to do.
Memory Adapter Cleanup
ChromeDB and MongoDB adapters now support explicit cleanup for resource management:As of PR #1558, MongoDB memory now requires
pymongo to be installed explicitly: pip install pymongo. Previously, the import was silently failing.Best Practices
Use importance scores wisely
Use importance scores wisely
Set higher importance (0.8-1.0) for critical facts like user names, preferences, and key information. Lower importance (0.3-0.5) for transient context.
Isolate memory per user
Isolate memory per user
Always set
user_id when building multi-user applications to prevent memory leakage between users.Clean up old memories
Clean up old memories
Call
cleanup_episodic() periodically to remove old date-based memories and save storage space.Use entities for structured data
Use entities for structured data
Store people, places, and organizations as entities with attributes rather than plain text for better retrieval.
Configure memory based on use case
Configure memory based on use case
Use file-based memory for simple single-agent apps, RAG for multi-agent semantic search, and graph memory for complex relationships.
Troubleshooting
Memory Issues
If memory isn’t working as expected:
- Check memory configuration
- Enable verbose mode for debugging
- Verify memory provider settings
- Check file permissions for storage path
Context Flow
If context isn’t being maintained:
- Review task dependencies
- Check memory configuration
- Verify agent communication
- Ensure user_id is consistent across sessions
Next Steps
Advanced Memory
Multi-tiered memory with quality scoring, ChromaDB, and graph support
Graph Memory
Neo4j/Memgraph integration for relationship-based memory
Memory Configuration
Detailed memory configuration options
Rules & Instructions
Auto-discover and apply persistent rules like Cursor and Windsurf
For optimal results, configure memory settings based on your specific use case requirements and expected interaction patterns.

