Overview
TheClient abstract class defines the core interface that clients must implement to handle requests from agents in the ACP protocol. Clients are responsible for managing the user interface, handling file system operations, managing terminals, requesting user permissions, and displaying session updates.
Class Definition
- Permission requests from agents
- Session update notifications and progress
- File system operations (reading and writing files)
- Terminal management (creation, output, termination)
Methods
requestPermission
Requests permission from the user for a tool call operation.session/cancel, it MUST respond to this request with RequestPermissionOutcome::Cancelled.
The permission request containing tool call details and available options
Contains the user’s decision (allow, deny, or cancelled)
sessionUpdate
Handles session update notifications from the agent.session/cancel notification, as the agent may send final updates before responding with the cancelled stop reason.
Notification containing session updates, messages, and tool call information
File System Methods
These methods are only available if the client advertises the corresponding file system capabilities.writeTextFile
Writes content to a text file in the client’s file system.fs.writeTextFile capability. Allows the agent to create or modify files within the client’s environment.
Request containing the file path and content to write
Returns
null if not supported, otherwise confirms the write operationreadTextFile
Reads content from a text file in the client’s file system.fs.readTextFile capability. Allows the agent to access file contents within the client’s environment.
Request containing the file path to read
Returns
null if not supported, otherwise contains the file contentTerminal Methods
These methods are only available if the client advertises theterminal capability as true.
createTerminal
Creates a new terminal to execute a command.terminal capability is set to true. The Agent must call releaseTerminal when done with the terminal to free resources.
Request containing the command to execute and terminal configuration
Returns
null if not supported, otherwise contains the terminal IDterminalOutput
Gets the current output and exit status of a terminal.Request containing the session ID and terminal ID
Returns
null if not supported, otherwise contains stdout, stderr, and exit statusreleaseTerminal
Releases a terminal and frees all associated resources.Request containing the session ID and terminal ID to release
Returns
null if not supported, otherwise confirms the terminal was releasedwaitForTerminalExit
Waits for a terminal command to exit and returns its exit status.Request containing the session ID and terminal ID
Returns
null if not supported, otherwise contains the exit code and signalkillTerminal
Kills a terminal command without releasing the terminal.releaseTerminal also kills the command, this method keeps the terminal ID valid so it can be used with other methods.
Useful for implementing command timeouts that terminate the command and then retrieve the final output.
Note: Call releaseTerminal when the terminal is no longer needed.
Request containing the session ID and terminal ID to kill
Returns
null if not supported, otherwise confirms the terminal was killedExtension Methods
extMethod
Allows the Agent to send an arbitrary request that is not part of the ACP spec._ prefix, so callers should include the leading underscore explicitly when needed.
The extension method name (should start with
_ for ACP-reserved extensions)Arbitrary parameters for the extension method
Returns
null if not supported, otherwise the extension method responseextNotification
Allows the Agent to send an arbitrary notification that is not part of the ACP spec.The extension notification name
Arbitrary parameters for the extension notification
Usage Example
Capability Advertisement
Clients should advertise their capabilities during the initialization phase:See Also
- Agent - The agent interface that clients communicate with
- ClientSideConnection - Implementation of client-side connections
- Connection - Base connection class for JSON-RPC communication