Skip to content

traceloop/a2a-multi-agent-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

A2A Protocol Multi-Agent System

A comprehensive multi-agent system demonstrating Agent-to-Agent (A2A) Protocol, OpenLLMetry tracing, and MCP integration through realistic AI-powered development workflows. Built for conference demonstrations and production-ready distributed agent systems.

๐ŸŽฏ What This System Does

This system features two powerful workflows with specialized agents:

๐Ÿ” Code Quality Analysis Workflow

Three review agents collaborate to analyze existing code:

  1. Security Scanner Agent - Scans for security vulnerabilities using tools like Bandit and Semgrep
  2. Code Reviewer Agent - Analyzes code quality, complexity, and style using MCP tools and linters
  3. Documentation Agent - Evaluates documentation coverage and quality

๐Ÿš€ A2A Development Workflow (Featured!)

Five agents collaborate using A2A Protocol in a complete AI-powered development lifecycle:

  1. Dev Lead Agent - Orchestrates development tasks and coordinates A2A communication
  2. Developer Agent - ๐Ÿค– Uses GPT-4o-mini to generate high-quality Python code based on requirements
  3. Security Scanner Agent - Reviews generated code for security vulnerabilities
  4. Code Reviewer Agent - ๐Ÿค– Uses GPT-4o-mini to analyze code quality with MCP tools
  5. Documentation Agent - Evaluates documentation coverage and quality

The agents use authentic A2A Protocol for discovery, authentication, and message passing, with full cross-agent trace propagation via OpenTelemetry.

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.10+
  • uv package manager (recommended) or pip

Installation & Setup

# Clone or download this project
cd multi-agent-example

# Install with uv (recommended)
uv sync --dev

# OR install with pip
pip install -e .

๐Ÿ”‘ API Keys Setup

# Copy the example environment file
cp .env.example .env

# Edit .env with your actual API keys
# Required keys:
# - OPENAI_API_KEY=sk-your-openai-api-key-here  
# - TRACELOOP_API_KEY=tl_your-traceloop-api-key-here

# Get your keys from:
# - OpenAI: https://platform.openai.com/account/api-keys
# - Traceloop: https://app.traceloop.com/settings/api-keys

Alternative: Export directly (temporary)

export OPENAI_API_KEY="your_openai_api_key_here"
export TRACELOOP_API_KEY="your_traceloop_api_key_here"

๐Ÿ”ง Optional Tools

# Enhanced security scanning (optional)
uv add bandit semgrep

# Or with pip
pip install bandit semgrep

๐Ÿš€ Running the A2A System

Complete A2A Development Workflow

# Run the complete A2A multi-agent development demo
uv run python test_a2a_complete.py

# Or test with specific requirements
uv run python -c "
import asyncio
from multi_agent_example.a2a_main import A2AMultiAgentOrchestrator

async def main():
    orchestrator = A2AMultiAgentOrchestrator()
    await orchestrator.initialize()
    
    # Run development workflow
    result = await orchestrator.run_development_workflow(
        task_description='Create a secure authentication system',
        requirements=[
            'Implement JWT token authentication',
            'Add password hashing with bcrypt', 
            'Include rate limiting protection',
            'Add comprehensive error handling'
        ]
    )
    
    await orchestrator.shutdown()

asyncio.run(main())
"

Test Traceloop Integration

# Set your Traceloop API key first
export TRACELOOP_API_KEY="your_key_here"

# Run with Traceloop export
uv run python test_traceloop_export.py

# Check dashboard at: https://app.traceloop.com

Quick Development Test

# Test A2A system without Traceloop (uses demo key)
uv run python test_a2a_complete.py

๐Ÿ—๏ธ Architecture

๐Ÿ”— A2A Protocol Architecture

  • Authentic A2A Protocol: Uses official a2a-sdk for genuine agent-to-agent communication
  • Agent Discovery: Automatic discovery via A2A endpoints (/.well-known/agent-card.json)
  • Message Passing: JSON-RPC message format with proper A2A validation
  • RequestHandler: Complete A2A RequestHandler implementation with proper method signatures
  • Agent Cards: Full A2A AgentCard, AgentSkill, and AgentCapability definitions
  • Port Management: Each agent runs on dedicated ports (8001-8006)

