Skip to content

Commit f110d44

Browse files
committed
A2A protocol added as part of the framework - demo
1 parent 35bbbcb commit f110d44

41 files changed

Lines changed: 10617 additions & 45 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ deploy.log
99
__pycache__
1010
*.log
1111
*agents_state.json
12+
.env.example
1213

1314
# .tfstate files
1415
*.tfstate

README.md

Lines changed: 90 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Demo: Zava AI Shopping Assistant <br/> Multi-Agent Architecture - Overview
1+
# Demo: Zava AI Shopping Assistant <br/> Multi-Agent Architecture with A2A Protocol - Overview
22

33
Costa Rica
44

@@ -9,9 +9,11 @@ Last updated: 2025-11-12
99

1010
----------
1111

12+
1213
> [!IMPORTANT]
1314
> Disclaimer: This repository contains a demo of `Zava AI Shopping Assistant`, a multi-agent system designed for e-commerce. It features a fully automated `"Zero-Touch" deployment` pipeline orchestrated by Terraform, which `provisions infrastructure, ingests data, creates real AI agents in Azure AI Foundry, and deploys the application container.` Please refer [TechWorkshop L300: AI Apps and Agents](https://microsoft.github.io/TechWorkshop-L300-AI-Apps-and-agents/), and if needed contact Microsoft directly: [Microsoft Sales and Support](https://support.microsoft.com/contactus?ContactUsExperienceEntryPointAssetId=S.HP.SMC-HOME) more guindace. There are tons of free resources out there, all eager to support!
1415
16+
1517
<img width="1905" height="1086" alt="image" src="https://github.com/user-attachments/assets/5cd2776f-4606-45c2-9482-53ff2d4df74e" />
1618

1719
> [!IMPORTANT]
@@ -22,30 +24,69 @@ Last updated: 2025-11-12
2224
2325
## Key Features
2426

25-
- **Multi-Agent Architecture**: Few specialized AI agents working in concert:
26-
- **Cora (Shopper)**: Front-facing assistant for general queries.
27-
- **Inventory Manager**: Checks stock availability.
28-
- **Customer Loyalty**: Manages rewards and discounts.
29-
- **Cart Manager**: Handles shopping cart operations.
30-
- **Real Azure AI Agents**: Integrates with **Azure AI Foundry** to create and host persistent agents (not just local simulations).
31-
- **Zero-Touch Deployment**: A single [terraform apply](./terraform-infrastructure/README.md) command handles the entire lifecycle from infrastructure to application code.
32-
- **Intelligent Routing**: A dedicated Handoff Service classifies user intent and routes messages to the appropriate specialist agent.
33-
- **Data Pipeline Automation**: Automatically ingests product catalogs into Cosmos DB and builds Vector Search indexes.
27+
- **A2A Protocol Implementation**: Complete Agent-to-Agent communication framework with standardized messaging, event handling, and task coordination
28+
- **Multi-Agent Architecture**: Specialized AI agents working through A2A protocol:
29+
- **Cora (Shopper)**: Front-facing assistant for general queries
30+
- **Inventory Manager**: Checks stock availability via A2A requests
31+
- **Customer Loyalty**: Manages rewards and discounts through agent coordination
32+
- **Cart Manager**: Handles shopping cart operations with inter-agent communication
33+
- **Real Azure AI Agents**: Integrates with **Azure AI Foundry** to create and host persistent agents (not just local simulations)
34+
- **Zero-Touch Deployment**: A single [terraform apply](./terraform-infrastructure/README.md) command handles the entire lifecycle including A2A framework deployment
35+
- **A2A Intelligent Routing**: Enhanced Handoff Service that supports both traditional routing and A2A protocol agent discovery
36+
- **Data Pipeline Automation**: Automatically ingests product catalogs with A2A event notifications and coordination
37+
38+
39+
40+
## About A2A Protocol
41+
42+
**A2A (Agent-to-Agent) Protocol** is a standardized communication framework that enables multiple AI agents to collaborate and coordinate tasks seamlessly. This repository implements a complete A2A protocol system that demonstrates:
43+
44+
> What is A2A Protocol?
45+
- **Agent-to-Agent Communication**: Structured messaging between multiple AI agents
46+
- **Task Coordination**: Agents can delegate tasks to specialized agents
47+
- **Event-Driven Architecture**: Real-time event handling for agent interactions
48+
- **Agent Discovery**: Automatic detection and registration of available agents
49+
- **Protocol Standardization**: Consistent API for inter-agent communication
50+
51+
> A2A Components in This Project:
52+
- **Agent Execution Framework**: Manages multiple agent instances (`src/a2a/server/agent_execution.py`)
53+
- **Event Queue System**: Handles inter-agent communication (`src/a2a/server/events/`)
54+
- **Task Management**: Coordinates work between agents (`src/a2a/server/tasks.py`)
55+
- **Request Handlers**: Processes agent-to-agent requests (`src/a2a/server/request_handlers.py`)
56+
- **Coordinator Agent**: Orchestrates multi-agent workflows (`src/a2a/agent/coordinator.py`)
57+
- **API Endpoints**: RESTful and WebSocket APIs for agent communication (`src/a2a/api/`)
58+
59+
> A2A vs Traditional Multi-Agent Systems:
60+
- **Standardized Protocol**: Uses consistent message formats and APIs
61+
- **Scalable Architecture**: Easily add new agents without modifying existing ones
62+
- **Real-time Communication**: WebSocket support for instant agent interactions
63+
- **Event-Driven**: Asynchronous event handling for better performance
64+
- **Infrastructure Integration**: Full Terraform deployment with monitoring and automation
3465

3566
## Architecture
3667

3768
```mermaid
3869
graph TD
3970
User[User] <--> UI[Chat Interface]
4071
UI <--> App[FastAPI Application]
41-
App <--> Handoff[Handoff Service]
42-
Handoff -->|Classifies Intent| Router{Router}
72+
App <--> A2A[A2A Protocol Server]
73+
A2A <--> EventQueue[Event Queue]
74+
A2A <--> Coordinator[A2A Coordinator]
75+
76+
Coordinator -->|A2A Protocol| Router{Agent Router}
77+
Router -->|Task Delegation| Cora[Cora Agent]
78+
Router -->|Design Tasks| Design[Interior Design Agent]
79+
Router -->|Inventory Events| Inventory[Inventory Agent]
80+
Router -->|Loyalty Tasks| Loyalty[Loyalty Agent]
81+
Router -->|Cart Events| Cart[Cart Agent]
4382
44-
Router -->|General| Cora[Cora Agent]
45-
Router -->|Design| Design[Interior Design Agent]
46-
Router -->|Stock| Inventory[Inventory Agent]
47-
Router -->|Rewards| Loyalty[Loyalty Agent]
48-
Router -->|Checkout| Cart[Cart Agent]
83+
subgraph "A2A Communication"
84+
EventQueue <--> Cora
85+
EventQueue <--> Design
86+
EventQueue <--> Inventory
87+
EventQueue <--> Loyalty
88+
EventQueue <--> Cart
89+
end
4990
5091
Inventory -->|Query| Search[Azure AI Search]
5192
Inventory -->|Lookup| Cosmos[Cosmos DB]
@@ -57,32 +98,40 @@ graph TD
5798
5899
1. **Infrastructure Provisioning**:
59100
- Creates Resource Group, Cosmos DB, Azure AI Foundry, AI Search, Storage Account, Key Vault, and Container Registry (ACR).
60-
- Deploys AI Models (`gpt-4o-mini`, `text-embedding-3-small`).
101+
- Deploys AI Models (`gpt-4o-mini`, `text-embedding-3-small`).
102+
- Sets up A2A protocol infrastructure including event queues and monitoring.
61103

62104
<img width="1859" height="900" alt="image" src="https://github.com/user-attachments/assets/cd24ab7f-5ddd-46de-b266-0d0a24c45803" />
63105

64-
2. **Data Pipeline Execution**:
106+
2. **A2A Framework Deployment**:
107+
- Initializes the Agent-to-Agent protocol server components.
108+
- Sets up event queue system for inter-agent communication.
109+
- Configures agent discovery and registration services.
110+
- Deploys A2A monitoring and automation frameworks.
111+
112+
3. **Data Pipeline Execution**:
65113
- Sets up a Python virtual environment.
66-
- Ingests `product_catalog.csv` into Cosmos DB.
114+
- Ingests `product_catalog.csv` into Cosmos DB with A2A event notifications.
67115

68116
<https://github.com/user-attachments/assets/41bf0976-0ca8-47fe-a2fa-8750bcc6f848>
69117

70-
- Creates and populates an Azure AI Search index with vector embeddings.
118+
- Creates and populates an Azure AI Search index with vector embeddings through A2A coordination.
71119

72120
<https://github.com/user-attachments/assets/37c4a8cd-73e1-4392-8755-fb018481d8cb>
73121

74-
3. **Agent Creation**:
122+
4. **Agent Creation & A2A Registration**:
75123
- Installs the `azure-ai-projects` SDK.
76124
- Connects to Azure AI Foundry.
77-
- Provisions 5 real agents with specific instructions and tool definitions
78-
- Saves the unique Agent IDs to the `.env` file.
125+
- Provisions 5 real agents with A2A protocol integration and specific instructions.
126+
- Registers agents with the A2A discovery service.
127+
- Saves the unique Agent IDs and A2A endpoints to the `.env` file.
79128

80129
<img width="1907" height="990" alt="image" src="https://github.com/user-attachments/assets/4234ead4-16e0-4bec-bbfd-3b8891d113b0" />
81130

82-
4. **Application Deployment**:
83-
- Builds the Docker container in the cloud (ACR Build).
84-
- Configures the Azure Web App with the generated Agent IDs and credentials.
85-
- Deploys the container and restarts the app.
131+
5. **Application Deployment**:
132+
- Builds the Docker container with A2A protocol support in the cloud (ACR Build).
133+
- Configures the Azure Web App with the generated Agent IDs, A2A endpoints, and credentials.
134+
- Deploys the container with A2A server components and restarts the app.
86135

87136
## Verification
88137

@@ -91,21 +140,27 @@ graph TD
91140
1. **Check the Web App**:
92141
- The Terraform output will provide the `application_url`.
93142
- Visit `https://<your-app-name>.azurewebsites.net`.
94-
- You should see the Zava chat interface.
143+
- You should see the Zava chat interface with A2A protocol support.
95144

96145
<https://github.com/user-attachments/assets/a1139528-6b37-4ac2-a1cb-771788ff45a4>
97146

98-
2. **Verify Agents**:
147+
2. **Verify A2A Protocol Endpoints**:
148+
- Check A2A Chat API: `https://<your-app-name>.azurewebsites.net/a2a/chat`
149+
- Check A2A Server API: `https://<your-app-name>.azurewebsites.net/a2a/api/docs`
150+
- Verify agent discovery: `https://<your-app-name>.azurewebsites.net/a2a/server/agents`
151+
152+
3. **Verify Agents**:
99153
- Go to the [Azure AI Foundry Portal](https://ai.azure.com).
100154
- Navigate to your project -> **Build** -> **Agents**.
101-
- You should see all 5 agents listed.
155+
- You should see all 5 agents listed with A2A protocol integration.
102156

103157
<https://github.com/user-attachments/assets/3c562ccd-cff3-4a30-b9f8-44111fb71113>
104158

105-
3. **Test Interactions**: For example:
106-
- **General**: "Hi, who are you?" (Handled by Cora)
107-
- **Inventory**: "Do you have the classic leather sofa in stock?" (Handled by Inventory Agent)
108-
- **Design**: "What colors of green paint do you have?"
159+
4. **Test A2A Interactions**: For example:
160+
- **General**: "Hi, who are you?" (Handled by Cora via A2A protocol)
161+
- **Inventory**: "Do you have the classic leather sofa in stock?" (Routed through A2A to Inventory Agent)
162+
- **Design**: "What colors of green paint do you have?" (A2A task delegation to Design Agent)
163+
- **Multi-Agent**: "Find a sofa and check my loyalty points" (A2A coordination between multiple agents)
109164

110165
<!-- START BADGE -->
111166
<div align="center">

run_a2a_server.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
A2A Protocol Test Runner
3+
4+
This script provides an easy way to test and run the A2A (Agent-to-Agent) protocol
5+
server for development and validation purposes.
6+
7+
Key frameworks and technologies used:
8+
- Uvicorn: ASGI web server implementation with support for HTTP/1.1 and WebSockets,
9+
designed for high-performance async Python web applications
10+
- AsyncIO: Python's asynchronous I/O framework enabling concurrent execution
11+
without threading, perfect for handling multiple agent communications
12+
- Python Logging: Built-in logging system for monitoring server startup and operations
13+
- Pathlib: Modern object-oriented filesystem path handling library
14+
"""
15+
import uvicorn
16+
import asyncio
17+
import logging
18+
from pathlib import Path
19+
20+
from src.a2a.config import load_config, A2AMode
21+
from src.a2a.main import create_app
22+
23+
# Configure logging
24+
logging.basicConfig(
25+
level=logging.INFO,
26+
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
27+
)
28+
logger = logging.getLogger(__name__)
29+
30+
async def test_a2a_protocol():
31+
"""Test the A2A protocol implementation"""
32+
try:
33+
# Load configuration
34+
config = load_config()
35+
logger.info(f"Loaded configuration with mode: {config.a2a.mode}")
36+
37+
# Create the application
38+
app = create_app()
39+
logger.info("✅ Application created successfully")
40+
41+
# Test agent initialization
42+
if hasattr(app.state, 'coordinator'):
43+
coordinator = app.state.coordinator
44+
agents = coordinator.get_available_agents()
45+
logger.info(f"✅ Available agents: {list(agents.keys())}")
46+
47+
# Test each agent
48+
for agent_id, agent_info in agents.items():
49+
logger.info(f" - {agent_id}: {agent_info.get('description', 'No description')}")
50+
51+
# Start server for testing
52+
config_obj = uvicorn.Config(
53+
app=app,
54+
host="localhost",
55+
port=8000,
56+
log_level="info",
57+
reload=False
58+
)
59+
server = uvicorn.Server(config_obj)
60+
61+
logger.info("🚀 Starting A2A protocol server on http://localhost:8000")
62+
logger.info(" - A2A Chat: http://localhost:8000/a2a/chat")
63+
logger.info(" - A2A API: http://localhost:8000/a2a/api/docs")
64+
logger.info(" - Legacy Chat: http://localhost:8000/chat")
65+
logger.info(" - Health: http://localhost:8000/health")
66+
67+
await server.serve()
68+
69+
except Exception as e:
70+
logger.error(f"❌ Error testing A2A protocol: {e}")
71+
import traceback
72+
logger.error(traceback.format_exc())
73+
raise
74+
75+
if __name__ == "__main__":
76+
asyncio.run(test_a2a_protocol())

src/a2a/.env_automation

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# A2A Automation Framework Configuration
2+
A2A_HOST=0.0.0.0
3+
A2A_PORT=8001
4+
A2A_LOG_LEVEL=INFO
5+
6+
# Base application URL for monitoring
7+
BASE_APP_URL=https://zava-72910920-app.azurewebsites.net
8+
9+
# Azure monitoring integration
10+
APPLICATION_INSIGHTS_CONNECTION_STRING=InstrumentationKey=cd157009-2ed7-472b-9bcf-9f83189fe438;IngestionEndpoint=https://westus3-1.in.applicationinsights.azure.com/;LiveEndpoint=https://westus3.livediagnostics.monitor.azure.com/;ApplicationId=43df942d-375b-4d95-b0b4-a85f1045018c
11+
LOG_ANALYTICS_WORKSPACE_ID=9a4604f5-a37e-4fc6-9c14-73d1d63e88d7
12+
13+
# Automation features
14+
ENABLE_PROCESS_MANAGEMENT=true
15+
ENABLE_CONTINUOUS_TESTING=true
16+
ENABLE_MONITORING_DASHBOARDS=true
17+
ENABLE_DEPLOYMENT_AUTOMATION=true
18+
19+
# Performance thresholds
20+
CPU_THRESHOLD=70.0
21+
MEMORY_THRESHOLD=80.0
22+
RESPONSE_TIME_THRESHOLD=2000
23+
ERROR_RATE_THRESHOLD=5.0
24+
25+
# Testing configuration
26+
CONTINUOUS_TESTING_INTERVAL=60
27+
LOAD_TEST_DURATION=300
28+
CONCURRENT_USERS=50
29+
MAX_RESPONSE_TIME=2000
30+
MIN_THROUGHPUT=50
31+
MAX_ERROR_RATE=0.05
32+
33+
# Storage paths
34+
AUTOMATION_STORAGE_PATH=./automation_data
35+
MONITORING_DATA_PATH=./monitoring_data
36+
TEST_RESULTS_PATH=./test_results
37+
DEPLOYMENT_LOGS_PATH=./deployment_logs

src/a2a/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"""
2+
Enhanced Agent to Agent (A2A) Protocol Implementation for Zava Shopping Assistant
3+
"""
4+
5+
__version__ = "1.0.0"
6+
__description__ = "Enhanced A2A Protocol for Multi-Agent Shopping Assistance"

src/a2a/agent/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Agent module initialization
3+
"""
4+
5+
from .agent_adapters import (
6+
ZavaAgentAdapter, InteriorDesignAgentAdapter, InventoryAgentAdapter,
7+
CustomerLoyaltyAgentAdapter, CartManagementAgentAdapter, CoraAgentAdapter
8+
)
9+
from .coordinator import A2ACoordinatorAgent, EnhancedProductManagementAgent
10+
11+
__all__ = [
12+
"ZavaAgentAdapter",
13+
"InteriorDesignAgentAdapter",
14+
"InventoryAgentAdapter",
15+
"CustomerLoyaltyAgentAdapter",
16+
"CartManagementAgentAdapter",
17+
"CoraAgentAdapter",
18+
"A2ACoordinatorAgent",
19+
"EnhancedProductManagementAgent"
20+
]

0 commit comments

Comments
 (0)