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

# Task Output • Rust AI Agent SDK

> TaskOutput: Task output containing the result of task execution

# TaskOutput

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

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

Task output containing the result of task execution

## Fields

| Name          | Type                              | Description                        |
| ------------- | --------------------------------- | ---------------------------------- |
| `raw`         | `String`                          | Raw output string                  |
| `json`        | `Option&lt;serde_json::Value&gt;` | Parsed JSON output (if applicable) |
| `task_id`     | `String`                          | Task ID                            |
| `agent_name`  | `Option&lt;String&gt;`            | Agent name that executed the task  |
| `duration_ms` | `Option&lt;u64&gt;`               | Execution duration in milliseconds |
| `tokens_used` | `Option&lt;u32&gt;`               | Token usage                        |
| `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(raw: impl Into<String>, task_id: impl Into<String>) -> Self
```

Create a new task output

**Parameters:**

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

### `with_json`

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

Set JSON output

**Parameters:**

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

### `with_agent`

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

Set agent name

**Parameters:**

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

### `with_duration`

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

Set duration

**Parameters:**

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

### `with_tokens`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn with_tokens(mut self, tokens: u32) -> Self
```

Set token usage

**Parameters:**

| Name     | Type  |
| -------- | ----- |
| `tokens` | `u32` |

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

### `as_str`

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

Get raw output as string

### `parse_json`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn parse_json(&self) -> Result<serde_json::Value>
```

Try to parse raw output as JSON

## Source

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

***

## Related Documentation

<CardGroup cols={2}>
  <Card title="Rust Tasks" icon="list-check" href="/docs/rust/tasks" />

  <Card title="Rust Execution" icon="play" href="/docs/rust/execution" />

  <Card title="Rust Output" icon="file-export" href="/docs/rust/output" />

  <Card title="Rust Structured Output" icon="code" href="/docs/rust/structured-output" />

  <Card title="Rust Display" icon="display" href="/docs/rust/display" />
</CardGroup>
