This directory contains practical examples demonstrating how to use the Python A2A library. Each example is designed to showcase different aspects of the A2A protocol and help you quickly implement agent-to-agent communication in your projects.
If you're new to Python A2A, start with these examples:
- Hello A2A - Create your first A2A messages in just a few lines of code
- Simple Client - Connect to any A2A-compatible agent
- Simple Server - Create your own basic A2A server
- Basic Streaming - Implement real-time streaming responses
These examples provide a gentle introduction to A2A concepts:
| Example | Description | Key Learning |
|---|---|---|
| Hello A2A | The simplest possible example | Creating basic messages |
| Simple Client | Connect to any A2A agent | Sending requests and handling responses |
| Simple Server | Build a basic A2A server | Creating your first agent |
| Function Calling | Add function calling capabilities | Executing functions through A2A |
These examples demonstrate how to implement streaming responses:
| Example | Description | Key Learning |
|---|---|---|
| Basic Streaming | Simple streaming implementation | Creating and consuming streams |
| Advanced Streaming | Advanced streaming techniques | Metrics tracking and chunking strategies |
| LLM Integration | Stream from LLM providers | Connecting provider APIs with A2A streaming |
| Task-Based Streaming | Structured streaming with tasks | Progress tracking and artifacts |
| UI Integration | Stream to user interfaces | CLI and web-based streaming visualization |
| Distributed Streaming | Multi-node streaming | Load balancing and fault tolerance |
These examples demonstrate fundamental A2A components:
| Example | Description | Key Learning |
|---|---|---|
| Agent Discovery | Create and understand agent cards | Agent capability discovery |
| Messages and Conversations | Work with message objects | Building complex conversations |
| Tasks | Understand the A2A task model | Managing stateful agent interactions |
| Agent Skills | Create agents with defined skills | Using decorators for clean agent definitions |
Connect A2A to various AI services:
| Example | Description | Key Learning |
|---|---|---|
| OpenAI Agent | Create GPT-powered agents | Connecting to OpenAI |
| Anthropic Agent | Create Claude-powered agents | Connecting to Anthropic |
| Bedrock Agent | Use AWS Bedrock models | Connecting to AWS Bedrock |
| LLM Client | Direct connection to LLMs | Working with various LLM providers |
Build and manage networks of cooperating agents:
| Example | Description | Key Learning |
|---|---|---|
| Basic Workflow | Create condition-based workflows | Building and executing agent workflows |
| Parallel Workflow | Execute tasks concurrently | Parallel execution for better performance |
| Agents Workflow | Orchestrate LLM-powered agents | Intelligent routing between AI models |
| Smart Routing | Route queries to specialized agents | AI-driven query analysis and routing |
| Agent Discovery | Automatically discover available agents | Dynamic agent network management |
Add external tool capabilities to your agents with the new provider architecture:
| Example | Description | Key Learning |
|---|---|---|
| GitHub MCP Provider | Complete GitHub integration | Repository management, issues, pull requests via GitHub MCP server |
| Browserbase MCP Provider | Browser automation and web scraping | Cloud-based browser automation with Browserbase MCP server |
| Filesystem MCP Provider | Secure file operations | Sandboxed file management via Filesystem MCP server |
| MCP Tools | Create MCP-compatible tools | Defining tools for AI agents |
| MCP Agent | Build agents that use MCP tools | Connecting agents to tools |
| OpenAI MCP Agent | OpenAI agent with MCP tools | Combining OpenAI with external tools |
End-to-end examples for real-world use cases:
| Example | Description | Key Learning |
|---|---|---|
| Weather Assistant | Weather information agent | Building a domain-specific agent |
| OpenAI Travel Planner | AI-powered travel planner | Combining multiple capabilities |
Tools to enhance your development workflow:
| Example | Description | Key Learning |
|---|---|---|
| CLI Tools | Command-line tools | Working with A2A via terminal |
| Interactive Docs | Generate API documentation | Creating documentation for your agents |
| Testing Agents | Test A2A agents | Writing tests for agents |
- AI/ML Engineers: Start with the AI-powered agent examples to see how to integrate with LLMs
- Backend Developers: Begin with the building blocks examples to understand the core protocol
- Frontend Developers: The simple client example shows how to connect to A2A agents
- DevOps Engineers: Check the CLI tools example for automation capabilities
- I want to call an existing AI agent: Simple Client
- I need to build my own agent: Simple Server or Agent Skills
- I want to use OpenAI with A2A: OpenAI Agent
- I need to implement streaming responses: Basic Streaming
- I want to integrate streaming with LLMs: LLM Integration
- I need to build a streaming UI: UI Integration
- I need to route queries to specialized agents: Smart Routing
- I want to execute tasks concurrently: Parallel Workflow
- I need to create agent workflows: Basic Workflow
- I want to discover agents automatically: Agent Discovery
- I need GitHub integration for my agent: GitHub MCP Provider
- I want browser automation capabilities: Browserbase MCP Provider
- I need secure file operations: Filesystem MCP Provider
- I need to add external tools to my agent: MCP Tools
- I want to build a complete application: Weather Assistant
Most examples can be run with:
python example_name.pySome examples require API keys or additional setup. Check the comments at the top of each file for specific requirements and instructions.
# For basic examples
pip install python-a2a
# For server examples
pip install "python-a2a[server]"
# For LLM integration
pip install "python-a2a[openai]" "python-a2a[anthropic]" "python-a2a[bedrock]"
# For MCP (tool) support
pip install "python-a2a[mcp]"
# For everything
pip install "python-a2a[all]"For a structured learning experience, we recommend following this sequence:
- Start with the basics: Run through the Getting Started examples
- Understand core concepts: Explore the Building Blocks examples
- Add AI capabilities: Try the AI-Powered Agents examples
- Implement streaming: Explore the Streaming examples for real-time responses
- Learn agent networking: Experiment with the Agent Network examples
- Extend with tools: Experiment with the MCP examples
- Build complete applications: Study the Applications examples
- Improve your workflow: Use the Developer Tools examples
Have an idea for a new example? We welcome contributions! Please check the CONTRIBUTING.md file for guidelines.
The python-a2a project includes a comprehensive validation system to ensure all examples work correctly. This is especially valuable before releases or after making significant changes.
# Validate all examples
python validate_all_examples.py
# Validate a specific category
python validate_all_examples.py --category streaming
# Skip slow examples for faster validation
python validate_all_examples.py --skip-slow
# Run examples concurrently for faster validation (be careful with server examples)
python validate_all_examples.py --concurrent 3
# Show detailed output for debugging
python validate_all_examples.py --verboseThe validation script provides detailed output including:
- Overall success/failure statistics
- Category-by-category results
- Detailed error messages for failing examples
- Skipped examples (due to missing dependencies or API keys)
Example output:
===============================================================================
VALIDATION SUMMARY
===============================================================================
Overall Results:
Total examples: 42
Passed: 39
Failed: 2
Skipped: 1
Category Results:
getting_started: [All 4 passed]
building_blocks: [All 4 passed]
streaming: [6/7 passed, 1 failed]
ai_powered_agents: [3/4 passed, 1 failed]
applications: [All 2 passed]
agent_network: [All 3 passed]
workflows: [All 3 passed]
mcp: [All 3 passed]
langchain: [All 4 passed]
developer_tools: [All 3 passed]
Failed Examples:
• streaming/06_distributed_streaming.py: Example timed out after 30 seconds
• ai_powered_agents/openai_agent.py: Missing API key environment variable: OPENAI_API_KEY
Skipped Examples:
• applications/openai_travel_planner.py: Skipped (missing API key: OPENAI_API_KEY)
--------------------------------------------------------------------------------
✗ Validation found 2 failing examples.
--------------------------------------------------------------------------------
- Run validation before submitting pull requests
- Run validation after making significant changes
- Include validation in CI/CD pipelines
- Use
--categoryto focus on specific areas you're working on
All examples are released under the MIT License. See the LICENSE file for details.