> ## 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 Manager • Rust AI Agent SDK

> ContextManager: High-level context manager facade.

# ContextManager

> Defined in the [**context**](../modules/context) module.

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

High-level context manager facade.

## Fields

| Name       | Type              | Description    |
| ---------- | ----------------- | -------------- |
| `config`   | `ContextConfig`   | Configuration  |
| `budgeter` | `ContextBudgeter` | Budgeter       |
| `ledger`   | `ContextLedger`   | Current ledger |

## Methods

### `new`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn new(config: ContextConfig) -> Self
```

Create a new context manager

**Parameters:**

| Name     | Type            |
| -------- | --------------- |
| `config` | `ContextConfig` |

### `default_for_model`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn default_for_model(model: impl Into<String>) -> Self
```

Create with default config

**Parameters:**

| Name    | Type                      |
| ------- | ------------------------- |
| `model` | `impl Into&lt;String&gt;` |

### `allocate_budget`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn allocate_budget(&self) -> BudgetAllocation
```

Get budget allocation

### `add_segment`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn add_segment(&mut self, segment: ContextSegment) -> ()
```

Add a segment to the ledger

**Parameters:**

| Name      | Type             |
| --------- | ---------------- |
| `segment` | `ContextSegment` |

### `remaining`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn remaining(&self) -> usize
```

Get remaining tokens

### `is_over_budget`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn is_over_budget(&self) -> bool
```

Check if over budget

### `utilization`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn utilization(&self) -> f64
```

Get utilization

### `reset`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn reset(&mut self) -> ()
```

Reset the ledger

### `track_system`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn track_system(&mut self, system_prompt: &str) -> ()
```

Estimate and track system prompt

**Parameters:**

| Name            | Type   |
| --------------- | ------ |
| `system_prompt` | `&str` |

### `track_messages`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn track_messages(&mut self, messages: &[serde_json::Value]) -> ()
```

Estimate and track messages

**Parameters:**

| Name       | Type                   |
| ---------- | ---------------------- |
| `messages` | `&[serde_json::Value]` |

### `track_tools`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn track_tools(&mut self, tools: &[serde_json::Value]) -> ()
```

Estimate and track tools

**Parameters:**

| Name    | Type                   |
| ------- | ---------------------- |
| `tools` | `&[serde_json::Value]` |

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai/src/context/mod.rs#L417">
  `praisonai/src/context/mod.rs` at line 417
</Card>

***

## 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>
