a2a-patterns
Agent-to-Agent (A2A) protocol implementation patterns for Google ADK - exposing agents via A2A, consuming external agents, multi-agent communication, and protocol configuration. Use when building multi-agent systems, implementing A2A protocol, exposing agents as services, consuming remote agents, configuring agent cards, or when user mentions A2A, agent-to-agent, multi-agent collaboration, remote agents, or agent orchestration.
What this skill does
# A2A Protocol Implementation Patterns
## Instructions
This skill provides comprehensive patterns for implementing the Agent2Agent (A2A) protocol in Google's Agent Development Kit (ADK). The A2A protocol standardizes communication between AI agents, enabling multi-agent collaboration across different platforms and frameworks.
## What is A2A?
The Agent2Agent (A2A) protocol enables AI agents to:
- Discover each other's capabilities through Agent Cards
- Communicate securely using standardized JSON-RPC messages
- Collaborate across different frameworks (CrewAI, LangGraph, ADK)
- Work across deployment platforms (Cloud Run, Agent Engine, GKE)
**Key Concept:** A2A focuses on agent-to-agent collaboration in natural modalities, complementing MCP (Model Context Protocol) which handles tool/data connections.
## Core Patterns
### 1. Exposing Agents via A2A (Server-Side)
**When to use:** Make your ADK agent available for other agents to consume
**Template:** `templates/a2a-server.py`
**Key Components:**
- `AgentCard` at `/.well-known/agent.json` - Advertises capabilities
- `AgentExecutor` - Handles incoming requests
- `DefaultRequestHandler` - Processes JSON-RPC messages
- `A2AStarletteApplication` - HTTP server implementation
**Script:** `scripts/expose-agent.sh`
### 2. Consuming External Agents (Client-Side)
**When to use:** Integrate remote A2A agents as sub-agents
**Template:** `templates/a2a-client.py`
**Key Components:**
- `A2ACardResolver` - Discovers remote agent capabilities
- `send_task` tool - Sends messages to remote agents
- Session tracking - Maintains context across interactions
**Script:** `scripts/consume-agent.sh`
### 3. Multi-Agent Communication
**When to use:** Orchestrate multiple specialized agents collaborating on complex tasks
**Template:** `templates/multi-agent-orchestration.py`
**Pattern:**
- Coordinator agent routes tasks
- Specialist agents handle specific domains
- Agent-to-agent messaging via A2A protocol
- Result aggregation and synthesis
**Example:** `examples/purchasing-concierge/`
### 4. Agent Card Configuration
**When to use:** Define agent capabilities for discovery
**Template:** `templates/agent-card.json`
**Contents:**
- Agent metadata (name, description, version)
- Capabilities and skills
- Supported modalities (text, audio, video)
- Endpoint URLs and protocol version
- Streaming support indicators
**Script:** `scripts/generate-agent-card.sh`
## Implementation Patterns
### Server-Side: Exposing an Agent
```python
# templates/a2a-server.py structure
from adk import Agent
from a2a import AgentExecutor, DefaultRequestHandler, AgentCard
class MyAgentExecutor(AgentExecutor):
"""Handle incoming A2A requests"""
async def execute(self, request):
# Process request using your agent
result = await self.agent.run(request.message)
return result
# Configure Agent Card
agent_card = AgentCard(
name="my-agent",
description="Agent description",
capabilities=["skill1", "skill2"],
endpoint="https://my-agent.example.com"
)
# Expose via HTTP
from a2a import A2AStarletteApplication
app = A2AStarletteApplication(
executor=MyAgentExecutor(),
card=agent_card
)
```
**Deployment:**
```bash
# Deploy to Cloud Run
bash scripts/expose-agent.sh --platform cloud-run
# Deploy to Agent Engine
bash scripts/expose-agent.sh --platform agent-engine
# Deploy to GKE
bash scripts/expose-agent.sh --platform gke
```
### Client-Side: Consuming an Agent
```python
# templates/a2a-client.py structure
from adk import Agent
from a2a import A2ACardResolver, send_task
# Discover remote agent
resolver = A2ACardResolver()
agent_card = await resolver.resolve("https://remote-agent.example.com")
# Create tool to communicate with remote agent
send_task_tool = send_task(
agent_url=agent_card.endpoint,
session_id="unique-session-id"
)
# Use in your agent
my_agent = Agent(
tools=[send_task_tool],
# ... other config
)
# Agent can now invoke remote agent
result = await my_agent.run("Ask the remote agent to do something")
```
### Multi-Agent Orchestration
```python
# templates/multi-agent-orchestration.py structure
from adk import Agent
from a2a import A2ACardResolver, send_task
# Discover specialist agents
resolver = A2ACardResolver()
research_agent = await resolver.resolve("https://research-agent.example.com")
analysis_agent = await resolver.resolve("https://analysis-agent.example.com")
writing_agent = await resolver.resolve("https://writing-agent.example.com")
# Coordinator agent
coordinator = Agent(
name="coordinator",
tools=[
send_task(agent_url=research_agent.endpoint),
send_task(agent_url=analysis_agent.endpoint),
send_task(agent_url=writing_agent.endpoint)
],
instructions="""
You coordinate multiple specialist agents:
1. Use research agent to gather information
2. Use analysis agent to process findings
3. Use writing agent to synthesize results
"""
)
# Execute multi-agent workflow
result = await coordinator.run("Research and write a report on AI agents")
```
## Agent Card Structure
```json
{
"id": "my-agent",
"name": "My Agent",
"description": "Description of agent capabilities",
"version": "1.0.0",
"url": "https://my-agent.example.com",
"capabilities": {
"skills": [
{
"name": "skill1",
"description": "First skill description"
},
{
"name": "skill2",
"description": "Second skill description"
}
],
"modalities": ["text", "image"],
"streaming": true
},
"protocol": {
"version": "0.3",
"transport": "grpc"
}
}
```
**Generation:**
```bash
bash scripts/generate-agent-card.sh \
--name "my-agent" \
--description "Agent description" \
--skills "skill1,skill2" \
--modalities "text,image" \
--url "https://my-agent.example.com"
```
## Protocol Configuration
### gRPC Transport (A2A v0.3+)
```python
# templates/grpc-config.py
from a2a import A2AStarletteApplication, GrpcTransport
app = A2AStarletteApplication(
executor=MyAgentExecutor(),
transport=GrpcTransport(
host="0.0.0.0",
port=50051,
secure=True,
cert_file="/path/to/cert.pem",
key_file="/path/to/key.pem"
)
)
```
### Security Cards (A2A v0.3+)
```python
# templates/security-card.py
from a2a import SecurityCard, sign_card
# Create security card
security_card = SecurityCard(
issuer="my-organization",
audience=["trusted-agent-1", "trusted-agent-2"],
permissions=["read", "write"]
)
# Sign the card
signed_card = sign_card(
card=security_card,
private_key="/path/to/private-key.pem"
)
```
### JSON-RPC Message Format
**Request:**
```json
{
"id": "request-uuid",
"jsonrpc": "2.0",
"method": "message/send",
"params": {
"message": "Task description",
"session_id": "session-uuid",
"context": {}
}
}
```
**Response:**
```json
{
"id": "request-uuid",
"jsonrpc": "2.0",
"result": {
"message": "Agent response",
"artifacts": [],
"status": "completed"
}
}
```
## Scripts
### 1. Expose Agent via A2A
```bash
bash scripts/expose-agent.sh --platform cloud-run --region us-central1
```
**What it does:**
- Generates Agent Card at `/.well-known/agent.json`
- Creates Dockerfile with A2A server
- Deploys to specified platform
- Configures networking and security
- Returns agent endpoint URL
### 2. Consume Remote Agent
```bash
bash scripts/consume-agent.sh --url https://remote-agent.example.com
```
**What it does:**
- Resolves Agent Card from remote URL
- Validates capabilities
- Generates client code
- Creates `send_task` tool wrapper
- Provides integration example
### 3. Generate Agent Card
```bash
bash scripts/generate-agent-card.sh \
--name "my-agent" \
--description "Agent description" \
--skills "research,analysis,writing"
```
**What it does:**
- Creates JSON Agent Card
- Validates against A2A schema
- Generates `/.well-known/agent.json`
- Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.