Agent-to-Agent Communication
Agent-to-Agent Communication
Section titled “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 Messaging
Section titled “NATS Messaging”NATS JetStream provides the message bus for inter-agent communication:
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 #liveUnder the hood, this maps to NATS subjects:
| 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 |
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" #responseQueue Groups
Section titled “Queue Groups”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 agentMemory 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 NATS.
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