Skip to main content

Module websocket

Module websocket 

Source
Available on crate feature websocket only.
Expand description

WebSocket transport implementation for A2A clients.

WebSocketTransport opens a persistent WebSocket connection to the agent and multiplexes JSON-RPC 2.0 requests over text frames.

§Streaming

For streaming methods (SendStreamingMessage, SubscribeToTask), the server sends multiple text frames — one per event — followed by a final JSON-RPC success response. The transport delivers these as an EventStream.

§Architecture

FIX(C2): The transport uses a dedicated background reader task that routes incoming frames to the correct pending request via a HashMap<RequestId, Sender>. This eliminates the reader lock deadlock where a streaming background task would hold the reader Mutex for the entire stream duration, preventing any subsequent non-streaming request from proceeding.

§Authentication and per-request headers

Headers (including those an AuthInterceptor produces) are applied to the HTTP upgrade request only at connection establishment, via WebSocketTransport::connect_with_options. A persistent WebSocket carries JSON-RPC text frames with no per-frame HTTP header channel, so headers supplied per request by the client’s interceptor chain cannot be attached to individual frames and are not sent over an established connection (a dropped set is logged at warn).

The practical consequence: provide credentials at connect time. A token that rotates mid-connection is not picked up — reconnect to present the new credential. This is a deliberate limitation of the WebSocket binding, which is not part of the canonical A2A transport set (JSON-RPC, REST, gRPC).

§W3C trace context is not propagated over this transport

Stated plainly because the alternative is a silent gap: TracePropagationInterceptor has no effect on an established WebSocket connection. The traceparent and tracestate it writes are per-request headers, and this binding has nowhere to put them: a JSON-RPC text frame carries no header channel, and the A2A WebSocket binding defines no in-band equivalent. Inventing one would be a private protocol extension no peer implements.

Connect-time headers are not the workaround they are for a credential. W3C Trace Context §3.4 requires every outgoing request to advance parent-id — “The value of property parent-id MUST be set to a value representing the ID of the current operation” (§4.3) — so one traceparent fixed at the handshake would report every request on the connection as the same span. That is a wrong trace, not a partial one, and a missing span is the smaller lie.

If a call must be traced, send it over JSON-RPC, REST or gRPC, where the interceptor writes the header on every request as documented. A dropped trace header is reported once per connection at warn, separately from the per-call credential warning, which has a different remedy.

§Feature gate

Requires the websocket feature flag:

a2a-protocol-client = { version = "0.16", features = ["websocket"] }

Structs§

WebSocketTransport
WebSocket transport: JSON-RPC 2.0 over a persistent WebSocket connection.
WebSocketTransportConfig
Configuration for WebSocketTransport::connect_with_config.

Constants§

DEFAULT_MAX_PENDING_REQUESTS
Default for WebSocketTransportConfig::max_pending_requests.
DEFAULT_PING_INTERVAL
Default for WebSocketTransportConfig::ping_interval.