http_transport
Class info¶
Classes¶
| Name | Children | Inherits |
|---|---|---|
| HttpTransportError aclientp.http_transport The ACP server rejected the connection or became unreachable. |
🛈 DocStrings¶
Client side of ACP's Streamable HTTP transport (experimental).
Implements the client of the "Streamable HTTP & WebSocket Transport" RFD
(docs/rfds/streamable-http-websocket-transport.mdx in the ACP repository), behaving
like the TypeScript SDK's createHttpStream (@agentclientprotocol/sdk/experimental):
POST /acpsends each client message.initializeis answered directly (200, with theAcp-Connection-Idheader); everything else is answered202and the response arrives on an SSE stream.GET /acpopens the SSE streams: one for the connection (responses tosession/newandsession/load, connection-level messages), and one per session (Acp-Session-Id), opened as soon as a response names the session.DELETE /acpends the connection on close. Cookies are kept for the connection.
The transport is exposed as a pair of byte streams carrying newline-delimited JSON-RPC, like stdio, so any connection (or a stdio relay) can use it unchanged.
Failure handling follows the TypeScript SDK: HTTP 401, 403, 404 and 410, network errors
and failed POSTs of notifications or responses close the transport. Any other HTTP error
fails only the request, with a JSON-RPC error whose data is {status, body}. HTTP 409
marks a single session as lost: its requests fail until session/load or
session/resume reattaches it. ACP v1 does not replay messages missed while a stream
was down.
CONNECTION_FAILURE_STATUSES
module-attribute
¶
POST statuses meaning the whole connection is unusable or gone.
SESSION_CONFLICT_STATUS
module-attribute
¶
Status meaning a session is no longer attached to this connection.
HttpTransportError
¶
connect_http_transport
async
¶
connect_http_transport(
url: str,
*,
headers: Mapping[str, str] | None = None,
client: AsyncClient | None = None,
timeout: float = 30.0,
) -> AsyncGenerator[tuple[ByteReceiveStream, ByteSendStream]]
Connect to an ACP server's Streamable HTTP endpoint.
The streams carry newline-delimited JSON-RPC, like a stdio agent's. The first message
written must be initialize.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The |
required |
headers
|
Mapping[str, str] | None
|
Extra headers for every request (e.g. authentication). |
None
|
client
|
AsyncClient | None
|
HTTP client to use (its cookies and settings apply). By default a client
is created, using HTTP/2 when the |
None
|
timeout
|
float
|
Timeout for connecting and for POSTs (SSE streams have no read timeout). |
30.0
|
Yields:
| Type | Description |
|---|---|
AsyncGenerator[tuple[ByteReceiveStream, ByteSendStream]]
|
(reader, writer) byte streams. |