Quick Start
The smallest possible end-to-end network scenario: one in-process hub, two agents, a consulting session that auto-closes after a single Q-and-A.
Expected output (Sonnet's exact words will differ on each run):
closed: 'consulting_complete'
alice: What's the single most important property of a distributed system?
bob: Fault tolerance — because a system that can't survive partial failures defeats its entire purpose.
What Just Happened#
In order:
Hub.open(MemoryKnowledgeStore())— boots an in-process hub. TheKnowledgeStoreis where the hub persists its audit log, registry, and write-ahead logs (here in memory).LocalLink(hub)— a transport factory. EachHubClientconstructed against the same link gets its own duplex queue pair to the hub.HubClient(link, hub=hub)— one per process boundary. In a real deployment alice and bob would each live in their own process, each with oneHubClient. Here they share a process for clarity.hc.register(agent, passport, resume)— registers anAgentwith the hub. Returns anAgentClientwhoseagent_idis hub-stamped.alice.open(type="consulting", target="bob")— alice creates a consulting session with bob as respondent. Internally: hub postsEV_SESSION_INVITEto bob → bob's default handler auto-acks → hub postsEV_SESSION_OPENEDandalice.open(...)returns withsession.state == ACTIVE.session.send(text, audience=...)— alice sends anEV_TEXTenvelope.- Bob's default handler — receives the
EV_TEXT, probes whether the adapter would accept a reply right now (it would — bob hasn't replied yet), runsAgent.ask(text), and sends bob's reply back through bob's own session handle. ConsultingAdapter— sees bothinitiator_sentandrespondent_repliedare true, returnsAdapterResult(next_state=CLOSED, auto_close_reason="consulting_complete"). Hub postsEV_SESSION_CLOSED.alice.wait_for_session_event(...)— alice's loop wakes when she receives the close envelope.hub.read_wal(session_id)— replays every envelope the hub recorded for the session. Each envelope is hub-stamped (id, timestamp, sender, audience, event_type, event_data).
Mental Hooks#
- The
Hubis the only authoritative state. Every send goes through it; every observer reads from it. Clients are thin. - A
session_idis the unit of conversation. The hub's WAL is keyed by session id; expectation evaluators evaluate per session; views project per session. - Each
AgentClientcarries adefault_handlerthat auto-acks invites and runsAgent.askon inbound text. You can replace it withagent_client.on_envelope(callback)when you need custom logic. - The hub assigns the
agent_idat registration. Use it (alice.agent_id) for routing rather than the human-readable name. The name may not be unique under a multi-tenant deployment.
Where to Next#
- Hub & Identity — the registry side:
Hub.open,Passport,Resume,Rule, auth. - Agent Clients — the agent side:
HubClient.register, default handler, custom handlers. - Session Adapters — pick the right one: free-form, 1Q1R, round-robin, or graph-driven.