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

> ContextEvent: A context event for replay/debugging.

# ContextEvent

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

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

A context event for replay/debugging.

## Fields

| Name           | Type                              | Description                              |
| -------------- | --------------------------------- | ---------------------------------------- |
| `event_type`   | `ContextEventType`                | Event type                               |
| `name`         | `String`                          | Event name                               |
| `timestamp_ms` | `u64`                             | Timestamp (milliseconds since epoch)     |
| `agent_id`     | `Option&lt;String&gt;`            | Agent ID (if applicable)                 |
| `agent_name`   | `Option&lt;String&gt;`            | Agent name (if applicable)               |
| `tool_name`    | `Option&lt;String&gt;`            | Tool name (if applicable)                |
| `input`        | `Option&lt;serde_json::Value&gt;` | Input data                               |
| `output`       | `Option&lt;serde_json::Value&gt;` | Output data                              |
| `error`        | `Option&lt;String&gt;`            | Error message (if applicable)            |
| `duration_ms`  | `Option&lt;u64&gt;`               | Duration in milliseconds (if applicable) |
| `metadata`     | `HashMap&lt;String`               | Additional metadata                      |
| `serde_json`   | `:Value&gt;`                      | Additional metadata                      |

## Methods

### `new`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn new(event_type: ContextEventType, name: impl Into<String>) -> Self
```

Create a new context event.

**Parameters:**

| Name         | Type                      |
| ------------ | ------------------------- |
| `event_type` | `ContextEventType`        |
| `name`       | `impl Into&lt;String&gt;` |

### `agent`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn agent(mut self, id: impl Into<String>, name: impl Into<String>) -> Self
```

Set agent info.

**Parameters:**

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

### `tool`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn tool(mut self, name: impl Into<String>) -> Self
```

Set tool name.

**Parameters:**

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

### `input`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn input(mut self, input: serde_json::Value) -> Self
```

Set input.

**Parameters:**

| Name    | Type                |
| ------- | ------------------- |
| `input` | `serde_json::Value` |

### `output`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn output(mut self, output: serde_json::Value) -> Self
```

Set output.

**Parameters:**

| Name     | Type                |
| -------- | ------------------- |
| `output` | `serde_json::Value` |

### `error`

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

Set error.

**Parameters:**

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

### `duration_ms`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn duration_ms(mut self, ms: u64) -> Self
```

Set duration.

**Parameters:**

| Name | Type  |
| ---- | ----- |
| `ms` | `u64` |

### `metadata`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn metadata(mut self, key: impl Into<String>, value: serde_json::Value) -> Self
```

Add metadata.

**Parameters:**

| Name    | Type                      |
| ------- | ------------------------- |
| `key`   | `impl Into&lt;String&gt;` |
| `value` | `serde_json::Value`       |

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-rust/praisonai/src/trace/mod.rs#L486">
  `praisonai/src/trace/mod.rs` at line 486
</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>