๐Ÿ“Š OpenTelemetry Tracing & Observability

  • Cross-Agent Trace Propagation: W3C Trace Context headers across HTTP requests
  • Traceloop Export: Professional dashboard for trace visualization and analysis
  • FastAPI Instrumentation: Automatic tracing of HTTP server requests/responses
  • HTTPX Instrumentation: Client-side HTTP request tracing
  • Custom Spans: Business logic spans with agent names, operations, and metadata
  • Dashboard Waterfall: Complete cross-agent request flow visualization

MCP Integration

  • Code Reviewer agent uses MCP tools for advanced analysis:
    • AST analyzer for code structure analysis
    • Complexity calculator for cyclomatic complexity
    • Style checker for code formatting compliance
  • Demonstrates protocol-based tool integration

๐Ÿ”ง Features

๐Ÿค– AI-Powered Development

  • GPT-4o-mini Code Generation: Fast, cost-effective, high-quality Python code generation
  • AI Code Review: Intelligent feedback on code quality, security, and best practices
  • Smart Requirements Analysis: AI understands and implements complex requirements
  • Contextual Suggestions: AI provides specific, actionable improvement recommendations
  • Cost-Effective: Uses GPT-4o-mini for optimal performance/cost balance

Real-World Problem Solving

  • Security Analysis: Detects SQL injection, XSS, hardcoded secrets, etc.
  • Code Quality: Measures complexity, style compliance, maintainability
  • Documentation: Analyzes docstring coverage and quality
  • Actionable Reports: Prioritized improvement recommendations

Agent Collaboration

  • Agents share results and coordinate analysis phases
  • Cross-referencing findings for comprehensive assessment
  • Distributed decision making and result aggregation

Observability

  • Rich console output with progress indicators
  • Detailed tracing of agent interactions
  • Performance metrics and operation timings
  • Visual result displays with tables and panels

๐Ÿ“Š Sample Output

๐Ÿงช Testing Complete A2A Protocol Multi-Agent System
๐ŸŒŸ Demonstrating authentic Agent-to-Agent Protocol communication
================================================================================

๐Ÿš€ A2A Multi-Agent System
๐ŸŽฏ Initializing Agent-to-Agent Protocol Communication

Traceloop exporting traces to https://api.traceloop.com authenticating with bearer token
โœ… Traceloop SDK initialized
๐Ÿš€ FastAPI instrumentation enabled
๐Ÿ“ก HTTPX client instrumentation enabled
๐Ÿ”— Cross-agent trace propagation activated
๐Ÿ“Š Traces will be exported to Traceloop: https://api.traceloop.com
๐Ÿ” View traces at: https://app.traceloop.com

๐Ÿค– Initializing agents...
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ A2A Agent Startup โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ ๐Ÿค– Agent Security Scanner initializing with A2A Protocol                     โ”‚
โ”‚ ๐Ÿ“ ID: security_scanner_2587bd69                                             โ”‚
โ”‚ ๐ŸŒ A2A Port: 8001                                                            โ”‚
โ”‚ ๐Ÿ“‹ Description: A2A-based security vulnerability scanner                     โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

                         ๐ŸŽญ A2A Agent Network Overview                          
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ณโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”“
โ”ƒ Agent               โ”ƒ Port โ”ƒ Capabilities                         โ”ƒ  Status  โ”ƒ
โ”กโ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ•‡โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”ฉ
โ”‚ Security Scanner    โ”‚ 8001 โ”‚ vulnerability_scan, security_report  โ”‚ โ— Active โ”‚
โ”‚ Code Reviewer Agent โ”‚ 8002 โ”‚ code_quality_review, ai_insights     โ”‚ โ— Active โ”‚
โ”‚ Documentation Agent โ”‚ 8003 โ”‚ documentation_analysis               โ”‚ โ— Active โ”‚
โ”‚ Dev Lead Agent      โ”‚ 8005 โ”‚ orchestrate_development_workflow     โ”‚ โ— Active โ”‚
โ”‚ Developer Agent     โ”‚ 8006 โ”‚ generate_code, refactor_code         โ”‚ โ— Active โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Starting A2A Development Workflow...
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ ๐Ÿ†• Development Task task_185 โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ ๐Ÿ“‹ Create a calculator function for A2A demo                                 โ”‚
โ”‚ โšก Priority: HIGH                                                            โ”‚
โ”‚ Requirements:                                                                โ”‚
โ”‚   โ€ข Create a function that can add, subtract, multiply, and divide           โ”‚
โ”‚   โ€ข Include proper error handling for division by zero                       โ”‚
โ”‚   โ€ข Add comprehensive docstring with examples                                โ”‚
โ”‚   โ€ข Use type hints for better code quality                                   โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

