Skip to main content
Commands, package names, and image names on this page come from the open-source project that Mibyan Desktop is built on, and can differ from the Mibyan Desktop installer. For the supported Mibyan install and update path, see Install and update.
Mibyan ships three protocols for driving the agent from external programs — IDE plugins, custom UIs, CI pipelines, embedded sub-agents. Pick the one that matches your transport and consumer. All three drive the same AIAgent core. They differ only in wire format and which set of features they expose.

ACP (Agent Client Protocol)

mibyan acp starts a stdio JSON-RPC server speaking ACP. Used in production by VS Code (Zed Industries’ ACP extension), Zed, and any JetBrains IDE with an ACP plugin. Capabilities exposed: session creation, prompt submission, streaming agent message chunks, tool-call events, permission requests, session fork, cancel, and authentication. Tool output is rendered into ACP Diff/ToolCall content blocks the IDE understands. Full lifecycle, event bridge, and approval flow: ACP Internals.

TUI Gateway JSON-RPC

tui_gateway/server.py is the protocol the Ink TUI (mibyan --tui) and the embedded dashboard PTY bridge talk to. Any external host can speak the same protocol over stdio (or WebSocket via tui_gateway/ws.py).

Method catalog (selected)

session.active_list, session.activate, and session.close are the process-local live-session controls used by the TUI session switcher. Use session.list / /resume for saved transcript discovery; use the active-session methods only for sessions that are currently open in the TUI gateway process. Within one authenticated gateway, resuming or activating a live session attaches another event subscriber rather than replacing the previous connection. Streaming and terminal events go to all attached clients; disconnecting one client does not end a session another client is viewing. Existing submit exclusivity and configured busy-input policy remain in force. Attached clients can steer the session’s subagents; browser-controller results still require the connection that registered that controller. This does not enable independent gateway processes to write the same session, nor does it imply durable prompt admission across an owner restart.

Model overrides on session.create

session.create accepts per-session model / provider overrides. A pair the provider cannot serve (model: gpt-5.5 with provider: anthropic, or with no provider when the profile’s configured provider is Anthropic) is refused up front with JSON-RPC code -32602 instead of minting a session whose first turn fails at the provider; error.data carries model, provider and up to five suggestions from that provider’s catalog, and error.message repeats them. The check is offline and only refuses names Mibyan knows belong elsewhere: custom endpoints (custom, custom:<name>), aggregators (OpenRouter, Nous, …), models in the provider’s own family that the curated list has not caught up with, and names no catalog lists are all accepted as before.

Rewinding history on prompt.submit

A rewind / edit / regenerate is a prompt.submit that drops part of the stored transcript before running the new turn. Because that write is a destructive rewrite of the session’s durable rows, the gateway honors it only when the client states its intent: A truncation parameter without confirm_truncate is refused with code 4004 or 4029 and nothing is written. Hosts that implement rewind must set the flag at the moment the user asks for it, and must never keep truncation parameters in state across ordinary submits. Prefer truncate_before_row_id (from resume row_id / _row_id) over ordinals; keep the ordinal as a back-compat / optimistic-row path only when no durable id is available yet. A truncating submit is never absorbed by the busy-input policy. While a turn is still running, an ordinary prompt.submit is steered, redirected, or queued (display.busy_input_mode), but a rewind / edit / regenerate refuses with code 4009 (session busy) instead — queueing it would drop the history cut and run the edit as a plain follow-up after the un-edited turn. Hosts call session.interrupt and retry the same submit until it lands; the Desktop app does this automatically, so editing a message while Mibyan is still thinking stops the live turn and reruns from the edited prompt. On a successful truncating submit against a durable session, the prompt.submit result additionally carries survivor_user_row_ids — the fresh post-rewrite row IDs of the surviving user turns, in visible-user-ordinal order. The rewrite re-inserts the kept prefix as new rows, so every row ID the host cached before the rewind is stale afterward; rebind cached IDs from this list (a null entry means that turn has no durable ID — drop the cached one) or the next rewind targeting an older surviving turn will be refused with 4018.

Events streamed back

message.delta, message.complete, tool.start, tool.generating, tool.complete, gateway.ready, request.cancel, plus session lifecycle and error events.

Server→client requests (questions the agent asks you)

Approvals, clarify questions, sudo/secret prompts, vault unlock, MCP setup and the desktop read/act bridges are JSON-RPC requests from the gateway to the client, not events. The frame carries a string id, and the client answers with a normal JSON-RPC response bearing the same id:
Methods: approval → {choice}; clarify → {answers} keyed by question id, or {} to cancel (clarify.lock locks one answer early; null skips that question); sudo, secret, vault.code, vault.unlock_prompt → {value}; connection → {settled_by, targets} (the manage_connections card: one outcome per target); terminal.read, window.read, preview.act, tour → {value} (JSON text). Respond with a JSON-RPC error (-32601) for a method your host does not implement so the agent fails fast instead of waiting out the timeout. Advertise that you answer them (breaking for existing WebSocket integrations). Once per connection, after gateway.ready, call client.capabilities with {"server_requests": true}; the result lists the request methods this backend may send. A WebSocket client that never does is treated as a build that predates server→client requests: the gateway fails every such request for it immediately (the agent sees the same “no answer” an error response produces; an approval is withdrawn, not denied) instead of stalling for the full deadline. There is no grace path — a third-party WebSocket client that answered clarify/approval/sudo/… before this change but never sends client.capabilities now has every such request refused until it adds the one call. A session with no client attached is not affected — its open questions wait in open_requests for the reconnect replay. The stdio TUI, the desktop app and the dashboard advertise through the shared JsonRpcRequestChannel. When the gateway withdraws a question (timeout, interrupt, answered from another surface) it emits request.cancel { id, method, reason }; clear only the matching prompt. session.resume / session.activate results and session.events.since carry open_requests — the still-open frames — so a reconnecting client re-renders (and can still answer) them.

