Stateful Agents Framework
PraisonAI provides a comprehensive stateful agents framework that enables building persistent, memory-aware agents capable of maintaining context across sessions, learning from interactions, and executing complex multi-step workflows.Core Stateful Capabilities
Memory System
PraisonAI includes a sophisticated multi-tiered memory system with quality-based filtering:- Short-term Memory (STM): Ephemeral context for current conversations
- Long-term Memory (LTM): Persistent knowledge with quality-based filtering
- Entity Memory: Structured data about named entities and relationships
- User Memory: User-specific preferences and interaction history
- Graph Memory: Complex relationship storage via Mem0 integration
Session Management
TheSession
class provides a unified API for managing stateful agent interactions:
Workflow State Management
PraisonAI supports complex stateful workflows with persistent state across tasks:Advanced Stateful Patterns
Quality-Based Memory Storage
Memory storage with automatic quality assessment using individual metrics:Enhanced State Management
Context Building from Multiple Sources
Knowledge Base Integration
Advanced Memory Features
Graph Memory Support
Quality Metrics and Evaluation
Session API Updates
Current Session Methods
Configuration Examples
Basic Stateful Agent
Advanced Memory Configuration
Complex Workflow with State
Best Practices
1. Session Management
- Use meaningful session IDs that can be restored later
- Save session state at key workflow milestones
- Include user_id for multi-user applications
- Use the new
session.Agent()
method for agent creation
2. Memory Strategy
- Use individual quality metrics for fine-grained control
- Implement quality thresholds based on application needs
- Store entity relationships for better context retrieval
- Use reranking for improved search results
3. State Design
- Use descriptive state keys with consistent naming
- Leverage convenience methods like
increment_state
andappend_to_state
- Implement state validation for critical workflows
- Use
has_state()
to check existence before accessing
4. Quality Management
- Set appropriate quality weights for your domain
- Use external evaluator quality when available
- Implement memory cleanup based on quality scores
- Monitor quality distribution for insights