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
function
required
A factory function that creates an Agent handler to process incoming client requests. The function receives the
AgentSideConnection instance as a parameter.Stream
required
The bidirectional message stream for communication. Typically created using
ndJsonStream() for stdio-based connections.Example
Methods
sessionUpdate
Sends session update notifications to the client.SessionNotification
required
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.RequestPermissionRequest
required
The permission request containing the session ID, tool call details, and available options
RequestPermissionOutcome
required
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.string
required
The session ID making the request
string
required
Absolute path to the file to read
string
required
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.string
required
The session ID making the request
string
required
Absolute path to the file to write
string
required
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.string
required
The session ID creating the terminal
string
required
The command to execute
string[]
Optional command arguments
string
Optional working directory for the command
object
required
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.string
required
The extension method name
Record<string, unknown>
required
The method parameters
extNotification
Sends an arbitrary notification that is not part of the ACP specification.string
required
The extension notification name
Record<string, unknown>
required
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