AI Agents with Context
PraisonAI provides industry-leading context management with smart defaults, lazy loading, and 6 optimization strategies.Quick Start
What is Context?
Context is everything sent to the LLM in a single API call. It includes:System Prompt
Agent instructions, role, and goals (~2K tokens)
Chat History
User/assistant messages (variable)
Tool Schemas
Function definitions (~2K tokens)
Tool Outputs
Results from tool calls (~20K tokens)
Memory/RAG
Retrieved context (~4K tokens)
Output Reserve
Space for LLM response (~8-16K tokens)
How Context Flows
Single Agent Flow
Multi-Agent Flow
Optimization Strategies
When context exceeds the threshold (default 80%), the optimizer kicks in:Smart Strategy Flow
Overflow Handling
Token Budgeting
The Context Budgeter allocates tokens across segments:Model Limits
Per-Tool Budgets
Set different limits for different tools:Session Deduplication
Prevents duplicate content across agents in multi-agent workflows:Multi-Agent Policies
Control how context is shared between agents:Context Monitoring
Real-time snapshots for debugging:Snapshot Output
Token Estimation
Fast offline token counting (no API calls):Fast Context (Code Search)
Rapid parallel code search for AI agents:CLI Commands
In-Session Commands
Configuration Reference
ManagerConfig Options
Environment Variables
Best Practices
Enable for tool-heavy agents
Enable for tool-heavy agents
Always enable
context=True for agents with tools to prevent token overflow from large search results.Use smart strategy in production
Use smart strategy in production
The
smart strategy combines all optimization techniques intelligently.Set per-tool limits
Set per-tool limits
Configure lower limits for verbose tools (search, web scraping) and higher limits for code execution.
Monitor during development
Monitor during development
Enable
monitor_enabled=True to debug context issues and understand token usage.Use session deduplication
Use session deduplication
In multi-agent workflows, deduplication prevents the same content from being processed multiple times.
Related Pages
Memory
Persistent storage across sessions
Knowledge
Pre-loaded reference documents
Context vs Memory
When to use each system
Context vs Knowledge
Runtime vs pre-loaded data
Context management uses lazy loading throughout. Setting
context=True adds only 1 boolean assignment at creation time (0ms). The ContextManager is only instantiated when first accessed.
