Context management is opt-in via the
context= parameter. When disabled (default), there is zero performance overhead.Quick Start
Default Behavior
Interactive Mode (praisonai chat)
| Setting | Default | Reason |
|---|---|---|
context= | False | Zero overhead for simple chats |
| When enabled: | ||
- auto_compact | True | Prevent overflow automatically |
- compact_threshold | 0.8 | Trigger at 80% usage |
- strategy | smart | Best balance of preservation |
- output_reserve | Model-specific | 8K-16K tokens |
Auto-Agents Mode (Agents)
| Setting | Default | Reason |
|---|---|---|
context= | False | Zero overhead for simple tasks |
| When enabled: | ||
- auto_compact | True | Handle long multi-agent tasks |
- compact_threshold | 0.8 | Trigger at 80% usage |
- strategy | smart | Preserve important context |
Optimization Strategies
Strategy Overview
| Strategy | Description | Pros | Cons |
|---|---|---|---|
truncate | Remove oldest messages first | Fast, simple | Loses early context |
sliding_window | Keep N most recent messages | Preserves recent | Loses early context |
prune_tools | Truncate old tool outputs | Keeps messages | May lose tool details |
summarize | Replace old messages with summary | Preserves meaning | Slower, uses API |
conversation | Structured summaries with topic/goal tracking | Preserves narrative | Requires analysis |
smart | Combine strategies intelligently | Best balance | More complex |
When to Use Each
truncate: Simple chatbots, Q&A agentssliding_window: Long conversations where recent context matters mostprune_tools: Tool-heavy agents with large outputssummarize: When historical context is criticalconversation: Multi-hour planning sessions, iterative development — automatically falls back tosmartwhen compaction ratio isn’t meaningful, making it safe as a default for long-running agentssmart(recommended): Production use, balances all concerns
Overflow Handling
Threshold Playbook
| Usage | Level | Action |
|---|---|---|
| 70% | INFO | Monitor usage, no action needed |
| 80% | NOTICE | Consider optimization soon |
| 90% | WARNING | Trigger auto-compact if enabled |
| 95% | CRITICAL | Aggressive optimization required |
| 100% | OVERFLOW | Immediate truncation to prevent API error |
Automatic Handling
Whenauto_compact=True, the system automatically:
- Monitors token usage before each API call
- Triggers optimization when threshold is reached
- Applies the configured strategy
- Logs the optimization event
Budgeting
Token Allocation
The context budget is divided into segments:| Segment | Default | Description |
|---|---|---|
| System Prompt | 2,000 | Agent instructions |
| Rules | 500 | Behavioral rules |
| Skills | 500 | Skill definitions |
| Memory | 1,000 | Long-term memory |
| Tools Schema | 2,000 | Tool definitions |
| Tool Outputs | 20,000 | Tool call results |
| History | Remaining | Conversation history |
| Buffer | 1,000 | Safety margin |
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
| Option | Type | Default | Description |
|---|---|---|---|
auto_compact | bool | True | Auto-optimize on threshold |
compact_threshold | float | 0.8 | Trigger at this usage % |
strategy | str | "smart" | Optimization strategy |
conversation_compaction | bool | False | Enable intelligent conversation compaction |
conversation_analyzer_strategy | str | "hybrid" | Strategy: hybrid, rule_based, llm_only |
conversation_min_compaction_ratio | float | 0.3 | Minimum compression ratio for conversation compaction |
output_reserve | int | Model-specific | Reserved for output |
monitor_enabled | bool | False | Enable snapshots |
monitor_path | str | None | Snapshot file path |
monitor_format | str | "human" | "human" or "json" |
redact_sensitive | bool | True | Redact secrets |
policy | str | "isolated" | Multi-agent policy |
How It Works
Best Practices
Pick strategy by session length
Pick strategy by session length
Short chats can use
truncate; long support threads benefit from smart or LLM summarisation.Isolate multi-agent context
Isolate multi-agent context
Use
policy="isolated" unless agents explicitly share a workspace.Leave redaction on
Leave redaction on
redact_sensitive=True protects API keys in tool results from appearing in logs.Revisit strategy after model changes
Revisit strategy after model changes
A larger context window may let you switch to lighter strategies and save latency.
Related
Context Budgeter
Token budget allocation
Context Monitor
Real-time context snapshots
Context Optimizer
Reduce context when over budget
Fast Context
High-performance context handling

