Context Management API
Complete reference for CLI commands, flags, environment variables, and configuration options. The user inspects or trims context via CLI and config; the agent stays within the configured window.How It Works
Quick Start
CLI Flags
Auto-Compaction
Optimization Strategy
Trigger Threshold
Monitoring
Redaction
Output Reserve
Interactive Commands
| Command | Description |
|---|---|
/context | Show context stats summary |
/context show | Show detailed summary + budgets |
/context stats | Token ledger table |
/context budget | Budget allocation details |
/context dump | Write snapshot to disk now |
/context on | Enable monitoring |
/context off | Disable monitoring |
/context path <path> | Set snapshot output path |
/context format <fmt> | Set format (human/json) |
/context frequency <f> | Set update frequency |
/context compact | Trigger optimization now |
Examples
Environment Variables
Configuration File
Precedence Order
Configuration is resolved in this order (highest to lowest):- CLI flags (
--context-strategy smart) - Environment variables (
PRAISONAI_CONTEXT_STRATEGY=smart) - Config file (
config.yaml) - Defaults
Python SDK
Complete Example
Best Practices
Track every turn in the ledger
Track every turn in the ledger
Call
ledger.track_history after each assistant message so budgets and snapshots stay accurate.Snapshot at meaningful triggers
Snapshot at meaningful triggers
Write monitor snapshots on turn boundaries or overflow — not on every token delta.
Compose budget + monitor together
Compose budget + monitor together
Allocate budgets before the run and attach a monitor when debugging context growth.
Keep the API surface minimal
Keep the API surface minimal
Use the high-level Agent
context= config in production; drop to the raw API only for custom integrations.Related
Context Management
Overview of context management features
Context Monitor
Real-time context snapshots for debugging

