# agent_prompt

Sends a prompt to an AI agent program on the machine and returns its answer and a session id to continue. Long runs return a task to follow.

**In short:** Risk class [`agent`](https://docs.cmdop.ai/reference/tools.md#risk-classes). Over MCP call `agent_prompt`; over HTTP send `"tool": "agent_prompt"` to [`POST /api/v1/call`](https://docs.cmdop.ai/reference/http/post-call.md).

## Arguments

Over MCP every tool also takes `machine`: the machine's name or id, optional when only one machine is online.

| Name | Type | Required | Meaning |
| --- | --- | --- | --- |
| `agent` | `string` | no | Catalog id from `agent_list`. Absent: the machine's default agent. |
| `cwd` | `string` | no | Folder the agent works in. Absent: the agent's own folder on the machine, the same for every prompt, so a `session` continues there. |
| `prompt` | `string` | yes | What to ask, at most 16 KiB. The agent reads it as an instruction. |
| `session` | `string` | no | A `session` from an earlier answer, to continue that conversation. |
| `tier` | `"text_only" \| "read_only"` | no | Ask for less than the machine allows; never more. |
| `wait_secs` | `integer` | no | Seconds to wait for the answer (default 50, at most 240). A run still going then keeps going: follow it with `task_output` on `task`. |

## Result

| Name | Type | Required | Meaning |
| --- | --- | --- | --- |
| `agent` | `string` | yes | The agent that answered. |
| `error` | `string` | no | Why there is no answer, when `state` is `failed`. |
| `session` | `string` | no | Pass it back as `session` to continue. |
| `state` | `"running" \| "done" \| "failed" \| "stopped" \| "paused"` | yes |  |
| `task` | `integer` | yes | The run's task: `task_output` reads it, `agent_cancel` stops it. |
| `text` | `string` | no | The agent's final answer. |
| `tier` | `"text_only" \| "read_only"` | yes | The tier the run had. |

## Examples

**MCP**

```json
{
  "name": "agent_prompt",
  "arguments": {
    "machine": "<machine>",
    "prompt": "<prompt>"
  }
}
```

**HTTP**

```bash
curl -sS -X POST "https://<contour>.cmdop.dev/api/v1/call" \
  -H "Authorization: Bearer $CMDOP_TOKEN" \
  -H "x-cmdop: 1" \
  -H "Content-Type: application/json" \
  -d '{"machine":"<machine>","tool":"agent_prompt","args":{"prompt":"<prompt>"}}'
```

## Limits

The call times out after 260 s (`timed_out`). Available since version 0.1.13. A refused or failed call returns one of the [error codes](https://docs.cmdop.ai/reference/errors.md).
