Skip to content

ACP agents ​

The Agent Client Protocol is JSON-RPC 2.0 over an agent's stdio. Any agent that speaks version 1 becomes a provider through a spec, with no backend of its own. Chat, thread and wire work as for the built-in providers.

ts
import { createAcpProvider, ModelCatalog } from '@adecore/agents/providers';

const exampleProvider = createAcpProvider({
    kind: 'example',
    name: 'Example',
    command: 'example',
    args: ['agent', 'stdio'],
    catalog: new ModelCatalog(exampleModels),
    modes: { supervised: ['default'], 'auto-accept-edits': ['accept-edits'], 'full-access': ['bypass'] },
    authMethod: 'api-key',
    loginHint: 'Run `example login` in a terminal.',
    capabilities: { reportsCost: true, reportsContextWindow: true }
});

Put it in the ProviderRegistry beside the others. A kind is any name the host picks.

The spec ​

createAcpProvider takes the fields the ACP backend needs plus the provider fields.

Field
kind, nameThe provider's kind and its display name, also used in backend notes and errors.
command, argsThe executable and arguments that start the ACP agent on its stdio.
catalogThe models a person picks from. The selection's slug is the agent's model id, unless model(selection) maps it. null leaves the choice to the agent.
envVariables set over the launch environment.
modesThe agent's mode ids per runtime mode, best first.
authMethod, loginHintThe method passed to authenticate when the agent needs a login, and the error text when there is no method.
clientHow the host names itself in initialize (AcpClientInfo).
onSession(info)What each session offers. See Models.
onUsage(report)The tokens of every turn that reports them, with session, folder and model.
usageLogA folder to log those turns to. See Usage.
allowToolsArgs(serverName)The arguments put on the agent's line for each server that allows its tools, for an agent whose permission requests name no server (Copilot's --allow-tool=<server>).
executable, terminal, launch, leanOneShotArgsWhat the provider says of its terminal, the host's launch additions and its short one-shot run. See Providers.
accountProbefalse drops askAccount and refreshModels, so the host's own reader checks accounts.
nowThe clock that dates the models a session reports, for refreshModels. Absent is Date.now.
adoptModelsfalse keeps catalog instead of adopting the models a session reports.
catalogStorePersists what the agent reported, so a restarted host offers it at once (AcpCatalogStore). See Models.
onCommands(commands)The session's slash commands, without the slash, each time the agent lists them.
adoptTitlestrue takes the agent's session titles as the chat's suggested title. Absent leaves naming to the host.
steerHow a message joins the running turn. interject sends Grok's _x.ai/interject, prompt another session/prompt (agy 1.5). Absent leaves the backend without steerTurn, so a message queues. Set capabilities.steer beside it. See Steering.
repliesEndOnUsagetrue for an agent whose every reply ends on a usage_update, also one it starts by itself with no prompt open. See Turns the agent opens.
repliesEndOnQuiettrue for an agent that starts replies by itself and ends them with no signal, as Grok does when a background task ends. See Turns the agent opens.
silentPromptstrue for an agent that can leave a prompt open with no update at all. Every update of the prompt starts the host's quiet watch again (quiet.watch) while none of its calls runs and no request waits, so a silence after the first output also gets the host's note. Nothing stops the agent.
cancelsIdletrue sends session/cancel for a stop with no prompt open, for an agent that stops the commands it runs on past its turn on it. Absent sends nothing then.
mcpMCP transports (http, sse) the agent takes although its initialize does not advertise them.
mcpToolPrefixWhat the name of a tool call that runs an MCP tool starts with, before <server>_<tool>, for an agent that marks the call no other way. See Calls the host guards.
daemonFlagThe key of a command's input that marks one the agent runs on past its turn. See Turns the agent opens.
minVersionThe oldest x.y.z the agent may name in initialize.agentInfo.version, with the updateHint an older one fails the start with. A version that is not x.y.z passes.
onContextReport()Called once per process, at the first usage_update that names the context window.
capabilitiesOverrides on top of the ACP defaults and what the agent showed (see Capabilities).
resumeCommand, home, detect, oneShotArgs, oneShotApart, oneShotEnv, oneShotStdinArgs, firstPromptArgs, enabled, ignoresProjectConfigAs on any ChatProvider. Without firstPromptArgs the agent is chat only. Without detect the host runs --version.

