ContextManager orchestrates budgeting, composition, optimisation, and monitoring through one interface.
The user sends a large thread; the context manager budgets tokens and returns an optimised message list for the next LLM call.
How It Works
Quick Start
Architecture
Configuration
ManagerConfig
Environment Variables
| Variable | Default | Description |
|---|---|---|
PRAISONAI_CONTEXT_AUTO_COMPACT | true | Enable auto-compaction |
PRAISONAI_CONTEXT_THRESHOLD | 0.8 | Compact threshold (0-1) |
PRAISONAI_CONTEXT_STRATEGY | smart | Optimization strategy |
PRAISONAI_CONTEXT_MONITOR | false | Enable monitoring |
PRAISONAI_CONTEXT_ESTIMATION_MODE | heuristic | Token estimation mode |
Config Precedence
Core Methods
process()
Process messages through the full context pipeline:capture_llm_boundary()
Capture exact state at LLM call boundary for debugging:get_stats()
Get current context statistics:get_resolved_config()
Get fully resolved configuration with source info:get_history()
Get optimization event history:Per-Tool Budgets
Set custom token budgets per tool:Token Estimation
Snapshot Callbacks
Register callbacks for LLM boundary snapshots:CLI Integration
Factory Function
Usecreate_context_manager for proper config precedence:
Best Practices
Enable auto-compact for long sessions
Enable auto-compact for long sessions
Set
auto_compact=True and compact_threshold=0.8 so context stays within model limits without manual /context compact.Set per-tool output budgets
Set per-tool output budgets
Use
set_tool_budget() on noisy tools like file reads before they flood the context window.Turn on monitoring for debugging
Turn on monitoring for debugging
Enable
monitor_enabled and write snapshots to disk when tracing compaction decisions.Use create_context_manager for precedence
Use create_context_manager for precedence
Prefer the factory when mixing CLI flags, env vars, and
config.yaml overrides.Related
Context Files
Inject project files into agent context alongside the manager pipeline.
Per-Tool Budgets
Cap individual tool outputs before they reach the manager.
Optimiser
Compression strategies used inside
ContextManager.process().Multi-Agent Policies
Per-agent isolation and handoff sharing rules.

