Skip to main content
Context strategies decide how an agent compacts history — truncate, prune, or summarise — when the conversation nears the model’s limit.
Context management is opt-in via the context= parameter. When disabled (default), there is zero performance overhead.
The user picks a compaction strategy; the agent applies truncation, chunking, or summarisation when context nears the limit.

Quick Start

1

Enable with defaults

2

Fine-tune strategy and threshold

Default Behavior

Interactive Mode (praisonai chat)

To enable in CLI:

Auto-Agents Mode (Agents)

To enable:

Optimization Strategies

Strategy Overview

Tool-call/tool-result pairs stay intact. Every strategy — including the default truncate — snaps its compaction boundary so an assistant tool_calls message and its matching tool result are never separated. Long-running sessions on OpenAI, Anthropic, and Azure OpenAI keep working after compaction; you do not need a workaround for the messages with role 'tool' must be a response to a preceding message with 'tool_calls' 400.

When to Use Each

  • truncate: Simple chatbots, Q&A agents
  • sliding_window: Long conversations where recent context matters most
  • prune_tools: Tool-heavy agents with large outputs
  • summarize: When historical context is critical
  • conversation: Multi-hour planning sessions, iterative development — automatically falls back to smart when compaction ratio isn’t meaningful, making it safe as a default for long-running agents
  • smart (recommended): Production use, balances all concerns

Tool-call safety

Every strategy keeps assistant tool_calls messages and their matching tool results on the same side of the compaction boundary. If the raw token/message cut lands between a pair, the boundary is snapped outward so the pair is preserved together. For truncate, the token-budget loop additionally drops a leading assistant tool_calls message together with all of its tool results in a single step. No configuration required — this behaviour is on by default for every strategy.

Overflow Handling

Threshold Playbook

Automatic Handling

When auto_compact=True, the system automatically:
  1. Monitors token usage before each API call
  2. Triggers optimization when threshold is reached
  3. Applies the configured strategy
  4. Logs the optimization event
Compaction never emits an orphaned tool message. The recent-window boundary and any per-message drop pass keep the assistant tool_calls message and its matching tool result together — so strict providers (OpenAI, Anthropic, Azure OpenAI) never receive a partial pair.

Budgeting

Token Allocation

The context budget is divided into segments:

Custom Budgets

Monitoring

Enable Context Monitoring

Snapshot Output Example

Percentage Display

Context utilization is displayed with smart formatting:
  • Values < 0.1%: Shows <0.1%
  • Values < 1%: Shows 2 decimal places (e.g., 0.02%)
  • Values >= 1%: Shows 1 decimal place (e.g., 5.3%)

Multi-Agent Policies

Isolated (Default)

Each agent has its own context ledger:

Shared

Agents share a common context ledger:

Redaction & Security

Sensitive data is automatically redacted in snapshots:
  • API keys (OpenAI, Anthropic, Google, AWS, etc.)
  • Passwords and secrets
  • Email addresses (optional)
  • Custom patterns

Configuration Reference

ManagerConfig Options

How It Works


Best Practices

Short chats can use truncate; long support threads benefit from smart or LLM summarisation.
Use policy="isolated" unless agents explicitly share a workspace.
redact_sensitive=True protects API keys in tool results from appearing in logs.
A larger context window may let you switch to lighter strategies and save latency.
When your agent calls tools inside a long conversation, compaction never separates an assistant tool_calls message from its tool result. This holds for every strategy — truncate, sliding_window, prune_tools, summarize, conversation, and smart. Long-lived Telegram/Slack/gateway bots on strict providers keep working across weeks of history without provider 400s.

Context Budgeter

Token budget allocation

Context Monitor

Real-time context snapshots

Context Optimizer

Reduce context when over budget

Fast Context

High-performance context handling