# ACP Protocol: Run Octomind as an Agent Client Protocol Agent The Agent Client Protocol (ACP) lets Octomind run as a JSON-RPC sub-agent over stdio for editor integration and agent-to-agent delegation. ACP provides: - JSON-RPC over stdio communication - Tool execution with streaming results - Slash command support (advertised set) plus a programmatic [extension-command](#extension-commands) method - MCP server injection from the host (Stdio/HTTP) - Session lifecycle management - Out-of-band [cost/token usage](#cost-and-token-usage-side-channel) reporting via `_meta` ## Starting an ACP Agent ```bash octomind acp --name editor-session ``` | Flag | Description | |------|-------------| | `TAG` | Agent name or role name. Omit for `default` (shipped value `assistant`). | | `--readonly` | Offer and run only tools whose MCP `readOnlyHint` annotation is true; a tool with no hint counts as mutable. A read-only session cannot delegate. The mode is fixed for the session and restored on resume. | | `--name`, `-n` | Preferred session name for the next `new_session` | | `--resume`, `-r` | Resume a specific session by name on `new_session` | | `--resume-recent` | Resume the most recent session for the CWD on `new_session` | | `--model`, `-m` | Override the model for all sessions | | `--sandbox` | Restrict filesystem writes to CWD | The agent reads JSON-RPC messages from stdin and writes responses to stdout. The initialized ACP runtime sends diagnostics to files under the data directory: | File | Contents | |------|----------| | `acp-debug.log` | Tracing output for the ACP session (controlled by `RUST_LOG` / config `log_level`) | | `acp-errors.jsonl` | Structured JSONL error sink for programmatic protocol-error analysis | | `acp-init-errors.log` | Fallback for failures that happen *before* logging is up (tracing / error-sink initialization). Written directly with no formatting. | The data directory is `OCTOMIND_DATA_DIR`, or `~/.local/share/octomind` on macOS/Linux and `%LOCALAPPDATA%/octomind` on Windows; the files above live in its `logs/` directory. Keep stdout exclusively for JSON-RPC. Capture stderr separately because CLI/bootstrap failures can write there before ACP logging starts. ```bash RUST_LOG=debug octomind acp --name editor-session 2>acp-startup.log ``` > ACP output reuses the same internal `ServerMessage` pipeline as the WebSocket server — `ToolCall`/`ToolCallUpdate` > translation mirrors the WebSocket message types. See [WebSocket Server](01-websocket-server.md) for the shared message > shapes. For example, resume a named session and override its model: ```bash octomind acp assistant --resume editor-session --model octohub:auto ``` Or resume the most recent session for the directory supplied by the host: ```bash octomind acp --resume-recent --sandbox ``` ## MCP Server Injection Hosts can inject additional MCP servers when creating a session (`session/new` or `session/load`). The injected servers become available to that session alongside its configured servers, letting editors provide project-specific tools (e.g. language servers, project databases) to the AI. Injection semantics: - **Transports**: `Stdio` and `HTTP` servers are accepted (timeout hard-coded to 30s, empty per-server tool filter; role tool filters still apply). `SSE` and unknown transports are skipped silently with a log line. - **Config snapshot**: injection does not mutate the base config. MCP processes/tool registration remain shared within the agent process; this is not a separate credential or process boundary. - **Deduped by name**: a server whose name is already present is not re-added. - **Ignored fields**: injected Stdio `env` and HTTP `headers` are not copied into Octomind's server config. Arrange credentials in the agent's environment or configured MCP server instead. For an existing HTTP MCP server listening locally, the creation payload is: ```json {"jsonrpc":"2.0","id":9,"method":"session/new","params":{"cwd":"/tmp","mcpServers":[{"type":"http","name":"project-tools","url":"http://127.0.0.1:9000/mcp","headers":[]}]}} ``` ## Protocol Flow Each step is labelled with who acts — **(host)** = the editor/parent client, **(agent)** = Octomind. 1. **(host)** Starts `octomind acp [TAG]` as a subprocess. 2. **(host → agent)** `initialize`: host sends its capabilities; agent responds with `ProtocolVersion::LATEST`, its capabilities, agent identity, and an `octomind.dev` extension marker (see [Agent Capabilities](#agent-capabilities)). 3. **(host → agent)** `authenticate`: needed only when a prompt fails with `auth_required` (`-32000`), which happens when the session model is `octohub:*`, `OCTOHUB_API_KEY` is unset, and `OCTOHUB_API_URL` does not point at a self-hosted hub. Sessions still open and slash commands still run while signed out; only model-bound prompts are refused. `initialize` advertises one method, `octomind-login`; `authenticate` with it opens the browser for the `octomind login` device flow and returns once the code is confirmed. Other providers take credentials from the agent environment/config. 4. **(host → agent)** Session creation: `session/new` starts a fresh session; `session/load` resumes a specific session id from disk. See [session creation details](02-acp-protocol.md) for the behavioral difference. 5. **(host ↔ agent)** Message exchange: host sends `session/prompt`; agent streams responses as `session/update` notifications. 6. **(agent → host)** Tool execution: agent announces tool calls as `ToolCall` updates and streams `ToolCallUpdate` results. 7. **(host → agent)** Cancellation: host sends `session/cancel`; the in-flight prompt returns `StopReason::Cancelled`. 8. **(host)** Shutdown: close stdin after sending your final request. The agent waits for finite background work and resulting inbox turns before closing stdout and returning. Keep reading stdout until EOF. There is no dedicated shutdown RPC. ### Example message exchange Use this Python client from your project directory. It starts the agent, waits for each response, prints updates, and uses the returned session ID. The wire format is one JSON object per line; do not close stdin before the pending responses arrive. ```python import json import os import subprocess agent = subprocess.Popen( ["octomind", "acp", "--name", "editor-session"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True, bufsize=1, ) def request(number, method, params): agent.stdin.write(json.dumps({ "jsonrpc": "2.0", "id": number, "method": method, "params": params }) + "\n") agent.stdin.flush() for line in agent.stdout: message = json.loads(line) if message.get("id") == number: if "error" in message: raise RuntimeError(message["error"]) return message["result"] print(json.dumps(message)) raise RuntimeError("ACP closed before replying") try: request(1, "initialize", {"protocolVersion": 1, "clientCapabilities": {}}) session = request(2, "session/new", {"cwd": os.getcwd(), "mcpServers": []}) session_id = session["sessionId"] print(request(3, "session/prompt", { "sessionId": session_id, "prompt": [{"type": "text", "text": "Explain src/main.rs"}], })) finally: agent.stdin.close() for line in agent.stdout: print(line, end="") agent.wait() ``` For subsequent payload examples, replace `editor-session` with the `sessionId` returned by your host's creation request. To resume that saved session, send: ```json {"jsonrpc":"2.0","id":4,"method":"session/load","params":{"sessionId":"editor-session","cwd":"/tmp","mcpServers":[]}} ``` Set `cwd` to the absolute project directory you want the session to use. ### Cost and token usage side-channel The standard ACP `UsageUpdate` variant is not used. Instead, token and cost usage is delivered out-of-band as a `SessionInfoUpdate` notification carrying an `octomind.usage` object in the notification `_meta`: ```json {"jsonrpc":"2.0","method":"session/update", "params":{"sessionId":"editor-session", "update":{"sessionUpdate":"session_info_update"}, "_meta":{"octomind.usage":{ "session_tokens": 12000, "session_cost": 0.0, "input_tokens": 9000, "output_tokens": 3000, "cache_read_tokens": 0, "cache_write_tokens": 0, "reasoning_tokens": 0 }}}} ``` After a normal AI prompt the agent also emits notification metadata: ```json {"jsonrpc":"2.0","method":"session/update","params":{"sessionId":"editor-session","update":{"sessionUpdate":"session_info_update"},"_meta":{"octomind.verified":false,"octomind.pending_work":false}}} ``` `octomind.verified` is true only when a plugin reported the work as verified at the end of its last turn; without any plugin it is false, and with plugins that gave no verdict it is left out. It is not proof that every task requirement passed. `octomind.pending_work` indicates outstanding async work and also appears in the successful prompt result's `_meta`; `end_turn` alone does not mean background work has finished. The inbox monitor also emits this field after draining its work, so a client keeping input open can observe when that background work becomes idle. Clients that preserve ACP `_meta` can read this extension; clients that discard `_meta` still receive the normal session updates but not this usage payload. The `octomind.evolution` `_meta` object is still defined for grounded behavior lifecycle changes, carrying action/id/name/kind/state/scope fields, but the current octomind code does not produce these events. ### Session creation: `new_session` vs `load_session` Both calls run the session in `websocket` output mode, merge any client-injected MCP servers (see [MCP Server Injection](#mcp-server-injection)), and spawn a [background inbox monitor](#background-inbox-monitor). They differ in how they pick the session: - **`session/new`** creates a fresh session and, on the **first** call, consumes the one-shot CLI overrides `--name` / `--resume` / `--resume-recent`. After that first call those overrides revert to defaults; subsequent `session/new` calls ignore them. - **`session/load`** always resumes the specific session id supplied by the client, read from disk. It does not touch the one-shot overrides. The `--model` value applies to **every** session created or loaded for the agent's lifetime. ### Prompt Content `session/prompt` content blocks are mapped as follows: - **Text** blocks and resource text are joined with newlines in their original order. - **Embedded text resources** (including editor @-mentioned files) become fenced blocks labelled with their URI. - **Resource links** with local `file://` URIs are read as UTF-8 text only when their canonical path is inside the session's working directory. Traversal and symlinks outside that directory are rejected. Unsupported URIs, missing files, directories, and invalid UTF-8 produce a short note in the prompt instead of being silently dropped. - **Image** blocks are all attached as inline base64 image attachments (using each block's `mimeType`). - **Resource** blocks carrying a blob resource with a `video/*` MIME type are attached as video (ACP has no native video block). All videos are retained, in order. Audio and other blob resources are ignored. Embedded and linked text share one per-prompt budget: `mcp_response_tokens_threshold`, the same token cap every tool result gets (default `20000`; `0` disables it). Text past the budget is cut with a notice, and file reads stop at the remaining budget. Ordinary text blocks and media attachments are not truncated. To attach an actual local image or video, indent this code inside the Python client's `try` block, before `finally` (choose a model supporting the modality): ```python import base64 from pathlib import Path image_data = base64.b64encode(Path("screenshot.png").read_bytes()).decode("ascii") print(request(6, "session/prompt", { "sessionId": session_id, "prompt": [ {"type": "text", "text": "Describe this screenshot"}, {"type": "image", "mimeType": "image/png", "data": image_data}, ], })) video_data = base64.b64encode(Path("clip.mp4").read_bytes()).decode("ascii") print(request(7, "session/prompt", { "sessionId": session_id, "prompt": [ {"type": "text", "text": "Summarize this clip"}, {"type": "resource", "resource": { "uri": "file:///tmp/clip.mp4", "mimeType": "video/mp4", "blob": video_data, }}, ], })) ``` Resource-only prompts are processed normally. If the prompt has no supported content, the agent immediately returns `StopReason::EndTurn`. ## Use Cases ### Editor Integration For editor launch configurations, see [Editor Integration](../usage/12-editor-integration.md). > Compatibility note: usage and extension data are delivered through ACP `_meta`. Clients that forward `_meta` see them; > clients that strip `_meta` still work but do not surface those fields. ### Agent Delegation For a tap run, Octomind acts as the **ACP client**: 1. Pins the selected manifest to the new run ID and spawns an ACP child with that binding. A local config role cannot replace the selected manifest. 2. Sends `initialize` (with `protocolVersion: 1`) — it does **not** call `authenticate`. 3. Sends `session/new` with an empty `mcpServers` list. 4. Sends `session/prompt` carrying the task as a single text block. 5. Accumulates every `agent_message_chunk` text into the result, and forwards intermediate `session/update` events (thinking, tool calls, tool results) up to the parent's notification sink so the user sees the sub-agent's progress live. 6. Waits for outstanding async work when `octomind.pending_work` is true, then returns accumulated text (surfacing any `session/prompt` error instead of an empty string). Initialization and session creation each have a 30-second handshake timeout. Custom ACP binaries must reply to both requests before they can receive the task. For tap agent runs, `tap(action="send", session="RUN_ID", prompt="...")` queues another ordinary `session/prompt` on the existing child connection. Prompts run sequentially in the same child session. The parent keeps input open while a prompt or background work is active, then drains accepted prompts before closing input and returning the combined reply. The `send` result acknowledges queueing, not completion. ## Background Inbox Monitor ACP sessions automatically spawn a background task that monitors schedules and the session inbox for internally enqueued messages such as scheduled work, background agents, tap runs, skills, monitors, detached jobs, and guardrail feedback. ACP does not start the `octomind send` or webhook listeners used by `octomind run`. When a message arrives: 1. The monitor acquires the session (via a per-session exclusion lock, so it never races with a concurrent user prompt). 2. Surfaces the injected message to the client as a `UserMessageChunk` prefixed with its source label, e.g. `[schedule abc12345] run the test suite`. 3. Processes the message through the full AI pipeline (tool calls, streaming, etc.). 4. Streams the response back to the ACP client. 5. Returns the session to the pool. The prompt path also surfaces queued inbox work as source-labelled user chunks before the new user prompt. The monitor is event-driven, not polling: each loop it flushes due/idle schedule entries into the inbox, then waits on a `tokio::select!` over either the next schedule timer (`next_schedule_sleep`) or an inbox notification. It exits when the session is destroyed. ## MCP Elicitation When an MCP server asks the user for input mid-tool-call, Octomind forwards it to the client as an ACP `elicitation/create` request, scoped to the session and the tool call that triggered it. This requires the client to advertise `clientCapabilities.elicitation` in `initialize`: with the `form` capability, form requests are forwarded; URL requests also need the `url` capability. Without the capability the elicitation is declined. The client's `accept` (with content), `decline` or `cancel` answer goes back to the MCP server unchanged. ## Extension Commands Beyond the slash commands sent as prompts, a host can invoke session commands programmatically through the `octomind/command` ACP extension method. > The ACP library strips the leading `_` from a method name before routing, so the agent matches the method name without > the underscore prefix. On the wire, include the leading underscore and a leading slash in the command (unlike WebSocket commands): ```json {"jsonrpc":"2.0","id":8,"method":"_octomind/command","params":{"session_id":"editor-session","command":"/mcp","args":["list"]}} ``` **Request** (`CommandRequest`): | Field | Type | Notes | |-------|------|-------| | `session_id` | string | Session to run the command in | | `command` | string | Command to execute, e.g. `/info` | | `args` | string[] | Optional arguments (defaults to `[]`) | **Response** (`CommandResponse`): | Field | Type | Notes | |-------|------|-------| | `success` | bool | Whether the command executed successfully | | `output` | JSON \| null | Structured command output, when any | | `error` | string \| null | Error message when `success` is false | For example, a handled command can return: ```json {"jsonrpc":"2.0","id":8,"result":{"success":true,"output":null,"error":null}} ``` The command result maps to the response as: | Command result | Response | |----------------|----------| | Handled | `success: true`, `output: null`, `error: null` | | Handled with output | `success: true`, `output` = the command's JSON | | Exit | `success: true`, `output` = `{ "action": "exit" }` | | Treated as user input (unknown command) | `success: false`, `error` = `"Unknown command: "` | `/done` through the extension method compresses only: trailing `args` do not become a follow-up prompt. Use `/done` in `session/prompt` when you want trailing instructions processed. Session-context-dependent commands such as `/status` should also use `session/prompt`: the extension dispatcher does not establish the task-local session context required by those handlers. ```json {"jsonrpc":"2.0","id":10,"method":"session/prompt","params":{"sessionId":"editor-session","prompt":[{"type":"text","text":"/status agents"}]}} ``` ## Cancellation A `session/cancel` notification triggers `SessionCancellation::shutdown()` for the targeted session, signalling the in-flight operation to stop. A successful in-flight API call then returns `StopReason::Cancelled` rather than `StopReason::EndTurn`. Because the agent runs single-threaded inside a `LocalSet`, cancellation only takes effect at the prompt's next await point. Send cancellation without a JSON-RPC request ID while a prompt is running: ```json {"jsonrpc":"2.0","method":"session/cancel","params":{"sessionId":"editor-session"}} ``` Prompts and extension commands for the same session wait on the same exclusion lock. Cancellation signals the active operation; API failures may still return a JSON-RPC error rather than a successful cancelled result. ## Common questions | Symptom | What to check | |---------|---------------| | Command appears in the editor but fails | The advertised `session`, `workflow`, and `agents` entries have no handler. | | Host waits forever after `/exit` | `/exit` reports intent; close the subprocess stdin to end ACP. | | Webhook receives no requests | ACP has no `--hook` flag and starts no HTTP listener; use the run daemon. | | Extension method not found | Send `_octomind/command` on the wire and `/info` or another slash-prefixed command. | | No usage or verification data | Preserve `params._meta` on notifications and `result._meta` on results. | | No startup response | Inspect the three log files above and captured bootstrap stderr. | ## Agent Capabilities The `initialize` response advertises: - **Protocol version**: `ProtocolVersion::LATEST` (the newest version the bundled `agent_client_protocol` crate supports). - **Agent identity**: `agentInfo` = `{ name: "octomind", version: }`. - **Session management**: `loadSession: true` — both `session/new` and `session/load` (resume by session id) are supported. - **Prompt**: `image: true` (inline base64 images) and `embeddedContext: true` (embedded text resources and video — see [Prompt Content](#prompt-content)). - **MCP**: `http: true` — HTTP transport is advertised so clients offer HTTP MCP servers. SSE is **not** supported and such servers are skipped silently. - **Cancellation**: in-progress prompts can be cancelled. - **Extension commands**: `_meta["octomind.dev"] = { commands: true }` signals support for the `octomind/command` extension method (see [Extension Commands](#extension-commands)). ## Advertised slash commands After a session is created the agent sends an `AvailableCommandsUpdate` listing the slash commands the client may offer. Names are sent **without** the leading `/` (the client prepends it for display). This is the ACP-advertised set and is distinct from the full interactive CLI command set: | Command | Input hint | Description | |---------|-----------|-------------| | `help` | — | Show available commands | | `role` | `` | View or change current role | | `model` | `` | View or change current AI model | | `done` | — | Force-compress the conversation context; with a plugin that learns from sessions, also start lesson extraction in the background | | `info` | — | Display token and cost breakdown for this session | | `clear` | — | Clear the screen | | `copy` | — | Copy last response to clipboard | | `context` | `[all\|assistant\|user\|tool\|large]` | Display session context | | `list` | `[page]` | List all available sessions | | `session` | `[session_name]` | Advertised for client compatibility, but not implemented by the session command dispatcher | | `run` | `` | Execute a command | | `workflow` | ` [input]` | Advertised for client compatibility, but not implemented; run workflows via `octomind workflow ` instead | | `mcp` | `[info\|list\|full\|health\|dump\|validate]` | MCP server management | | `plan` | — | Display the current plan | | `prompt` | `[template_name]` | Manage prompt templates | | `image` | `` | Attach image to next message | | `video` | `` | Attach video to next message | | `loglevel` | `[none\|info\|debug]` | Set logging level | | `report` | `[day\|week\|month] [here]` | Generate detailed usage report for this session; `day`, `week` and `month` cover interactive CLI sessions per day and project, `here` only the current project | | `skill` | `[name\|pattern\|page]` | List, filter, or toggle skills | | `effort` | `[low\|medium\|high]` | View or change reasoning effort level | | `schedule` | `[list\|add\|remove\|edit] [] [when=...] [message=...] [every=...]` | Schedule a message to be injected at a future time | | `agents` | `[session]` | Advertised but unsupported by shared dispatch; use `/status` for async work | | `usage` | — | Show spend and quotas for the signed-in Octomind account | | `login` | — | Start the Octomind account sign-in flow | | `exit` | — | Report exit requested; the host still owns subprocess shutdown | Slash commands are sent as ordinary `session/prompt` text per the ACP spec. The agent intercepts any prompt beginning with `/` *before* the AI pipeline, runs it via the session command handler, and streams the result back as an `agent_message_chunk`. `/done` (optionally with trailing instructions, e.g. `/done now write tests`) is intercepted first: it compresses the conversation, reports a status chunk, and — if trailing instructions are present — falls through to process them as a normal prompt. For example, request MCP information through the prompt channel: ```json {"jsonrpc":"2.0","id":5,"method":"session/prompt","params":{"sessionId":"editor-session","prompt":[{"type":"text","text":"/mcp list"}]}} ``` Use the [Session Commands](../reference/02-session-commands.md) reference for argument examples. The advertised list is not a dispatch guarantee: `session`, `workflow`, and `agents` are unsupported. `/done` compresses and may start lesson extraction when a plugin provides it; despite its advertised description, this handler does not auto-commit. Remote `clear`/`copy` commands run on the agent host and do not clear your editor or copy to its clipboard. The unadvertised `/reply` returns the quoted reply as JSON text; it cannot fill the editor's input. ## Session context passed to downstream MCP servers This is **not** part of the ACP handshake with the host. It is client information Octomind sends downstream to MCP servers. Modern MCP requests carry it per request (each tool call names its own session, even on a shared connection); the legacy fallback carries it in `initialize`. In both cases, `capabilities.experimental.session` has this shape: ```json { "capabilities": { "experimental": { "session": { "role": "developer", "spec": "general", "project": "3f9a2c71d04b8e65", "session_id": "editor-session", "workdir": "/home/me/my-project", "git": true, "shell": true, "context_epoch": 1760697600000000000 } } } } ``` `project` is the hashed `octolib::utils::path_to_id` of `workdir`, `workdir` is the session's anchor directory, `git` says whether `workdir` itself is a git repository root, `shell` says whether the session may call that server's `shell` tool, and `context_epoch` (modern requests only) changes whenever the model loses tool results it was served. Field details and the rules servers follow are in [MCP Server Development](../dev/03-mcp-server-development.md#session-context-for-external-servers). ## See also - [ACP implementation](../../src/acp/agent.rs), [extension dispatch](../../src/acp/commands.rs), and [CLI flags](../../src/commands/acp.rs). - [Shared command handlers](../../src/session/chat/session/commands/mod.rs) and [ACP subprocess client](../../src/acp/driver.rs). - [WebSocket Server](01-websocket-server.md) — JSON frame transport and shared event shapes. - [Daemon Mode and Webhook Hooks](03-daemon-and-hooks.md) — external injection with `run`. - [Editor Integration](../usage/12-editor-integration.md) — editor setup. - [Session Commands](../reference/02-session-commands.md) — command arguments and examples.