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
1
Create a manager
2
Process messages
3
Inspect utilisation
Architecture
Configuration
ManagerConfig
Environment Variables
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. The praisonai chat / praisonai code interactive CLI honours the same defaults inside its worker loop — no extra wiring required.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.

