# Run a failed agent again from its task branch.

> Optional `guidance` (up to 4000 characters) is added to the next run's prompt as the founder's guidance for this attempt, after the task's instructions.
> https://koi.dog/docs/api/agents/retry-agent/

`POST /api/v1/agents/{id}/retry` · Scope: `crews`

It is recorded on the agent and on each later run (`guidance`, with who gave it) and stays with the agent, through automatic retries and recoveries, until a later retry replaces it. Without a body the agent keeps the guidance it had. An agent that is not failed or stopped answers `409 conflict`. No query parameters.

## Path parameters.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | The agent's id. |

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Makes a retry safe: the same key with the same request returns the first answer and does nothing else. |

## Body.

Optional: leave the body out and it is read as `{}`.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `guidance` | `string` | no | Added guidance for this attempt and every later run of this agent, in the founder's words. 1 to 4000 characters. |

## Response.

200 OK: a `Agent`. The example has placeholder values.

- **422 validation_failed**: The body does not match its schema; each problem is in `details`.

## Request.

```sh
curl -X POST "https://app.koi.dog/api/v1/agents/$ID/retry" \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)"
```

```js
const res = await fetch(`https://app.koi.dog/api/v1/agents/${process.env.ID}/retry`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
});
console.log(await res.json());
```

```python
import os
import uuid

import requests

r = requests.post(
    f"https://app.koi.dog/api/v1/agents/{os.environ['ID']}/retry",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "id": "string",
  "crewId": "string",
  "taskId": "string",
  "role": "manager",
  "connectionId": "string",
  "harness": "claude-code",
  "model": "string",
  "options": {
    …
  },
  "state": "created",
  "stateReason": "string",
  "placementReason": "string",
  "attempts": 0,
  "createdAt": "string",
  "updatedAt": "string",
  …
}
```