A session ​

start runs initialize and opens the session before the first turn. The backend accepts only protocol version 1. The client advertises no file system or terminal, so the agent uses its own tools.

Every session request (session/new, session/load, session/resume) names the launch's mcpServers, each a ChatMcpServer with a name, a url, its headers or a tokenVariable and a transport (http by default, or sse). A server goes along only when the agent advertises that transport in agentCapabilities.mcpCapabilities, or the spec's mcp names it. Otherwise the session starts without it, and the thread gets a warning note that names it. An agent expands no variable in a session request, so a tokenVariable becomes an Authorization: Bearer header holding the value of that variable in the launch's environment.

A chat with an agent session to continue uses session/resume (if the agent advertises sessionCapabilities.resume) or session/load (if it advertises loadSession). The backend drops the history a load replays, since the thread already holds it. An agent that marks replayed frames with _meta.isReplay (Grok) ends the replay at its first unmarked frame, so what it says live before the load answers reaches the thread. If the agent supports neither or refuses, it gets a new session and the thread gets a note. BackendLaunch.folders go along as additionalDirectories when the agent supports them.

ACP has no system prompt. The launch's instructions go before the first prompt of a new session. resumeInstructions and resumeNote go before the first prompt of a resumed one.

A prompt is one text block with attachments named by path. Images go as image blocks when the agent advertises promptCapabilities.image. With promptCapabilities.embeddedContext, small text files mentioned with @ inside the chat's folders also go as resource blocks. Everything else stays a path for the agent to open.

When a session request answers that authentication is required, the backend calls authenticate with authMethod and retries once. Without a method, the start fails with loginHint. When the agent refuses authenticate, whatever the error code, the start fails with the agent's own message followed by loginHint.

Modes ​

The runtime mode picks the first id in modes the agent offers, through session/set_mode or a mode config option. Without a matching id it falls to the next narrower runtime mode, down to supervised, never wider. The start fails if the agent already runs in a wider mode and offers nothing narrower.

The agent asks with session/request_permission for what its mode does not allow. The backend answers part of that itself, so every runtime mode holds:

Runtime modeAnswered with allow once, without asking
supervisedNothing
auto-accept-editsTool kinds read, search, think, edit, move
autoThe same, and fetch
full-accessEverything

Everything else becomes an approval in the thread.

Calls the host guards ​

A server in mcpServers with allowTools: true checks each call itself, so its tools run without asking in every runtime mode. The backend knows a call's server only where the agent marks it. Antigravity marks it in the tool call's _meta.mcp.server. Grok puts it in the <server>__<tool> name of its use_tool, which the backend matches against the launch's own server names, the longest first. With mcpToolPrefix, a call whose name is the prefix followed by <server>_<tool> (agy 1.5's mcp_files_read) is matched the same way; a name that starts with no server of the launch stays an ordinary call and asks. A call of a kind other than other, or one with _meta.is_mcp_tool_call: false, is never an MCP call. The mark of a call holds for the permission request that names only its toolCallId. Copilot names no server, so a host allows its tools with Copilot's own --allow-tool=<server>.

ACP does not tell a client which servers an agent loaded. A server of the agent's own configuration with the same name as one in mcpServers gets the same calls allowed, so give a server with allowTools a name no configuration uses. The backend refuses the clashes it can see. start throws before the agent runs when two servers in mcpServers share a name, or when one name is another followed by __, since own__events__delete could then be a tool of either. A server the agent could not take (see A session) never counts, so a call to a server of that name asks.

Turns, approvals and cancels ​

A turn is one session/prompt and ends on its response. stopReason maps onto the turn:

stopReasonTurn
end_turnDone
cancelledAborted after interrupt, else done
max_tokens, max_turn_requestsDone, with a warning note
refusalError

A failed request ends the turn as an error and leaves the process running.

ACP defines no limits. The backend recognizes these agent-specific reports and ends the turn as an error with a limit:

AgentWhat it sendslimit
Grok CLIsession/prompt fails with -32003 whose data names subscription:free-usage-exhaustedusage, without a reset
Grok CLIsession/prompt fails with -32003 otherwise (a 429 after its own retry)overload
Grok CLIsession/prompt fails with -32603 and http_status 529, a 5xx that says overloaded, or the stream error overloaded_error or service_unavailable_erroroverload
AntigravityA message that starts Usage Limit Reached, then end_turnusage, with the reset the message names. The message becomes the turn's error.

