Overview
An agent-side connection to a client. This class provides the agent’s view of an ACP connection, allowing agents to communicate with clients. It implements theClient interface to provide methods for requesting permissions, accessing the file system, and sending session updates.
See protocol docs: Agent
Constructor
(conn: AgentSideConnection) => Agent
required
A function that creates an Agent handler to process incoming client requests
Stream
required
The bidirectional message stream for communication. Typically created using
ndJsonStream for stdio-based connections.Methods
sessionUpdate
session/cancel notification, as the agent may send final updates before responding with the cancelled stop reason.
SessionNotification
required
The session notification parameters containing updates about session progress
Promise<void>
A promise that resolves when the notification has been sent
requestPermission
session/cancel, it MUST respond to this request with RequestPermissionOutcome::Cancelled.
RequestPermissionRequest
required
The permission request parameters
RequestPermissionResponse
The user’s permission decision
readTextFile
fs.readTextFile capability. Allows the agent to access file contents within the client’s environment.
ReadTextFileRequest
required
The file read request parameters
ReadTextFileResponse
The file contents
writeTextFile
fs.writeTextFile capability. Allows the agent to create or modify files within the client’s environment.
WriteTextFileRequest
required
The file write request parameters
WriteTextFileResponse
An empty object on success
createTerminal
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”.
CreateTerminalRequest
required
The terminal creation parameters
TerminalHandle
A handle to control and monitor the terminal
extMethod
string
required
The extension method name
Record<string, unknown>
required
The extension method parameters
Record<string, unknown>
The extension method response
extNotification
string
required
The extension notification name
Record<string, unknown>
required
The extension notification parameters
Promise<void>
A promise that resolves when the notification has been sent
Properties
signal
- Listen for connection closure:
connection.signal.addEventListener('abort', () => {...}) - Check connection status synchronously:
if (connection.signal.aborted) {...} - Pass to other APIs (fetch, setTimeout) for automatic cancellation