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
1
Enable context flags in chat
2
Inspect usage in session
CLI Flags
Auto-Compaction
Interactive mode (
praisonai chat, praisonai code) actually enforces the flag inside the worker loop — proactive check every turn plus a reactive retry on provider context-length errors. In non-interactive workflow runs the same flag is applied via the standard ContextManager config.Optimization Strategy
Trigger Threshold
Monitoring
Redaction
Output Reserve
Interactive Commands
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