Rebuilding the in-flight turn on reconnect

session.resume / session.activate results carry inflight — the turn still running (or the retained failed one) that history does not hold yet: user, assistant streamed so far, streaming, mid-turn corrections, and error fields. When the turn was started by the gateway rather than typed by a person (a background-process completion, an async delegation result, a hidden scaffolding prompt) inflight also carries the same display_kind / display_metadata the persisted messages row will get, so a client renders the live prompt exactly as it will render history after the turn lands — a process_complete timeline marker with display_metadata.display_text, nothing at all for hidden. Both fields are absent for genuine user input; never infer origin from the prompt text (a user quoting a marker string is still a user).

Pi-style RPC mapping

Every command in the Pi-mono RPC spec (issue #360) has a TUI-gateway equivalent:

OpenAI-Compatible API Server

gateway/platforms/api_server.py exposes mibyan over HTTP for any client that already speaks the OpenAI format. Useful when you want a web frontend, a curl-driven CI runner, or a non-Python consumer. Endpoints:
Setup, headers (X-Mibyan-Session-Id, X-Mibyan-Session-Key), and frontend wiring: API Server. Browser extensions can opt into the disabled-by-default controller protocol to drive the exact browser session that opened the Mibyan conversation. The API and dashboard transports share one principal-bound broker and one explicit capability allowlist; see Browser-extension control.

Model catalog surfaces

The OpenAI-compatible API intentionally keeps GET /v1/models minimal: it is the compatibility endpoint frontends expect, not the full Mibyan provider/model picker catalog. If an external control plane needs Mibyan’ curated provider rows, per-model pricing, or capability hints, use one of the authenticated picker surfaces:
  • API server REST: GET /api/model/options with the API-server bearer key
  • Dashboard backend REST: GET /api/model/options with X-Mibyan-Session-Token
  • TUI gateway RPC: model.options
Those surfaces share the same payload builder and the same custom-provider probe policy:
  • Normal open: probe only the current custom provider so offline saved endpoints do not stall the picker.
  • Explicit refresh (refresh=1 or refresh: true): bust the provider-model cache and probe all saved custom providers so live catalogs repopulate fully.
Use /v1/models for OpenAI-client compatibility. Use /api/model/options or model.options when you are building a Mibyan-aware model picker. POST /v1/runs/{id}/steer is the HTTP equivalent of Mibyan /steer: it does not create a new user turn or immediately rewrite the assistant output already in flight. Instead, the text is appended to the live run and becomes visible to the agent after the next tool boundary, so it can course-correct without discarding the current tool-calling loop. /v1/runs/{id}/steer is only accepted while the run status is running. Queued, approval-paused, stopping, cancelled, failed, and completed runs return 409 run_not_accepting_steer, even if the server still retains internal agent references during cooperative shutdown. A 200 (and the run.steered event) means the text was queued, not that the agent consumed it. If a steer lands after the agent’s final response — with no later tool boundary to deliver it at — the undelivered text is returned as pending_steer on the terminal event (run.completed, run.failed, or run.cancelled) and run status, so the client can replay it as the next user turn instead of losing it.

Terminal run status

The terminal status of a run is derived from how the agent’s turn actually ended, and the terminal event name always matches it (run.<status>): A run is never reported as completed with completed: false or partial: true in the same payload. The same rule applies to /api/sessions/{id}/chat/stream, whose assistant.completed payload carries the real completed / partial / interrupted flags and whose terminal event is run.completed, run.failed, or run.cancelled.

Which one should I use?

  • You’re writing an IDE plugin and the IDE already speaks ACP → ACP. Zero protocol work on the IDE side.
  • You’re writing a custom desktop / web / TUI host and want every Mibyan feature (slash commands, approvals, clarify, multi-agent, session branching) → TUI gateway JSON-RPC.
  • You want any OpenAI-compatible frontend, a language-agnostic HTTP client, or curl-driven automation → API server.
  • You want a Python in-process embed without a subprocess → import run_agent.AIAgent directly. See Agent Loop.

Model hot-swapping

Mid-session model switching works on every surface — it’s the /model slash command under the hood.
  • CLI / TUI: /model claude-sonnet-4 or /model openrouter:anthropic/claude-sonnet-4.6
  • TUI gateway RPC: command.dispatch with {"command": "/model claude-sonnet-4"}
  • ACP: the IDE sends the slash command as a prompt; the agent dispatches it
  • API server: include a model field in the request body
Provider-aware resolution (the same model name picks the right format for whatever provider you’re on) is built in. See mibyan_cli/model_switch.py.

A note on --mode rpc

Mibyan does not have a --mode rpc flag. The three protocols above already cover the use cases — ACP for IDE-protocol clients, the TUI gateway for stdio JSON-RPC hosts, and the API server for HTTP. If you find a real gap that none of them fill, open an issue with the concrete consumer you’re building.