A2A Development Patterns
Before writing code
Fetch live docs:
- Fetch
https://a2a-protocol.org/latest/specification/ for the latest protocol details
- Web-search
a2a protocol best practices multi-agent architecture for community patterns
- Web-search
site:github.com a2aproject A2A samples patterns for reference architectures
- Web-search
multi-agent system design patterns for general multi-agent architecture guidance
Conceptual Architecture
Orchestration Topologies
Hub-and-Spoke (Orchestrator)
A central coordinator agent delegates subtasks to specialist agents:
┌→ Research Agent
Coordinator Agent ──┼→ Analysis Agent
└→ Writing Agent
- Pros: Centralized control, clear task routing, easy to monitor
- Cons: Single point of failure, coordinator bottleneck
- Use when: Well-defined subtask decomposition, need for aggregation
Peer-to-Peer (Mesh)
Agents discover and communicate directly with each other:
Agent A ←→ Agent B
↕ ↕
Agent C ←→ Agent D
- Pros: No single point of failure, flexible
- Cons: Complex routing, harder to monitor, potential loops
- Use when: Agents are loosely coupled, dynamic discovery needed
Pipeline (Chain)
Tasks flow through a sequence of agents:
Input → Agent A → Agent B → Agent C → Output
- Pros: Simple flow, easy to reason about, composable
- Cons: Sequential latency, failure in one stage blocks all
- Use when: Clear transformation stages, ETL-like workflows
Hierarchical (Tree)
Manager agents delegate to team agents, which may further delegate:
CEO Agent
├── Marketing Manager Agent
│ ├── Content Agent
│ └── SEO Agent
└── Engineering Manager Agent
├── Frontend Agent
└── Backend Agent
- Pros: Natural decomposition, scoped authority, scalable
- Cons: Deep hierarchies add latency, complex coordination
- Use when: Large organizations of agents, domain separation
Idempotency
Design A2A interactions to be idempotent:
- Use deterministic task IDs (hash of input + context) when possible
- Handle duplicate
message/send requests gracefully
- Store task results for replay on retry
- Use request IDs for deduplication at the transport level
Observability
Multi-agent systems need deep observability:
Distributed tracing:
- Propagate trace IDs through A2A task metadata
- Log entry/exit for each agent in the chain
- Use OpenTelemetry or similar for cross-agent tracing
Metrics:
- Task latency per agent
- Task success/failure rates
- Message volume and throughput
- Active task count per agent
- Error code distribution
Logging:
- Log all JSON-RPC requests/responses (with sensitive data redacted)
- Include task IDs and request IDs in all log entries
- Log state transitions with timestamps
Agent Registries
For systems with many agents:
- Centralized registry — Agents register their Agent Cards; clients query by skill/tag
- DNS-based discovery — Agent Cards at well-known URLs
- Service mesh — Use infrastructure-level service discovery
Versioning
A2A agents evolve over time:
- Agent Card version — Update when skills or capabilities change
- Skill versioning — Individual skills can be versioned
- Protocol version — Track which A2A spec version you implement
- Breaking changes — Update the Agent Card URL or version for breaking changes
- Backward compatibility — Support old and new message formats during transitions
Security Patterns
- Zero trust — Authenticate every agent-to-agent call
- Least privilege — Agents only get access to the skills they need
- Audit trail — Log all cross-agent interactions for compliance
- Secret management — Use vaults for API keys and credentials, never hardcode
Production Deployment
- Health checks — Implement
/health endpoints alongside the A2A endpoint
- Graceful shutdown — Complete or cancel in-flight tasks before stopping
- Scaling — A2A servers are stateless per-request; task store handles state
- Load balancing — Standard HTTP load balancing works for A2A endpoints
- Rate limiting — Protect agents from being overwhelmed by requests
- Circuit breakers — Stop calling failing agents, use fallbacks
Error Recovery Patterns
- Retry with backoff — Transient failures, exponential backoff
- Fallback agents — If primary agent fails, try an alternative
- Dead letter queue — Store failed tasks for later analysis/replay
- Compensation — If a multi-step workflow fails midway, undo completed steps
- Timeout escalation — If a task is stuck, escalate to a human or different agent
Best Practices
- Start simple — hub-and-spoke before mesh
- Design for failure — every agent call can fail
- Make agents stateless where possible — state lives in the task store
- Use structured DataParts for inter-agent data, not serialized text
- Monitor everything — you can't debug what you can't see
- Version your Agent Cards and document changes
- Test the full topology, not just individual agents
- Set SLOs for agent response times and success rates
Fetch the latest A2A specification and community patterns before implementing multi-agent architectures.
1---2name: a2a-dev-patterns3description: Apply A2A cross-cutting development patterns — orchestration topologies, idempotency, observability, agent registries, versioning, and production deployment. Use when architecting multi-agent systems or solving cross-cutting concerns.4---5
6# A2A Development Patterns
7
8## Before writing code
9
10**Fetch live docs**:
111. Fetch `https://a2a-protocol.org/latest/specification/` for the latest protocol details
122. Web-search `a2a protocol best practices multi-agent architecture` for community patterns
133. Web-search `site:github.com a2aproject A2A samples patterns` for reference architectures
144. Web-search `multi-agent system design patterns` for general multi-agent architecture guidance
15
16## Conceptual Architecture
17
18### Orchestration Topologies
19
20#### Hub-and-Spoke (Orchestrator)
21A central coordinator agent delegates subtasks to specialist agents:
22```
23 ┌→ Research Agent
24Coordinator Agent ──┼→ Analysis Agent
25 └→ Writing Agent
26```
27- **Pros**: Centralized control, clear task routing, easy to monitor
28- **Cons**: Single point of failure, coordinator bottleneck
29- **Use when**: Well-defined subtask decomposition, need for aggregation
30
31#### Peer-to-Peer (Mesh)
32Agents discover and communicate directly with each other:
33```
34Agent A ←→ Agent B
35 ↕ ↕
36Agent C ←→ Agent D
37```
38- **Pros**: No single point of failure, flexible
39- **Cons**: Complex routing, harder to monitor, potential loops
40- **Use when**: Agents are loosely coupled, dynamic discovery needed
41
42#### Pipeline (Chain)
43Tasks flow through a sequence of agents:
44```
45Input → Agent A → Agent B → Agent C → Output
46```
47- **Pros**: Simple flow, easy to reason about, composable
48- **Cons**: Sequential latency, failure in one stage blocks all
49- **Use when**: Clear transformation stages, ETL-like workflows
50
51#### Hierarchical (Tree)
52Manager agents delegate to team agents, which may further delegate:
53```
54CEO Agent
55├── Marketing Manager Agent
56│ ├── Content Agent
57│ └── SEO Agent
58└── Engineering Manager Agent
59 ├── Frontend Agent
60 └── Backend Agent
61```
62- **Pros**: Natural decomposition, scoped authority, scalable
63- **Cons**: Deep hierarchies add latency, complex coordination
64- **Use when**: Large organizations of agents, domain separation
65
66### Idempotency
67
68Design A2A interactions to be idempotent:
69- Use deterministic task IDs (hash of input + context) when possible
70- Handle duplicate `message/send` requests gracefully
71- Store task results for replay on retry
72- Use request IDs for deduplication at the transport level
73
74### Observability
75
76Multi-agent systems need deep observability:
77
78**Distributed tracing:**
79- Propagate trace IDs through A2A task metadata
80- Log entry/exit for each agent in the chain
81- Use OpenTelemetry or similar for cross-agent tracing
82
83**Metrics:**
84- Task latency per agent
85- Task success/failure rates
86- Message volume and throughput
87- Active task count per agent
88- Error code distribution
89
90**Logging:**
91- Log all JSON-RPC requests/responses (with sensitive data redacted)
92- Include task IDs and request IDs in all log entries
93- Log state transitions with timestamps
94
95### Agent Registries
96
97For systems with many agents:
98- **Centralized registry** — Agents register their Agent Cards; clients query by skill/tag
99- **DNS-based discovery** — Agent Cards at well-known URLs
100- **Service mesh** — Use infrastructure-level service discovery
101
102### Versioning
103
104A2A agents evolve over time:
105- **Agent Card version** — Update when skills or capabilities change
106- **Skill versioning** — Individual skills can be versioned
107- **Protocol version** — Track which A2A spec version you implement
108- **Breaking changes** — Update the Agent Card URL or version for breaking changes
109- **Backward compatibility** — Support old and new message formats during transitions
110
111### Security Patterns
112
113- **Zero trust** — Authenticate every agent-to-agent call
114- **Least privilege** — Agents only get access to the skills they need
115- **Audit trail** — Log all cross-agent interactions for compliance
116- **Secret management** — Use vaults for API keys and credentials, never hardcode
117
118### Production Deployment
119
120- **Health checks** — Implement `/health` endpoints alongside the A2A endpoint
121- **Graceful shutdown** — Complete or cancel in-flight tasks before stopping
122- **Scaling** — A2A servers are stateless per-request; task store handles state
123- **Load balancing** — Standard HTTP load balancing works for A2A endpoints
124- **Rate limiting** — Protect agents from being overwhelmed by requests
125- **Circuit breakers** — Stop calling failing agents, use fallbacks
126
127### Error Recovery Patterns
128
129- **Retry with backoff** — Transient failures, exponential backoff
130- **Fallback agents** — If primary agent fails, try an alternative
131- **Dead letter queue** — Store failed tasks for later analysis/replay
132- **Compensation** — If a multi-step workflow fails midway, undo completed steps
133- **Timeout escalation** — If a task is stuck, escalate to a human or different agent
134
135### Best Practices
136
137- Start simple — hub-and-spoke before mesh
138- Design for failure — every agent call can fail
139- Make agents stateless where possible — state lives in the task store
140- Use structured DataParts for inter-agent data, not serialized text
141- Monitor everything — you can't debug what you can't see
142- Version your Agent Cards and document changes
143- Test the full topology, not just individual agents
144- Set SLOs for agent response times and success rates
145
146Fetch the latest A2A specification and community patterns before implementing multi-agent architectures.