Overview
TheAgentSideConnection class provides the agent’s view of an ACP connection, allowing agents to communicate with clients. It handles the bidirectional JSON-RPC communication and provides methods for sending session updates, requesting permissions, and accessing client capabilities.
See protocol docs: Agent
Constructor
A factory function that creates an Agent handler to process incoming client requests. The function receives the
AgentSideConnection instance as a parameter.The bidirectional message stream for communication. Typically created using
ndJsonStream() for stdio-based connections.Example
Methods
sessionUpdate
Sends session update notifications to the client.The session update to send, containing the session ID and update content (message chunks, tool calls, etc.)
Clients SHOULD continue accepting tool call updates even after sending a
session/cancel notification, as the agent may send final updates before responding with the cancelled stop reason.requestPermission
Requests permission from the user for a tool call operation.The permission request containing the session ID, tool call details, and available options
The user’s decision, including the selected option ID or cancellation status
readTextFile
Reads content from a text file in the client’s file system.The session ID making the request
Absolute path to the file to read
The file contents as a string
Only available if the client advertises the
fs.readTextFile capability during initialization.writeTextFile
Writes content to a text file in the client’s file system.The session ID making the request
Absolute path to the file to write
The content to write to the file
Only available if the client advertises the
fs.writeTextFile capability during initialization.createTerminal
Executes a command in a new terminal.The session ID creating the terminal
The command to execute
Optional command arguments
Optional working directory for the command
A handle to control and monitor the terminal
TerminalHandle that can be used to get output, wait for exit, kill the command, or release the terminal.
The terminal can also be embedded in tool calls by using its ID in ToolCallContent with type “terminal”.
extMethod
Sends an arbitrary request that is not part of the ACP specification.The extension method name
The method parameters
extNotification
Sends an arbitrary notification that is not part of the ACP specification.The extension notification name
The notification parameters
Properties
signal
AnAbortSignal that aborts when the connection closes.
- Listen for connection closure
- Check connection status synchronously
- Pass to other APIs (fetch, setTimeout) for automatic cancellation