Distributed Deployment
The network is not limited to one process. Replace LocalLink with WsLink and the hub becomes a server that agents anywhere on the network can connect to over WebSocket — entirely over the wire, no shared memory, no in-process hub reference.
Install#
WsLink and serve_ws require the network-ws extra:
Architecture#
┌─────────────── hub server ────────────────┐
│ Hub + serve_ws · registry · WAL · auth │
└───▲──────────────────────────▲────────────┘
│ ws://hub:8765 │ ws://hub:8765
┌────────┴──────────┐ ┌─────────┴──────────┐
│ process A │ │ process B │
│ HubClient(WsLink)│ │ HubClient(WsLink) │
│ alice │ │ bob │
└───────────────────┘ └────────────────────┘
Every control-plane call (register, open channel, post envelope, WAL read) travels as a RequestFrame / ResponseFrame RPC over the WebSocket. Every inbound notify arrives as a NotifyFrame and is ack'd by a ReceiptFrame. The HubClient API is identical whether you pass a LocalLink or a WsLink — the transport is the only thing that changes.
Starting the Hub Server#
serve_ws(hub, host, port) is an async context manager. It binds a WebSocket server, hands each incoming connection its own WsLinkEndpoint, and lets the hub dispatch from there. Pass port=0 to bind an ephemeral port and read the real one from server.sockets[0].getsockname()[1].
Connecting a Remote Agent#
From any other process — same machine, different container, or across a real network:
HubClient(WsLink(url)) puts the client in remote mode: every register, open, send, and read_wal call is an RPC round-trip to the hub. The AgentClient surface (bob.open(...), bob.wait_for_channel_event(...), channel.send(...)) is identical to the in-process API.
Agents backed by different providers can share the same hub and the same channel — the hub is provider-neutral.
Sending a Cross-Process Consult#
The channel invite travels hub → bob over bob's WebSocket. Bob's default handler answers, and the reply comes back hub → alice over alice's WebSocket. The hub brokers the exchange; neither agent holds a reference to the other.
All four channel adapters work cross-process without change: consulting, conversation, discussion, and workflow.
Authentication#
For deployments where agents must authenticate at the WebSocket handshake, build the hub with an AuthRegistry:
Each agent passes its token inside Passport.auth:
The hub's AuthRegistry validates the claim before binding the connection. Raise AuthError from a custom AuthAdapter (a Protocol) to reject any scheme you define.
At-Least-Once Delivery#
The hub guarantees each envelope is delivered at least once across reconnects:
- Each
AgentClientmaintains an inbox cursor per channel — theenvelope_idof the last successfully processed envelope. - Inbound envelopes are ack'd with
ReceiptFrame; a nack causes immediate replay. - On reconnect, pass
since_envelope_idto replay any unacked envelopes from that point:
attach re-binds an existing identity to a fresh connection. resume_pending_turns re-fires any turns the protocol still expects from this agent. The default notify handler is idempotent under redelivery — causation-id deduplication short-circuits duplicate model turns without double-posting.
Task Durability#
Tasks can be checkpointed through the hub so state survives a process restart:
HubBackedCheckpointStore satisfies the CheckpointStore Protocol by delegating writes and reads to the hub's KnowledgeStore. Pass a Hub for in-process durability or a HubClient for cross-process. For checkpoints that survive a hub restart, use DiskKnowledgeStore(path) on the hub.
Production Notes#
| Concern | Recommendation |
|---|---|
| TLS | Pass an ssl_context to serve_ws(...) and use wss:// in WsLink. |
| Auth | Build the hub with AuthRegistry([ApiKeyAuth(keys=...)]) and pass Passport(auth=AuthBlock(...)) from each agent. |
| Durability | Use DiskKnowledgeStore(path) on the hub so the registry and channel WALs survive a restart. |
| Reconnect | On disconnect, build a fresh HubClient, call open(), then attach(agent, name=..., since_envelope_id=last_id). The hub replays any unacked envelopes past that cursor. |
| Federation | Register a RemoteAgentProxy on the hub to route envelopes addressed to agents with kind="remote_agent" across hub boundaries. |
Where to Next#
- Hub & Identity —
AuthRegistry,ApiKeyAuth, governance rules. - Agent Clients — custom envelope handlers, replacing the default handler.
- Governance, Audit & Observability — per-channel expectations and the hub audit log.