Internals
The wire protocol, codec architecture, conversation tree, and transport patterns that AI Transport is built from. For senior engineers and codec implementers.
The internals section is for engineers who want to understand the system before they depend on it, and for anyone building a custom codec.
Four layers fit together, from the application-facing model down to the SDK's internal components:
- Conversation tree: the highest-level structure. Every session is a tree of
ConversationNodes (InputNodes keyed bycodec-message-idfor user prompts andRunNodes keyed byrunIdfor agent replies), joined byparentandfork-ofpointers. The view walks the tree to produce a flat message list for rendering. - Codec architecture: the encoder converts client-published
TInputs and agent-publishedTOutputs into Ably publish operations. The decoder converts inbound Ably messages back into typed events. The codec lets AI Transport work with any AI framework. - Wire protocol: the Ably channel format. Two header tiers (
extras.ai.transportfor run and message identity plus the stream lifecycle;extras.ai.codecfor the payload identity a codec declares), four run lifecycle event names (ai-run-start,ai-run-suspend,ai-run-resume,ai-run-end), two step lifecycle event names (ai-step-start,ai-step-end), one cancel signal (ai-cancel), and two content event names (ai-inputfor client publishes,ai-outputfor agent publishes). Nine message names in all. - Transport patterns: the SDK-internal components that carry the codec's messages over the wire: the stream router that fans inbound channel messages out to per-run streams, the input-event lookup that resolves a POSTed invocation to its channel events, and the cancel-routing pipeline.
Topics
Wire protocol
The Ably channel wire format: header tiers, lifecycle events, content event names, and message identity.
Codec architecture
How the codec translates TInput and TOutput to Ably messages. Encoder, decoder, and the input/output type split.
Conversation tree
The branching run tree. Sibling resolution, regenerate groups, and message-anchored branch selection.
Transport patterns
Internal transport components: stream router, input-event lookup, and cancel routing.