# AgentFinishedEvent
Source: https://docs.maelstrom-ai.co/dev/reference/protocol/interfaces/agentfinishedevent/
Documentation revision: 89a8f5e9d10cedcf0b30376d7846113f06f26120
SDK manifests in this build: @maelstrom-co/react@0.2.1, @maelstrom-co/client@0.2.1, @maelstrom-co/connectors@0.2.1, @maelstrom-co/protocol@0.2.1, @maelstrom-co/engine@0.2.1
These docs follow this source revision. Manifest versions do not prove release compatibility; verify the installed package exports before using an API.

Defined in: [packages/protocol/src/lib/agent-wire.ts:412](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/agent-wire.ts#L412)

The end of an Agent Run with its structured outcome.

The agent loop is experimental in 0.3 and may change in any minor release.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

## Properties

### code?

> `optional` **code?**: `string`

Defined in: [packages/protocol/src/lib/agent-wire.ts:439](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/agent-wire.ts#L439)

Optional machine-readable failure kind with no closed taxonomy, same meaning as on the `error` event.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

* * *

### error?

> `optional` **error?**: `string`

Defined in: [packages/protocol/src/lib/agent-wire.ts:434](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/agent-wire.ts#L434)

Human-readable failure description when `ok` is `false`.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

* * *

### metrics

> **metrics**: [`AgentRunMetrics`](https://docs.maelstrom-ai.co/dev/reference/protocol/interfaces/agentrunmetrics/)

Defined in: [packages/protocol/src/lib/agent-wire.ts:432](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/agent-wire.ts#L432)

Cost counters for the run.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

* * *

### ok

> **ok**: `boolean`

Defined in: [packages/protocol/src/lib/agent-wire.ts:423](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/agent-wire.ts#L423)

`true` when the run ended as intended (`completed`, `waiting`), `false` for `cancelled`, `budget` and `error`.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

* * *

### reason

> **reason**: `"error"` | `"completed"` | `"waiting"` | `"cancelled"` | `"budget"`

Defined in: [packages/protocol/src/lib/agent-wire.ts:425](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/agent-wire.ts#L425)

Why the run ended.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

* * *

### reply?

> `optional` **reply?**: `string`

Defined in: [packages/protocol/src/lib/agent-wire.ts:430](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/agent-wire.ts#L430)

Full text of the final reply, or the closing message on a budget ending. Absent when the run failed, was cancelled or ended without text.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

* * *

### runId

> **runId**: [`RunId`](https://docs.maelstrom-ai.co/dev/reference/protocol/type-aliases/runid/)

Defined in: [packages/protocol/src/lib/agent-wire.ts:418](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/agent-wire.ts#L418)

The Agent Run that ended.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

* * *

### type

> **type**: `"finished"`

Defined in: [packages/protocol/src/lib/agent-wire.ts:414](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/agent-wire.ts#L414)

Member discriminator.

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.

* * *

### version

> **version**: `1`

Defined in: [packages/protocol/src/lib/agent-wire.ts:416](https://github.com/maelstrom-co/maelstrom/blob/89a8f5e9d10cedcf0b30376d7846113f06f26120/packages/protocol/src/lib/agent-wire.ts#L416)

Agent wire version, always [AGENT\_WIRE\_VERSION](https://docs.maelstrom-ai.co/dev/reference/protocol/variables/agent_wire_version/).

> [!WARNING]
> Experimental
> 
> This API should not be used in production and may be trimmed from a public release.
