latent.wire¶
latent.wire — wire codecs as pluggable WireProtocol implementations.
A wire protocol encodes the canonical :class:~latent.events.AgentEvent stream
onto a streaming wire (AI SDK SSE, AG-UI, …) and decodes it back. It is
bidirectional (ADR-009 D3): X-Stream-Protocol selects the response
encoding, while decode_request accepts the request body — latent-native
for Studio's RemoteAgentProxy, protocol-native for a stock client.
This seam is dependency-free so importing it never pulls a web/codec dep —
import latent.wire stays light (enforced by
tests/unit/test_import_without_extras.py). Concrete codecs (ai-sdk, pure
stdlib; ag-ui, via ag-ui-protocol) register themselves via
:func:register_wire_protocol; adding one is a single registration and leaves
serving/proxy code untouched (ADR-002 D2's additive-codec promise).
Classes¶
WireProtocol¶
Bidirectional codec between AgentEvents and a wire protocol's bytes.
Server side consumes :meth:decode_request + :meth:encode; the
client/proxy side consumes :meth:encode_request + :meth:decode. The same
instance serves both ends so encode/decode stay a single inverse pair
(encode ∘ decode = identity for latent-native agents — ADR-003 D2).
Functions¶
get_wire_protocol¶
Return the registered codec for name; raise ValueError if unknown.
A built-in codec is imported on first lookup so it self-registers — the codec (and its extra deps) load only when actually requested.
register_wire_protocol¶
Register a codec under its name (the X-Stream-Protocol value).
Methods¶
WireProtocol.decode¶
Client/proxy: parse the wire back into AgentEvents.
WireProtocol.decode_request¶
Server: parse a request body into (messages, config).
WireProtocol.encode¶
Server: encode the agent's event stream onto the wire.
WireProtocol.encode_request¶
Client/proxy: serialize a request body.