โšก Phase 2: Code Generation
๐Ÿ“ค Dev Lead Agent โ†’ Developer Agent: A2A Message
๐Ÿง  Sending request to GPT-4o-mini...
โœ… Code generation completed successfully!

๐Ÿ” Phase 3: Multi-Agent Review
๐Ÿ“ค Dev Lead Agent โ†’ Security Scanner: A2A Message
๐Ÿ“ค Dev Lead Agent โ†’ Code Reviewer Agent: A2A Message
๐Ÿ“ค Dev Lead Agent โ†’ Documentation Agent: A2A Message

================================================================================
๐ŸŽ‰ A2A PROTOCOL MULTI-AGENT SYSTEM TEST SUCCESSFUL!
๐Ÿš€ Ready for conference demonstration!
================================================================================

๐Ÿ“Š A2A Workflow Results:
  โœ… Status: completed
  ๐Ÿ”ง Workflow Phases: 4/4
  ๐Ÿ’ป Code Generated: โœ…
  ๐Ÿ” Agent Reviews: 3
  ๐ŸŽฏ Final Assessment: GOOD

๐ŸŒ A2A Agent Network Status:
  โ€ข Active Agents: 5
  โ€ข A2A Protocol: โœ… Operational
  โ€ข Cross-Agent Tracing: โœ… Active
  โ€ข AI Integration: โœ… Available

๐Ÿ› ๏ธ Configuration

Environment Variables

Recommended: Use .env file (automatically loaded)

# Copy and edit the environment file
cp .env.example .env

# The .env file contains:
OPENAI_API_KEY=sk-your-openai-api-key-here
TRACELOOP_API_KEY=tl_your-traceloop-api-key-here
TRACELOOP_BASE_URL=https://api.traceloop.com
ENVIRONMENT=development
DEBUG=false

Alternative: Export directly

export OPENAI_API_KEY="your_openai_api_key"
export TRACELOOP_API_KEY="your_traceloop_api_key"

A2A Agent Ports

  • Security Scanner: 8001
  • Code Reviewer: 8002
  • Documentation Agent: 8003
  • Dev Lead Agent: 8005
  • Developer Agent: 8006

๐Ÿ“Š Traceloop Dashboard

Once running with TRACELOOP_API_KEY, visit https://app.traceloop.com to see:

  • ๐ŸŒŠ Trace Waterfall: Complete cross-agent request flow visualization
  • ๐Ÿ“Š Performance Metrics: Request timing, duration, and throughput
  • ๐Ÿ” Error Analysis: Failed requests and exception tracking
  • ๐Ÿ“ˆ Service Map: Agent relationships and communication patterns
  • ๐ŸŽฏ Business Metrics: Code generation success rates, review scores

๐ŸŽฏ What You'll See in Traceloop

With your API key configured, the dashboard will show:

  • ๐Ÿ“Š Service Map: Visual network of your 5 A2A agents and their connections
  • ๐ŸŒŠ Trace Waterfall: Complete request flow from Dev Lead โ†’ Developer โ†’ Reviewers
  • ๐Ÿ“ˆ Performance Metrics: Request timing, spans per trace, success rates
  • ๐Ÿ” Span Details: Agent names, message types, business context attributes
  • ๐Ÿšจ Error Tracking: Failed requests with stack traces and retry attempts

๐ŸŽช Conference Demo Features

This system was designed for conference presentations and includes:

๐ŸŽฏ Authentic A2A Protocol Implementation

  • Real A2A SDK: Uses official a2a-sdk, not custom HTTP APIs
  • Complete Protocol: Agent discovery, capability exchange, message validation
  • Production Ready: Full RequestHandler implementation with proper error handling

๐Ÿ” Comprehensive Tracing & Observability

  • Cross-Agent Propagation: W3C Trace Context headers across all agent communication
  • Traceloop Dashboard: Professional waterfall visualization and service map
  • Real-time Monitoring: See traces as they happen during demo
  • Business Context: Spans include agent names, operations, and workflow stages

๐Ÿค– AI-Powered Workflows

  • GPT-4o-mini Integration: Cost-effective, high-quality code generation and review
  • Realistic Use Cases: Security scanning, code review, documentation analysis
  • Multi-Agent Collaboration: Agents coordinate to solve complex development tasks
  • MCP Tool Integration: Advanced code analysis with protocol-based tools