Any other failure stays an error without a limit.

An approval offers allow, allow always (only when the agent has allow_always) and deny. They map to the agent's allow_once, allow_always and reject_once or reject_always options. A missing option falls to the narrower one. A denial without any reject option answers cancelled.

interrupt cancels every open permission request and question and sends session/cancel. The turn ends when the agent answers the prompt. With no prompt open, it cancels the open requests the same way, withdraws their cards and ends the turn the agent opened itself at once; it sends session/cancel only with cancelsIdle.

Turns the agent opens ​

An agent may speak with no prompt open. Copilot's root agent says when it starts and goes idle, and that idle ends its turn. With repliesEndOnUsage, every reply ends on a usage_update: output with no prompt open is a turn of the agent's own, and it ends once WAKE_QUIET_MS (3 seconds) pass after a usage_update with no new output. Output in that time, a tool that ends included, keeps the turn open until the next usage_update. With repliesEndOnQuiet, such a turn ends once WAKE_QUIET_MS pass with no update at all, while no tool it started still runs and no permission request or question waits; answering one starts the wait again. The backend's timers run on BackendLaunch.clock.

With daemonFlag, a command whose input sets that key and still runs when its prompt answers is background work (background.started under the call's id), ended by the tool_call_update that completes or fails it. With cancelsIdle, stopTask stops it with session/cancel, which stops every such command; with a prompt open it answers stop.refused, since the cancel would end that prompt too.

Steering ​

With steer: 'interject', steerTurn sends _x.ai/interject with the session and the message's text, the preamble in front and attachments named by path. Grok CLI answers queued at once. A running tool finishes, the model reads the message at its next step, and the one prompt response still ends the turn, so no session/cancel goes out. steerTurn resolves false without a prompt in flight, after interrupt, and when the agent refuses the request or answers another status.

With steer: 'prompt', steerTurn sends the message as another session/prompt, attachments and mentions included as in any prompt. agy 1.5 answers the running prompt with end_turn at once and works on with both messages, a running command included. That answer ends nothing: the turn ends on the answer of the last prompt sent, and steerTurn resolves true once the agent answered either. Each answer reports its own usage to onUsage.

Questions ​

Two agents ask questions outside the protocol. Both become a question.requested, answered with respondQuestion and turned down with declineRequest:

  • Grok CLI sends _x.ai/ask_user_question, with options and multiSelect per question.
  • Antigravity asks one question per session/request_permission, on a tool call whose id starts with interaction_. It takes one choice only. A free-text answer turns the question down with a warning note. No runtime mode answers it.

Updates ​

sessionUpdateBackend event
agent_message_chunktext.delta, then one text.done per message. Images and resources are left out.
agent_thought_chunkthinking.delta and thinking.done
tool_call, tool_call_updatetool.started on each change, tool.done once completed or failed. The kind names the row (execute is Bash, read is Read, search is Grep, fetch is WebFetch or WebSearch). A one-file diff draws as Edit, Write or MultiEdit, several files as unified changes. A call the agent marks as an MCP tool is named mcp__<server>__<tool>, with only the tool's arguments as its input. Any other call keeps its title in description, also when the tool has an argument of that name.
planA TodoWrite row with the whole plan
available_commands_updateThe chat's slash commands
current_mode_updatepermissions, with the runtime mode that agent mode falls under
config_option_updatemodel and permissions for the model and mode options
usage_updateusage with the context tokens and window, and the cost when in USD
session_info_updateIgnored unless the spec sets adoptTitles. Then the title, cut to SUGGESTED_TITLE_LIMIT, becomes the suggested title. A title that only repeats the start of a sent prompt is left out.

The backend ignores other updates and unknown fields. Agent requests the backend does not handle, file system and terminal included, get "method not found".

Models ​

What onSession gets names the session, the agent (name, title and version), its models and its modes. The models and the modes each list their options, and a configId names the config option that picks one, or is null where the agent takes session/set_model or session/set_mode.

The models of that report hold the models a session offers, read from a model config option or the older models field. The backend switches through the option or session/set_model. A model the agent does not offer keeps the agent's own, and the thread gets a note. Its thoughtLevel holds the reasoning effort as a list of choices. After the model, the backend sets the selection's effort when the agent offers that value for the model.

The provider adopts the models a session reports into its catalog (ModelCatalog.adopt). The agent's current model becomes the default, the rest follow in the agent's order and names. A reported reasoning effort becomes the profile's effort option, with the agent's current value as default. A session without models leaves the catalog as it was. Account checks open sessions too, so the list is usually there before the first chat. Set adoptModels: false to keep the host's catalog. onSession still sees every session.

An agent's list can change on the vendor's side while no chat runs. refreshModels(command, env, refresh) takes a ModelRefresh, { maxAgeMs, spawn? }, and opens a session only to read the models, unless a session reported them less than maxAgeMs ago by the spec's now clock, and answers whether it asked. Since the session it opens may stay in the agent's history, a host calls it at moments a person comes back with an age of hours, never in a loop. A provider with adoptModels: false or accountProbe: false has no refreshModels.

The provider calls its onChange listeners when the models change. ProviderRegistry.onChange passes that on with the provider's kind, so a host can send clients the new list.

With catalogStore the provider saves what the agent reported on each change, and a new provider with the same store starts from it. load() returns what save(value) last got. The value only needs to survive as JSON. A store that throws only loses the cache.

ts
const store: AcpCatalogStore = {
    load: () => (existsSync(file) ? JSON.parse(readFileSync(file, 'utf8')) : null),
    save: (value) => writeFileSync(file, JSON.stringify(value))
};

Capabilities ​

A provider starts from the ACP defaults and adds what its agent showed in sessions and account checks. The spec's capabilities go on top. catalogStore keeps them with the models, and a change calls onChange. The object changes in place, so a copy of the provider still reads current values.

The agentCapability
Sends a usage_update with its context windowreportsContextWindow: true
Lists a compact commandcompaction: 'prompt': the backend's compact() sends /compact as a prompt. The turn ends as one compaction with the size before and the agent's last count, in place of the agent's text; a turn that does not end with end_turn keeps its text and leaves no marker
Lists a goal commandgoals: 'command': the goal goes to the agent as /goal

An agent that reports a fold in a notification of its own, as Grok's _x.ai/session_notification with auto_compact_completed does, gives that compaction its sizes. A list without compact sets compaction back to none. A model entry with _meta.totalContextTokens gets that size as its context window, so the meter has a size before the first usage_update.

Usage ​

A session/prompt response may carry usage, an unstable part of the protocol. The backend reads it into the turn's usage, with thought tokens as reasoning inside output. A cancelled turn still reports what it spent.

Every turn with usage goes to onUsage. With usageLog, the provider also appends a hostUsageLine per turn to a file per session in that folder. The host then adds a usage root for that folder under a provider in USAGE_PROVIDERS (such as copilot). An agent whose own usage files the scanner already reads (Grok) logs nothing, so no turn counts twice.

An agent without usage_update may send the context size in _meta.totalTokens, as Grok CLI does. The backend uses that as the context tokens until a usage_update arrives.

Accounts ​

ACP cannot say who is signed in, so the provider's account check opens a session to find out. It runs initialize and session/new in the account's environment, in an empty temporary folder. A session means signed in. The "authentication required" code (-32000) means signed out. Any other error, an exit or 20 seconds without answer fails the check. The probe never calls authenticate, which could start a login. It deletes the session when the agent supports session/delete, which keeps it out of the history the agent lists, and otherwise closes it when the agent supports session/close. An agent with neither may keep an empty session in its history. The session's offer goes to onSession and onCommands, as from a chat.

A reading carries no email or plan.

What it leaves out ​

Plan limits, file system and terminal client capabilities, MCP servers over stdio, elicitation/create, notices and compaction updates. compaction is none unless the agent lists a compact command.

@adecore/agents/testing has fakeAcpWith, an agent for backend tests that can require a login (authMethod) or refuse one where no browser opens (noBrowser), support session/close (closeSession) or session/delete (deleteSession), report usage per prompt (turnUsage), name a version in initialize (version), name context windows (contextWindows), list slash commands (commands) or take MCP servers over HTTP or SSE (mcp). A prompt mcp: <server> <tool> asks permission for a tool of that server as Antigravity marks it, and use_tool: <server>__<tool> as Grok does. A prompt continued sends one message that goes on under its messageId after a thought.

Licenses and third-party notices are listed in each package.