Skip to main content

Module acp

Module acp 

Source
Expand description

AcpController: manages agent CLIs that speak the Agent Client Protocol (ACP).

ACP is a JSON-RPC 2.0 protocol over stdin/stdout — the “LSP for AI agents.” Instead of custom per-provider output parsing, ACP provides a standardized protocol for session management, prompting, and streaming events.

Lifecycle:

  1. Spawn the ACP agent process (e.g., gemini --acp, openclaw acp)
  2. Send initialize request, receive capabilities
  3. Send initialized notification
  4. Create a session via session/create
  5. For each user turn: send session/prompt, stream session/update notifications
  6. On close: send shutdown + exit

I/O model (similar to PersistentSubprocessController):

  • stdin_writer: sends JSON-RPC requests/notifications to agent
  • stdout_reader: reads JSON-RPC responses/notifications, persists + broadcasts
  • process_waiter: monitors process lifecycle

See: https://github.com/agentclientprotocol/agent-client-protocol

Structs§

AcpController
AcpController manages an ACP-speaking agent process.
AcpInner 🔒
Inner state protected by mutex.

Constants§

ACP_OUTPUT_SUBJECT
MPS file subject name for ACP output.
BLOCK_CONTROLLER_ACP
TURN_ENDED_BY_ERROR 🔒
Written to the output after an error that ended the turn (no prompt left running, or the session couldn’t open). The translator ends a turn on a stopReason; it can’t tell from an error alone, which may answer only a mid-turn steering prompt while the first one still runs.

Functions§

initialize_params 🔒
initialize: the protocol version and what this client can do. AgentMux offers no file system or terminal to the agent; it runs its own tools.
is_session_replay 🔒
Whether a line from the agent is part of a session/load replay: the agent streams the earlier conversation as session/updates before it answers the load, and the load’s own answer is not one of them.
meta_string_list 🔒
A meta value that is a string array, or a JSON string encoding one.
prompt_params 🔒
session/prompt params: the prompt is an array of content blocks.
reply_to_agent_request 🔒
The reply to a request the agent sends us, if json is one (it has both method and id). AgentMux approves tool use by default, as it does for every harness: the first allow_always option, else allow_once, else cancelled. Anything else (fs/*, terminal/*, which this client does not offer) gets “method not found”, so the agent never waits on us.
resolve_prompt_and_check_idle 🔒
Remove resolved_id from the set of outstanding (sent, not yet resolved) prompts and report whether the set is now EMPTY — i.e. whether every prompt sent so far has now been resolved, by either a real stopReason completion or a JSON-RPC error rejection, meaning the turn has genuinely ended. Extracted as a pure function over a plain HashSet so this exact logic is directly unit-testable; call sites wrap it with the shared mutex around the real outstanding_prompt_ids.
session_cwd 🔒
The absolute directory ACP’s session/new and session/load take as cwd: the pane’s working directory (~ expanded; a relative one resolved against the server’s, as Command::current_dir resolves it), else the directory the agent process itself starts in.
session_request 🔒
session/new, or session/load of resume when the agent can load one.