Skip to content

Agent-to-Agent Communication

AgentCTX enables agents to communicate through three channels: NATS messaging for real-time pub/sub, memory handoffs for state transfer, and CTX delegation for task routing.

NATS JetStream provides the message bus for inter-agent communication:

// Agent A publishes an event
+m:context "auth review complete" #event #team
// Agent B subscribes to team events
?m #team #live

Under the hood, this maps to NATS subjects:

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

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

Load-balance tasks across available agents:

// Multiple agents subscribe to the same queue
?m #queue:code-review #live
// Tasks are distributed round-robin
^a code-review context="PR #42" → routed to least-busy agent

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 NATS.

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.