ws_transport
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| WebSocketTransportError aclientp.ws_transport The WebSocket connection to the ACP server could not be opened. |
🛈 DocStrings¶
Client side of ACP's WebSocket transport (experimental).
Implements the WebSocket mode of the "Streamable HTTP & WebSocket Transport" RFD: a
GET with Upgrade: websocket on the agent's /acp endpoint (the server answers
with Acp-Connection-Id), then one JSON-RPC message per text frame in both directions.
Binary frames are ignored. The first message must still be initialize.
Like :func:aclientp.http_transport.connect_http_transport, the transport is exposed as
byte streams carrying newline-delimited JSON-RPC. :func:connect_remote_transport picks
the transport from the URL scheme.
MAX_MESSAGE_BYTES
module-attribute
¶
Largest message accepted from the server (file contents and images can be large).
WebSocketTransportError
¶
connect_remote_transport
async
¶
connect_remote_transport(
url: str, *, headers: Mapping[str, str] | None = None
) -> AsyncGenerator[tuple[ByteReceiveStream, ByteSendStream]]
Connect to a remote agent, choosing the transport by URL scheme.
ws:// / wss:// use the WebSocket transport, http:// / https:// the
Streamable HTTP transport. Both yield newline-delimited JSON-RPC byte streams.
Raises:
| Type | Description |
|---|---|
ValueError
|
The URL has another scheme. |
Source code in src/aclientp/ws_transport.py
connect_websocket_transport
async
¶
connect_websocket_transport(
url: str, *, headers: Mapping[str, str] | None = None, open_timeout: float = 30.0
) -> AsyncGenerator[tuple[ByteReceiveStream, ByteSendStream]]
Connect to an ACP server's WebSocket endpoint (ws:// or wss://).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The |
required |
headers
|
Mapping[str, str] | None
|
Extra headers for the upgrade request (e.g. authentication). |
None
|
open_timeout
|
float
|
Timeout for the opening handshake. |
30.0
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[tuple[ByteReceiveStream, ByteSendStream]]
|
(reader, writer) byte streams. |
Raises:
| Type | Description |
|---|---|
WebSocketTransportError
|
The server rejected the upgrade or is unreachable. |