๐ŸŽจ Engaging Presentation Features

  • Rich Visual Output: Colorful tables, panels, and progress indicators
  • Live Agent Network: Real-time display of active agents and their capabilities
  • Interactive Workflows: Watch AI agents collaborate in real-time
  • Conference Ready: Professional output suitable for large screen projection

๐Ÿ” Technical Stack

  • A2A Protocol: Official a2a-sdk for authentic agent communication
  • OpenTelemetry: Industry standard distributed tracing
  • FastAPI: Modern async HTTP framework for agent servers
  • Traceloop: Professional trace visualization and analysis
  • Rich: Beautiful terminal output with colors and formatting
  • OpenAI GPT-4o-mini: Cost-effective AI for code generation and review
  • AsyncIO: Concurrent agent operations and HTTP communication
  • Pydantic: Data validation and serialization
  • MCP: Model Context Protocol for advanced tool integration

๐Ÿค Agent Capabilities

Each agent exposes its capabilities via REST API:

# List agent capabilities
curl http://localhost:8001/capabilities
curl http://localhost:8002/capabilities  
curl http://localhost:8003/capabilities

# Check agent health
curl http://localhost:8001/health

๐Ÿšง Extending the System

To add new agents:

  1. Inherit from BaseAgent
  2. Implement required abstract methods
  3. Add to CodeQualityOrchestrator.agent_classes
  4. Define capabilities and message handlers

Example agent skeleton:

class MyAgent(BaseAgent):
    def __init__(self):
        super().__init__("My Agent", 8004, "Does something useful")
    
    async def initialize(self):
        # Setup agent-specific resources
        pass
    
    def get_capabilities(self):
        return [AgentCapability(...)]
    
    async def process_message(self, message):
        # Handle incoming messages
        pass
    
    async def perform_analysis(self, target):
        # Main agent logic
        return {}

๐Ÿ“ License

MIT License - feel free to use this in your own projects and presentations!

๐Ÿš€ Complete Setup Guide

1๏ธโƒฃ Installation

git clone <this-repo>
cd multi-agent-example
uv sync --dev

2๏ธโƒฃ API Keys

# Copy and configure environment file
cp .env.example .env

# Edit .env file with your actual API keys:
# OPENAI_API_KEY=sk-your-key-here
# TRACELOOP_API_KEY=tl_your-key-here

# Get your keys from:
# - OpenAI: https://platform.openai.com/account/api-keys  
# - Traceloop: https://app.traceloop.com/settings/api-keys

3๏ธโƒฃ Run Complete Demo

# Full A2A system with AI-powered development workflow
uv run python test_a2a_complete.py

# OR test Traceloop dashboard integration
uv run python test_traceloop_export.py

4๏ธโƒฃ View Results

  • Console: Rich visual output with A2A agent communication
  • Dashboard: https://app.traceloop.com (shows cross-agent waterfall)

๐Ÿ’ก Note: The .env file is git-ignored for security. Each developer needs to create their own .env file with their API keys.

๐ŸŽฏ Perfect For

๐Ÿ“š Conference Presentations

  • Live Demo: Watch AI agents collaborate in real-time
  • Visual Appeal: Rich console output + professional dashboard
  • Technical Depth: Real A2A Protocol + OpenTelemetry tracing
  • Audience Engagement: Relatable AI-powered development workflow

๐ŸŽ“ Educational Use

  • Distributed Systems: Agent communication patterns and discovery
  • Observability: Cross-service tracing and monitoring
  • AI Integration: Practical GPT-4o-mini usage in multi-agent systems
  • Modern Protocols: A2A, OpenTelemetry, MCP integration

๐Ÿข Production Insights

  • Agent Architecture: Scalable multi-agent system design
  • Trace Propagation: W3C standards implementation
  • Error Handling: Robust failure modes and recovery
  • Performance Monitoring: Real-time observability patterns

๐Ÿ™‹โ€โ™‚๏ธ Questions?

This system demonstrates cutting-edge multi-agent architecture with:

โœ… Authentic A2A Protocol (not toy HTTP APIs)
โœ… Production-grade tracing (OpenTelemetry + Traceloop)
โœ… Real AI integration (GPT-4o-mini for development workflows)
โœ… Professional presentation (Rich visuals + dashboard)

Perfect for conference demonstrations, educational workshops, and production architecture examples!

About

Multi-agent system with A2A Protocol, OpenTelemetry tracing, and AI-powered code generation workflows

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages