# Ask an AI agent on a machine

An agent connected to CMDOP, or your own program through the SDK, can put a question to an AI agent
program installed on one of your machines (Claude Code, Codex) and get its answer back. It works the
same way for every program, so ChatGPT can ask Claude Code, and Claude can ask Codex, with no
integration between the vendors.

**In short:** [`agent_list`](https://docs.cmdop.ai/reference/tools/agent_list.md) names the agents a machine lets you ask;
[`agent_prompt`](https://docs.cmdop.ai/reference/tools/agent_prompt.md) `{"prompt": "…"}` returns the answer and a `session`; pass that
`session` back to continue. The asked agent answers in words or reads files. It never changes files or runs
commands.

## Before you start

- The agent program is installed and signed in on that machine, under the same user that runs CMDOP. Its model
  runs at its vendor, and each answer counts against that vendor account.
- Nothing to switch on: every machine allows it unless its owner turned `agent` off in
  [`ceiling.json`](https://docs.cmdop.ai/reference/config/ceiling-json.md), whose `agents` key can also name which programs may be asked
  (`allow`), the one asked when none is named (`default`), and how far they may go (`tier`).
- The agent or program that asks may run commands (`exec` in its [grant](https://docs.cmdop.ai/guides/access/grant.md)), or holds `agent`
  alone. Listing needs only `read`.

## Steps

1. **See who can answer.** Call [`agent_list`](https://docs.cmdop.ai/reference/tools/agent_list.md) on the machine. Each row has the
   agent's `id`, its `tier`, whether it can `resume` a conversation and whether it is `busy`, and `default` names
   the one a prompt goes to without `agent`. With no allowed agent installed, the machine offers none of these
   tools.
2. **Ask.** Call [`agent_prompt`](https://docs.cmdop.ai/reference/tools/agent_prompt.md) with `prompt` (up to 16 KiB) and, if you want a
   particular one, `agent`. It waits up to `wait_secs` (default 50, at most 240) and returns `state` and `text`:

   ```json
   {"task": "…", "agent": "claude-code", "state": "done", "session": "…", "text": "The weakest point is …", "tier": "read_only"}
   ```

   A longer answer comes back as `state: "running"`. Read the rest with
   [`task_output`](https://docs.cmdop.ai/reference/tools/task_output.md) `{task}`.
3. **Continue.** Pass the answer's `session` back to `agent_prompt` with the next question. The agent remembers
   the conversation. [`agent_sessions`](https://docs.cmdop.ai/reference/tools/agent_sessions.md) lists recent sessions, newest first.
4. **Stop** a run with [`agent_cancel`](https://docs.cmdop.ai/reference/tools/agent_cancel.md) `{task}`.

From the SDK, the same calls are `box.agent.list()`, `box.agent.prompt({ prompt, session })`,
`box.agent.sessions()` and `box.agent.cancel({ task })` ([SDK](https://docs.cmdop.ai/reference/sdk.md)). Streaming callers also receive the
agent's progress as it works.

## How far the asked agent may go

| Tier | It may |
|---|---|
| `text_only` | answer in words. Any attempt to use a tool stops the run with [`tool_refused`](https://docs.cmdop.ai/reference/errors/tool_refused.md) |
| `read_only` | also read files in its folder. It changes nothing and runs no commands. This is the default |

There is no tier that changes files or runs commands. A call may ask for a lower tier than the machine allows,
never a higher one. Claude Code offers both tiers; Codex answers in words only (`text_only`).

`cwd` picks the folder the agent reads. Without it, the agent works in a folder of its own that stays the same, so
a `session` continues where it left off. Folders that hold keys or credentials (your home folder itself, `~/.ssh`,
the agents' own folders, a repository's `.git`) are refused.

## Safety

- The prompt and the answer are not stored by CMDOP. The record shows that the agent was asked, by whom and how it
  ended ([the record of calls](https://docs.cmdop.ai/concepts/audit-and-history.md)).
- Send no secrets in the prompt: it goes to the other program's vendor.
- If the asked agent refuses, bring that back to the person; do not rephrase the request until it agrees.
- One question at a time per agent on a machine: a second one answers [`busy`](https://docs.cmdop.ai/reference/errors/busy.md).

## If it fails

| Code | What to do |
|---|---|
| [`denied`](https://docs.cmdop.ai/reference/errors/denied.md) | the grant or the machine's ceiling lacks `agent`, the agent is not in `allow`, or `cwd` is refused |
| [`not_found`](https://docs.cmdop.ai/reference/errors/not_found.md) | the agent is not installed there, or the `cwd` folder does not exist |
| [`busy`](https://docs.cmdop.ai/reference/errors/busy.md) | wait for the running answer, or stop it with `agent_cancel` |
| [`tool_refused`](https://docs.cmdop.ai/reference/errors/tool_refused.md) | the agent tried to use a tool on a `text_only` run; ask in a way it can answer in words, or allow `read_only` |
| [`sandbox_unavailable`](https://docs.cmdop.ai/reference/errors/sandbox_unavailable.md) | the machine cannot run the agent safely, so nothing started |
| [`unknown_tool`](https://docs.cmdop.ai/reference/errors/unknown_tool.md) | the machine offers no agent tools: no allowed agent installed, or an older cmdop |

## Related

[Ask another AI for a second opinion](https://docs.cmdop.ai/guides/use-cases/second-opinion.md) · [Grant risk classes](https://docs.cmdop.ai/guides/access/grant.md) ·
[`ceiling.json`](https://docs.cmdop.ai/reference/config/ceiling-json.md) · [Tools](https://docs.cmdop.ai/reference/tools.md)
