Skip to main content

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):
  1. CLI flags (--context-strategy smart)
  2. Environment variables (PRAISONAI_CONTEXT_STRATEGY=smart)
  3. Config file (config.yaml)
  4. Defaults

Python SDK

Complete Example

Best Practices

Call ledger.track_history after each assistant message so budgets and snapshots stay accurate.
Write monitor snapshots on turn boundaries or overflow — not on every token delta.
Allocate budgets before the run and attach a monitor when debugging context growth.
Use the high-level Agent context= config in production; drop to the raw API only for custom integrations.

Context Management

Overview of context management features

Context Monitor

Real-time context snapshots for debugging