-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_a2a_complete.py
More file actions
107 lines (87 loc) · 4.2 KB
/
test_a2a_complete.py
File metadata and controls
107 lines (87 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/usr/bin/env python3
"""
Complete A2A Protocol Multi-Agent System Test
"""
import asyncio
import os
import signal
import sys
from rich.console import Console
# Load environment variables from .env file
from load_env import load_environment, check_required_keys
load_environment()
# Set fallback demo keys if not configured
os.environ.setdefault("OPENAI_API_KEY", "demo-key")
os.environ.setdefault("TRACELOOP_API_KEY", "demo-key")
from multi_agent_example.a2a_main import A2AMultiAgentOrchestrator
console = Console()
async def test_complete_a2a_system():
"""Test the complete A2A Protocol multi-agent system"""
console.print("🧪 [bold yellow]Testing Complete A2A Protocol Multi-Agent System[/bold yellow]")
console.print("🌟 [cyan]Demonstrating authentic Agent-to-Agent Protocol communication[/cyan]")
console.print("=" * 80)
orchestrator = None
try:
# Initialize the complete A2A system
orchestrator = A2AMultiAgentOrchestrator()
await orchestrator.initialize()
# Run development workflow
console.print("\n🚀 [blue]Testing A2A Development Workflow...[/blue]")
result = await orchestrator.run_development_workflow(
task_description="Create a calculator function for A2A demo",
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"
]
)
# Display results
console.print("\n📊 [green]A2A Workflow Results:[/green]")
if "error" not in result:
console.print(f" ✅ Status: {result.get('status', 'completed')}")
console.print(f" 🔧 Workflow Phases: {result.get('workflow_phases_completed', 0)}/4")
console.print(f" 💻 Code Generated: {'✅' if result.get('code_generated') else '❌'}")
console.print(f" 🔍 Agent Reviews: {result.get('reviews_completed', 0)}")
console.print(f" 🎯 Final Assessment: {result.get('final_summary', {}).get('overall_assessment', 'N/A')}")
else:
console.print(f" ❌ Error: {result.get('error')}")
# Test A2A communication
console.print("\n📡 [blue]Testing A2A Protocol Communication...[/blue]")
await orchestrator.demonstrate_a2a_communication()
# Display agent network status
console.print(f"\n🌐 [green]A2A Agent Network Status:[/green]")
console.print(f" • Active Agents: {len(orchestrator.agents)}")
console.print(f" • A2A Protocol: ✅ Operational")
console.print(f" • Cross-Agent Tracing: ✅ Active")
console.print(f" • AI Integration: ✅ Available")
# Wait briefly to show system stability
console.print(f"\n⏱️ [yellow]System running for 3 seconds...[/yellow]")
await asyncio.sleep(3)
console.print("\n" + "=" * 80)
console.print("🎉 [bold green]A2A PROTOCOL MULTI-AGENT SYSTEM TEST SUCCESSFUL![/bold green]")
console.print("🚀 [cyan]Ready for conference demonstration![/cyan]")
console.print("=" * 80)
except Exception as e:
console.print(f"\n❌ [red]Test failed: {e}[/red]")
import traceback
console.print(f"[dim]{traceback.format_exc()}[/dim]")
finally:
if orchestrator:
console.print("\n🛑 [yellow]Shutting down A2A system...[/yellow]")
await orchestrator.shutdown()
console.print("✅ [green]Test cleanup complete[/green]")
def signal_handler(sig, frame):
"""Handle Ctrl+C gracefully"""
console.print(f"\n🛑 [yellow]Received interrupt signal, shutting down...[/yellow]")
sys.exit(0)
if __name__ == "__main__":
# Handle Ctrl+C gracefully
signal.signal(signal.SIGINT, signal_handler)
try:
asyncio.run(test_complete_a2a_system())
except KeyboardInterrupt:
console.print("🛑 [yellow]Test interrupted[/yellow]")
except Exception as e:
console.print(f"❌ [red]Test failed: {e}[/red]")
sys.exit(1)