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

> Task: A unit of work that can be executed by an Agent

# Task

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

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

A unit of work that can be executed by an Agent

## Fields

| Name              | Type                       | Description                            |
| ----------------- | -------------------------- | -------------------------------------- |
| `id`              | `String`                   | Unique task ID                         |
| `name`            | `Option&lt;String&gt;`     | Task name (optional)                   |
| `description`     | `String`                   | Task description (what to do)          |
| `expected_output` | `String`                   | Expected output description            |
| `status`          | `TaskStatus`               | Task status                            |
| `task_type`       | `TaskType`                 | Task type                              |
| `result`          | `Option&lt;TaskOutput&gt;` | Task result                            |
| `depends_on`      | `Vec&lt;String&gt;`        | Dependencies (task IDs or names)       |
| `next_tasks`      | `Vec&lt;String&gt;`        | Next tasks to execute                  |
| `condition`       | `HashMap&lt;String`        | Condition for routing (decision tasks) |
| `config`          | `TaskConfig`               | Task configuration                     |
| `output_file`     | `Option&lt;String&gt;`     | Output file path                       |
| `output_variable` | `Option&lt;String&gt;`     | Output variable name                   |
| `variables`       | `HashMap&lt;String`        | Variables for substitution             |
| `serde_json`      | `:Value&gt;`               | Variables for substitution             |
| `retry_count`     | `u32`                      | Retry count                            |
| `is_start`        | `bool`                     | Is this the start task?                |

## Methods

### `new`

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

Create a new task with description

**Parameters:**

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

### `id`

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

Get task ID

### `display_name`

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

Get task name or description

### `is_completed`

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

Check if task is completed

### `is_failed`

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

Check if task failed

### `can_retry`

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

Check if task can be retried

### `increment_retry`

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

Increment retry count

### `set_result`

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

Set task result

**Parameters:**

| Name     | Type         |
| -------- | ------------ |
| `output` | `TaskOutput` |

### `set_failed`

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

Set task as failed

**Parameters:**

| Name    | Type   |
| ------- | ------ |
| `error` | `&str` |

### `result_str`

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

Get result as string

### `substitute_variables`

```rust theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
fn substitute_variables(&self, context: &HashMap<String, String>) -> String
```

Substitute variables in description

**Parameters:**

| Name      | Type                 |
| --------- | -------------------- |
| `context` | `&HashMap&lt;String` |

## Source

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