Skip to main content

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

ContextSegment

A segment of context with token count.

ContextLedger

Tracks token usage across different context segments.

BudgetAllocation

Budget allocation for different context components.

ContextConfig

Configuration for context management.

ContextBudgeter

Manages context budget allocation.

ContextManager

High-level context manager facade.

MultiAgentContextManager

Context manager for multi-agent scenarios.

LineRange

A line range within a file.

FileMatch

A file match from a search.

FastContextResult

Result of a fast context search.

FastContextConfig

Configuration for FastContext.

OptimizerStrategy

Strategy for optimizing context when it exceeds limits.

Functions

get_model_limit()

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.

Rust Context Management

Rust Token Management