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

> ContextAgent: Context agent for managing conversation context

# ContextAgent

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

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

Context agent for managing conversation context

```mermaid theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#8B0000', 'primaryTextColor': '#fff', 'primaryBorderColor': '#710101', 'lineColor': '#189AB4', 'secondaryColor': '#189AB4', 'tertiaryColor': '#fff' }}}%%

graph LR
    input["Input Data"] --> agent["Agent: ContextAgent"]
    agent --> output["Output Result"]
    style agent fill:#8B0000,color:#fff
    style input fill:#8B0000,color:#fff
    style output fill:#8B0000,color:#fff
```

## Fields

| Name          | Type                      | Description     |
| ------------- | ------------------------- | --------------- |
| `config`      | `ContextAgentConfig`      | Configuration   |
| `context`     | `Vec&lt;ContextEntry&gt;` | Context window  |
| `max_entries` | `usize`                   | Maximum entries |

## Methods

### `new`

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

Create a new context agent

**Parameters:**

| Name     | Type                 |
| -------- | -------------------- |
| `config` | `ContextAgentConfig` |

### `add`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn add(&mut self, role: impl Into<String>, content: impl Into<String>) -> ()
```

Add an entry to context

**Parameters:**

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

### `get_context`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn get_context(&self) -> Vec<&ContextEntry>
```

Get context as messages

### `clear`

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

Clear context

### `len`

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

Get context length

### `is_empty`

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

Check if context is empty

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai/src/parity/specialized.rs#L46">
  `praisonai/src/parity/specialized.rs` at line 46
</Card>

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Rust Agent" icon="robot" href="/docs/rust/agent" />

  <Card title="Rust Overview" icon="book-open" href="/docs/rust/overview" />

  <Card title="Rust Quickstart" icon="rocket" href="/docs/rust/quickstart" />

  <Card title="Rust Installation" icon="download" href="/docs/rust/installation" />

  <Card title="Rust Autonomy" icon="wand-magic-sparkles" href="/docs/rust/autonomy" />
</CardGroup>
