Agent-to-Agent Communication
Agent-to-Agent Communication
Section titled “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.
SurrealDB LIVE SELECT (Default Transport)
Section titled “SurrealDB LIVE SELECT (Default Transport)”The default inter-agent transport is backed by SurrealDB LIVE SELECT via the SovereignBus and LiveSelectCoordinator:
Event Routing
Section titled “Event Routing”Agent A writes memory → SurrealDB → LIVE SELECT→ sidecar receives → fans out to workspace agents→ Agent B/C/D receive notification in <100msThe sovereign event bus publishes dispatch events; subagents subscribe by role. All state persists in SurrealDB — no in-memory pub/sub.
Transport Selection
Section titled “Transport Selection”| Path | Transport | Overhead |
|---|---|---|
| Same machine | IPC push | Zero |
| Cross network | CF Tunnel push (ctxb-transport) | Minimal |
Pub/Sub
Section titled “Pub/Sub”// Agent A publishes an event+m:context "auth review complete" #event #team
// Agent B subscribes to team events?m #team #liveEvents are routed through the bus’s role-based filter, matching against SovereignRole identifiers.
Request/Reply
Section titled “Request/Reply”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" #responseMemory Handoffs
Section titled “Memory Handoffs”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"Handoff Best Practices
Section titled “Handoff Best Practices”- Use pipeline verbs —
+m:handoff,+m:context,+m:edgecreate structured traces - Tag with
#state— makes handoffs discoverable - Include context — the receiving agent needs enough information to continue
- Reference related memories — use
+m:cross_refto link to supporting evidence
CTX Delegation
Section titled “CTX Delegation”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:
| Pattern | Subject | Use |
|---|---|---|
| Team events | agentctx.team.{team}.events | Broadcast to team |
| Agent direct | agentctx.agent.{id}.inbox | Direct messages |
| Plane events | agentctx.plane.{plane}.ops | Plane operation stream |
| Process group | agentctx.group.{id}.events | Coordinated group |
NATS provides at-least-once delivery via JetStream, consumer groups for work distribution, and cross-region durability for organizations that need it.
Federation
Section titled “Federation”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-analysisFederation uses mTLS for transport and Ed25519 for message signing.
See Also
Section titled “See Also”- Multi-Agent Orchestration — process groups and coordination
- Pipeline Verbs — handoff and context verbs
- Seven Planes — the agents plane