Scope: process-local, in-memory, opt-in
get_global_store() returns the low-level ContextStoreImpl singleton. Before you use it, know exactly what it is:
- In-memory, scoped to the current process. It is not persisted automatically and is never shared with another process. A separate
praisonaiCLI process can therefore never see a store an agent run populated. Cross-process sharing requires explicitsnapshot()/restore(). - Nothing in the agent runtime writes to it.
Agent.chat_historyand the session/memory subsystems keep their own state. This store is an opt-in structure a caller must populate — viastore.get_mutator(agent_id).append(...).commit()orstore.add_shared_context(...). - Empty on first creation. It only holds what a caller put in it during this process. The same singleton is returned on later calls, so it may already contain data from earlier in the process.
Populate the store
Cross-process sharing
The store lives in one process only. To move it to another process, serialise it withsnapshot() and rebuild it with restore():
Context Management API
Complete reference for CLI commands, flags, environment variables, and configuration options.Scope: process-local, in-memory, opt-in
get_global_store() returns a singleton that is easy to misread. Three facts govern its behaviour:
- In-memory, process-local. The store lives only in the current process. It is not persisted and not shared, so a separate
praisonaiCLI process can never see a store an agent run populated. Cross-process sharing requires explicitsnapshot()/restore(). - Nothing in the agent runtime writes to it.
Agent.chat_historyand the session/memory subsystems keep their own state. This store is opt-in — a caller must populate it viaget_mutator(...)oradd_shared_context(...). - Empty until you fill it. A freshly created store holds nothing; the same singleton is returned on later calls, so it may already contain data you added earlier in this process.
snapshot() / restore():
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

