> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# context • Rust AI Agent SDK

> Context Management Module for PraisonAI Agents.

# context

<Badge color="orange">Rust AI Agent SDK</Badge>

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

```ignore theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
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

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
use praisonai::context::*;
```

## Classes

<CardGroup cols={2}>
  <Card title="ContextSegment" icon="brackets-curly" href="../classes/ContextSegment">
    A segment of context with token count.
  </Card>

  <Card title="ContextLedger" icon="brackets-curly" href="../classes/ContextLedger">
    Tracks token usage across different context segments.
  </Card>

  <Card title="BudgetAllocation" icon="brackets-curly" href="../classes/BudgetAllocation">
    Budget allocation for different context components.
  </Card>

  <Card title="ContextConfig" icon="brackets-curly" href="../classes/ContextConfig">
    Configuration for context management.
  </Card>

  <Card title="ContextBudgeter" icon="brackets-curly" href="../classes/ContextBudgeter">
    Manages context budget allocation.
  </Card>

  <Card title="ContextManager" icon="brackets-curly" href="../classes/ContextManager">
    High-level context manager facade.
  </Card>

  <Card title="MultiAgentContextManager" icon="brackets-curly" href="../classes/MultiAgentContextManager">
    Context manager for multi-agent scenarios.
  </Card>

  <Card title="LineRange" icon="brackets-curly" href="../classes/LineRange">
    A line range within a file.
  </Card>

  <Card title="FileMatch" icon="brackets-curly" href="../classes/FileMatch">
    A file match from a search.
  </Card>

  <Card title="FastContextResult" icon="brackets-curly" href="../classes/FastContextResult">
    Result of a fast context search.
  </Card>

  <Card title="FastContextConfig" icon="brackets-curly" href="../classes/FastContextConfig">
    Configuration for FastContext.
  </Card>

  <Card title="OptimizerStrategy" icon="brackets-curly" href="../classes/OptimizerStrategy">
    Strategy for optimizing context when it exceeds limits.
  </Card>
</CardGroup>

## Functions

<CardGroup cols={2}>
  <Card title="get_model_limit()" icon="function" href="../functions/get_model_limit">
    Get context limit for a model.
  </Card>

  <Card title="get_output_reserve()" icon="function" href="../functions/get_output_reserve">
    Get recommended output reserve for a model.
  </Card>

  <Card title="estimate_tokens_heuristic()" icon="function" href="../functions/estimate_tokens_heuristic">
    Estimate tokens for a string using heuristic (4 chars ≈ 1 token).
  </Card>

  <Card title="estimate_messages_tokens()" icon="function" href="../functions/estimate_messages_tokens">
    Estimate tokens for messages.
  </Card>

  <Card title="estimate_tool_schema_tokens()" icon="function" href="../functions/estimate_tool_schema_tokens">
    Estimate tokens for tool schemas.
  </Card>
</CardGroup>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Rust Context Management" icon="layer-group" href="/docs/rust/context-management" />

  <Card title="Rust Token Management" icon="coins" href="/docs/rust/token-management" />
</CardGroup>
