context • Rust AI Agent SDK
Context Management Module for PraisonAI Agents.
context
Rust AI Agent SDK
Context Management Module for PraisonAI Agents.
This module provides comprehensive context management capabilities:
- Token estimation and budgeting
- Context composition within limits
- Optimization strategies (truncate, sliding window, summarize)
- Multi-agent context isolation
Example
use praisonai::{ContextManager, ContextConfig, OptimizerStrategy};
let config = ContextConfig::new()
.model("gpt-4o")
.strategy(OptimizerStrategy::Smart);
let manager = ContextManager::new(config);
let budget = manager.allocate_budget();Import
use praisonai::context::*;Classes
A segment of context with token count.
ContextLedgerTracks token usage across different context segments.
BudgetAllocationBudget allocation for different context components.
ContextConfigConfiguration for context management.
ContextBudgeterManages context budget allocation.
ContextManagerHigh-level context manager facade.
MultiAgentContextManagerContext manager for multi-agent scenarios.
LineRangeA line range within a file.
FileMatchA file match from a search.
FastContextResultResult of a fast context search.
FastContextConfigConfiguration for FastContext.
OptimizerStrategyStrategy for optimizing context when it exceeds limits.
Functions
Get context limit for a model.
get_output_reserve()Get recommended output reserve for a model.
estimate_tokens_heuristic()Estimate tokens for a string using heuristic (4 chars ≈ 1 token).
estimate_messages_tokens()Estimate tokens for messages.
estimate_tool_schema_tokens()Estimate tokens for tool schemas.