Transports¶
A WireStream is A11's pluggable transport —
a bidirectional, unordered channel between two endpoints. Choosing an
implementation is how an agent goes from in-process to networked; see
Principles.
WireStream¶
start and
accept install callbacks on the
initiating and responding sides. send
admits a message into the bounded outgoing path;
half_close queues the local end
marker; and
drain_outgoing_messages
is the delivery barrier. abort
terminates a failed exchange with a structured status.
a11.net.wire_stream.WireStream
¶
Construct the abstract WireStream base. Subclass this in Python to implement a custom asynchronous, bidirectional transport for an agent; the abstract operations (send, start/accept, get_status, get_trailers, ...) are dispatched to your overrides.
deadline
property
¶
The stream's current absolute deadline, after which it is automatically aborted.
abort
¶
accept
¶
Begin driving the stream as the responding (server) side, delivering each inbound message to the asynchronous on_message callback and end-of-stream to on_done. Use this instead of start() when this endpoint is answering an incoming agent connection. Returns an awaitable that resolves when acceptance completes; use on_done as the terminal barrier.
drain_outgoing_messages
¶
get_id
¶
Return the stream's stable identifier, which also seeds its tracing trace id. Use it to correlate an agent stream with logs and traces.
get_impl
¶
Return an opaque native handle to the underlying implementation, or None. Intended for advanced interop, not normal agent code.
get_status
¶
Return the stream's terminal status once it has finished, or OK while it is still active. Inspect this after the stream completes to learn whether the agent exchange succeeded or failed.
get_trailers
¶
Return the trailers (final metadata) the peer sent at half-close, or None if none were received. Read this after the stream ends to recover end-of-turn metadata from the agent exchange.
half_close
¶
send
¶
send(message: WireMessage) -> None
set_deadline
¶
Set an absolute wall-clock deadline after which the stream is automatically aborted; pass None to clear it. Use this to bound how long an agent interaction is allowed to run.
start
¶
a11.net.wire_stream.WireStreamOptions
¶
WireStreamOptions(max_buffered_incoming_messages: Any = 100, max_single_message_size: Any = 33554432, max_buffered_incoming_bytes: Any = 33554432, message_timeout_millis: Any | None = None, deadline: Any | None = None)
Construct wire-stream options controlling buffering and timeouts for an agent stream. All arguments are keyword-friendly and validated on construction.
deadline
property
writable
¶
Absolute wall-clock deadline after which the stream is aborted.
max_buffered_incoming_bytes
property
writable
¶
Maximum total bytes of buffered inbound messages before backpressure is applied.
max_buffered_incoming_messages
property
writable
¶
Maximum number of inbound messages buffered before backpressure is applied.
max_single_message_size
property
writable
¶
Maximum size, in bytes, of a single wire message.
message_timeout
property
writable
¶
Per-message inactivity timeout as a duration.
message_timeout_millis
property
writable
¶
Per-message inactivity timeout expressed in milliseconds.
In-process¶
a11.net.in_process_wire_stream.InProcessWireStream
¶
Bases: WireStream
create_pair
staticmethod
¶
create_pair(options: WireStreamOptions | None = None, first_options: WireStreamOptions | None = None, second_options: WireStreamOptions | None = None) -> tuple[InProcessWireStream, InProcessWireStream]
Create a connected pair of in-process wire streams that talk to each other directly in memory, with no network involved. Use this to wire an agent to a local service or test harness: one endpoint drives start() while the other drives accept(). Pass shared options, or per-endpoint first_options/second_options, to tune buffering and timeouts.
wait
¶
Await until this in-process stream has fully finished. Block on this to know a local agent exchange has completed before tearing the pair down.
a11.net.in_process_wire_stream.create_in_process_wire_stream_pair
¶
create_in_process_wire_stream_pair(options: WireStreamOptions | None = None, *, first_options: WireStreamOptions | None = None, second_options: WireStreamOptions | None = None) -> tuple[InProcessWireStream, InProcessWireStream]
Use
create_in_process_wire_stream_pair
to test both endpoints without opening a socket.
WebSocket¶
a11.net.websocket_wire_stream.WebSocketWireStream
¶
Bases: WireStream
connect
staticmethod
¶
connect(url: str, options: WireStreamOptions = ..., websocket_options: WebSocketClientOptions = ...) -> WebSocketWireStream
Open a client WebSocket connection to url and return a WireStream over it. This is the standard way for an agent to dial out to a remote A11 endpoint; the returned stream is then driven asynchronously via start()/send(). Tune transport buffering with options and the handshake (headers, framing, HTTP/2, TLS) with websocket_options.
a11.net.websocket_wire_stream.WebSocketWireServer
¶
port
property
¶
The actual TCP port the server is listening on, resolved even when an ephemeral port (0) was requested.
create
staticmethod
¶
create(on_stream: Any, options: WebSocketServerOptions = ...) -> WebSocketWireServer
Start a WebSocket server that accepts incoming A11 connections, invoking the asynchronous on_stream callback with a fresh WireStream for each accepted client. This is the server-side entry point for hosting an agent: each callback runs concurrently and typically drives accept() on its stream. Configure the listen address, port, path and TLS via options.
get_impl
¶
Return an opaque native handle to the underlying implementation, or None. Intended for advanced interop.
stop
¶
Stop the server and close the listening socket, releasing the bound port. Call this to shut the agent host down cleanly; it blocks until shutdown completes.
HTTP SSE¶
a11.net.http_sse_wire_stream.HttpSseWireStream
¶
Bases: WireStream
get_http_request_headers
¶
Return the HTTP headers carried on the underlying SSE request. This is the base class shared by the client and server SSE wire streams that transport A11 messages over an HTTP/2 Server-Sent Events connection. Use it when building an agent that needs to inspect the transport-level request metadata.
get_http_response_headers
¶
Return the HTTP response headers negotiated for the SSE connection, or None if they have not arrived yet. Because the connection is established asynchronously, prefer awaiting wait_for_http_headers() before relying on this value.
set_http_request_headers
¶
Set the HTTP headers to send on the underlying SSE request. Call this before the stream connects to attach auth or routing metadata that your agent's transport needs.
set_http_response_headers
¶
Set the HTTP headers to send on the SSE response. Used on the server side to attach transport metadata before the streaming response is flushed to the client.
wait_for_http_headers
¶
Await the exchange of HTTP headers for the SSE connection. Because SSE wire streams connect asynchronously, await this future before reading response headers or assuming the stream is live.
a11.net.http_sse_wire_stream.HttpSseServer
¶
create
staticmethod
¶
create(bind_address: str = '127.0.0.1', port: SupportsInt | SupportsIndex = 0, on_connect: Any | None = None, options: HttpSseOptions = ...) -> HttpSseServer
Create and start an SSE server that accepts A11 wire streams, invoking the optional async on_connect callback for each client.
wait_for_stream
¶
Await the next incoming SSE wire stream from a connecting client.
WebRTC¶
a11.net.webrtc_wire_stream.WebRtcWireStream
¶
Bases: WireStream
data_channel
property
¶
Opaque capsule around the underlying libdatachannel DataChannel. Exposed for advanced interop and diagnostics; agent code normally reads and writes through the WireStream API rather than touching this directly.
peer_connection
property
¶
Opaque capsule around the underlying libdatachannel PeerConnection. Useful for inspecting ICE/connection state during debugging; not required for normal streaming.
signalling_endpoint
property
¶
Signalling transport this stream negotiated over. Lets an agent observe or reuse the channel that carried the asynchronous SDP/ICE handshake.
a11.net.webrtc_wire_stream.WebRtcWireServer
¶
signalling_endpoint
property
¶
Signalling endpoint the server negotiates over.
create
staticmethod
¶
create(identity: str, signalling: SignallingService, on_stream: Any, configuration: WebRtcConfiguration = ..., stream_options: WireStreamOptions = ...) -> WebRtcWireServer
Create a WebRTC server that accepts peer connections and invokes the async on_stream callback with each new WebRtcWireStream.
Signalling¶
Signalling is the out-of-band handshake WebRTC peers use to find each other and exchange connection details.
For a service,
WebSocketSignallingServer.create
starts the endpoint and
stop ends acceptance
during shutdown.
a11.net.signalling.WebSocketSignallingServer
¶
create
staticmethod
¶
create(service: SignallingService, options: WebSocketSignallingServerOptions = ...) -> WebSocketSignallingServer
Create a WebSocket signalling server that fronts the given in-process signalling service.
a11.net.signalling.WebSocketSignallingClient
¶
Bases: SignallingTransport
connect
staticmethod
¶
connect(url: str, identity: str, on_message: Any | None = None, options: WebSocketSignallingClientOptions = ...) -> Any
Asynchronously connect to a WebSocket signalling server, resolving to a client once registered under the given identity.
a11.net.signalling.SignallingService
¶
HTTP/2 primitives¶
Low-level building blocks under the WebSocket and SSE transports; most agents use them only indirectly.
a11.net.http2.Http2Client
¶
connect
staticmethod
¶
Asynchronously connect to an HTTP/2 server, returning a future that resolves to the connected client.
extended_connect
¶
extended_connect(protocol: str, path: str, headers: Any | None = None, scheme: str = '') -> Http2DuplexStream
Open an extended CONNECT duplex stream for bidirectional data.
request
¶
request(method: str, path: str, headers: Any | None = None, body: Any = b'', scheme: str = '') -> Any
Send a request and await the full buffered response.
request_stream
¶
request_stream(method: str, path: str, headers: Any | None = None, body: Any = b'', scheme: str = '') -> Http2ResponseStream
Open a request and return a pull-oriented response stream for reading the response body incrementally.
a11.net.http2.Http2Server
¶
create
staticmethod
¶
create(bind_address: str = '127.0.0.1', port: SupportsInt | SupportsIndex = 0, handler: Any | None = None, options: Http2Options = ...) -> Http2Server
Create and start an HTTP/2 server bound to the given address and port, dispatching each request to the async handler.