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

# Session Message • Rust AI Agent SDK

> SessionMessage: A single message in a session

# SessionMessage

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

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

A single message in a session

## Fields

| Name         | Type                | Description                                 |
| ------------ | ------------------- | ------------------------------------------- |
| `role`       | `"user"`            | -                                           |
| `role`       | `String`            | Message role: "user", "assistant", "system" |
| `content`    | `String`            | Message content                             |
| `timestamp`  | `f64`               | Unix timestamp                              |
| `metadata`   | `HashMap&lt;String` | Optional metadata                           |
| `serde_json` | `:Value&gt;`        | Optional metadata                           |

## Methods

### `new`

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

Create a new session message

**Parameters:**

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

### `user`

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

Create a user message

**Parameters:**

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

### `assistant`

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

Create an assistant message

**Parameters:**

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

### `system`

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

Create a system message

**Parameters:**

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

### `with_metadata`

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

### `to_message`

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

Convert to LLM Message

## Source

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

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Rust Sessions" icon="clock" href="/docs/rust/sessions" />

  <Card title="Rust Memory" icon="database" href="/docs/rust/memory" />
</CardGroup>
