Skip to content

Agent-to-Agent Communication

AgentCTX enables agents to communicate through three channels: SurrealDB LIVE SELECT for real-time event routing, memory handoffs for state transfer, and CTX delegation for task routing.

The default inter-agent transport is backed by SurrealDB LIVE SELECT via the SovereignBus and LiveSelectCoordinator:

Agent A writes memory → SurrealDB → LIVE SELECT
→ sidecar receives → fans out to workspace agents
→ Agent B/C/D receive notification in <100ms

The sovereign event bus publishes dispatch events; subagents subscribe by role. All state persists in SurrealDB — no in-memory pub/sub.

PathTransportOverhead
Same machineIPC pushZero
Cross networkCF Tunnel push (ctxb-transport)Minimal
// Agent A publishes an event
+m:context "auth review complete" #event #team
// Agent B subscribes to team events
?m #team #live

Events are routed through the bus’s role-based filter, matching against SovereignRole identifiers.

Synchronous agent-to-agent queries:

// Agent A asks Agent B a question
^a query agent="security-agent" question="Is this endpoint safe?"
// Agent B responds through the gateway
+m:chat "Endpoint is safe — parameterized queries, no injection surface" #response

The structured way to transfer state between agents:

// Agent A completes work and hands off
+m:handoff "security review complete, 1 critical finding" #state
+m:context "SQL injection in search endpoint, line 42"
+m:cross_ref "see OWASP A03:2021"
// Agent B picks up the handoff
?m #handoff @1h Find recent handoffs
?m @traverse "PR-42" Get full context graph
+m:context "continuing from security review handoff"
  1. Use pipeline verbs+m:handoff, +m:context, +m:edge create structured traces
  2. Tag with #state — makes handoffs discoverable
  3. Include context — the receiving agent needs enough information to continue
  4. Reference related memories — use +m:cross_ref to link to supporting evidence

The ^ operator delegates tasks to specific agents:

^a code-review agent="claude-opus" context="PR #42"
^a security-audit agent="security-specialist" context="auth module"
^a docs-update agent="gemini-flash" context="API reference changes"

The gateway’s delegation middleware (pipeline position 12) routes these to the target agent via the SovereignBus event system.

NATS JetStream (Optional — Enterprise Tier)

Section titled “NATS JetStream (Optional — Enterprise Tier)”

For high-throughput, cross-region enterprise deployments, NATS JetStream is available as an optional transport:

PatternSubjectUse
Team eventsagentctx.team.{team}.eventsBroadcast to team
Agent directagentctx.agent.{id}.inboxDirect messages
Plane eventsagentctx.plane.{plane}.opsPlane operation stream
Process groupagentctx.group.{id}.eventsCoordinated group

NATS provides at-least-once delivery via JetStream, consumer groups for work distribution, and cross-region durability for organizations that need it.

For cross-organization communication:

// Connect to a federated AgentCTX instance
+a federation endpoint="https://partner.example.com/agentctx" trust="mTLS"
// Query tools from a federated instance
?t partner.code-analysis

Federation uses mTLS for transport and Ed25519 for message signing.