Enable agents to discover and delegate tasks using the A2A protocol with SPIFFE identity and mTLS on every message. Includes fan-out and pipeline examples.
Hexr implements Google’s Agent-to-Agent (A2A) protocol with SPIFFE identity extensions, so agents can securely discover and communicate with each other without manual service discovery, API keys, or shared secrets. Every message is encrypted over mTLS, every sender’s identity is verified via its SPIFFE certificate, and every exchange is authorized by OPA policy and traced with OpenTelemetry. This guide shows you how to enable A2A communication and implement the two most common patterns: fan-out and pipeline.
Add a2a=True to the @hexr_agent decorator. This provisions the A2A sidecar and registers an Agent Card so other agents can discover yours:
coordinator.py
from hexr import hexr_agentfrom hexr.a2a import A2AClient@hexr_agent(name="coordinator", tenant="acme-corp", a2a=True)def main(): a2a = A2AClient() # Discover agents in the same namespace agents = a2a.discover() for agent in agents: print(f"Found: {agent.name} - {agent.description}") # Send a task to another agent task = a2a.send( agent="research-analyst", message="Research the latest AI agent frameworks", ) # Get the result result = a2a.get_task(task.id) print(result.output)
2
Choose a communication pattern
Pick the pattern that fits your workflow:
# Fan-out: send tasks to multiple agents in parallel@hexr_agent(name="coordinator", tenant="acme-corp", a2a=True)def main(): a2a = A2AClient() topics = ["quantum computing", "robotics", "biotech"] tasks = [] for topic in topics: task = a2a.send( agent="research-analyst", message=f"Research {topic} trends for 2026", ) tasks.append(task) # Collect results results = [a2a.get_task(t.id) for t in tasks] # Synthesize from hexr import hexr_llm synthesis = hexr_llm( provider="openai", model="gpt-4o", prompt=f"Synthesize these research results: {results}", ) print(synthesis)
3
Build and deploy all agents
Build and deploy each agent that participates in A2A communication. Agents discover each other by name within the same tenant namespace:
All A2A communication is mTLS encrypted, identity verified, OPA authorized, and fully traced.
1
Agent A sends a task over mTLS
The coordinator sends a task to the researcher through the Envoy proxy, authenticated with its SPIFFE identity.
2
OPA authorizes the request
Envoy checks with OPA: “Can coordinator communicate with researcher?” OPA returns ALLOW based on your policy.
3
Task delivered over mTLS
Envoy delivers the task to the researcher over mTLS. The researcher processes it and returns the result.
A2A request flow
Agent A (coordinator) → Envoy (mTLS) → OPA (authorize) → Agent B (researcher) → Result → A
Security property
Mechanism
Encryption
mTLS using SPIFFE SVIDs
Identity verification
Each agent’s SPIFFE ID is validated on every message
Authorization
OPA policies control which agents can communicate
Audit trail
Every message is traced via OpenTelemetry
Agents must be in the same tenant namespace to discover each other via a2a.discover(). Cross-tenant communication requires explicit OPA policy configuration.