Skip to content

Commit 766dc4e

Browse files
authored
Merge pull request #9 from MicrosoftCloudEssentials-LearningHub/A2A-protocol
A2A protocol
2 parents 35bbbcb + 5e888bb commit 766dc4e

43 files changed

Lines changed: 10374 additions & 334 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: 92 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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

55
[![GitHub](https://img.shields.io/badge/--181717?logo=github&logoColor=ffffff)](https://github.com/)
66
[brown9804](https://github.com/brown9804)
77

8-
Last updated: 2025-11-12
8+
Last updated: 2025-12-03
99

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

@@ -16,36 +16,77 @@ Last updated: 2025-11-12
1616

1717
> [!IMPORTANT]
1818
> The deployment process typically takes 15-20 minutes
19+
>
1920
> 1. Adjust [terraform.tfvars](./terraform-infrastructure/terraform.tfvars) values
2021
> 2. Initialize terraform with `terraform init`. Click here to [understand more about the deployment process](./terraform-infrastructure/README.md)
2122
> 3. Run `terraform apply`, you can also leverage `terraform apply -auto-approve`.
2223
2324
## Key Features
2425

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.
26+
- **A2A Protocol Implementation**: Complete Agent-to-Agent communication framework with standardized messaging, event handling, and task coordination
27+
- **Multi-Agent Architecture**: Specialized AI agents working through A2A protocol:
28+
- **Cora (Shopper)**: Front-facing assistant for general queries
29+
- **Inventory Manager**: Checks stock availability via A2A requests
30+
- **Customer Loyalty**: Manages rewards and discounts through agent coordination
31+
- **Cart Manager**: Handles shopping cart operations with inter-agent communication
32+
- **Real Azure AI Agents**: Integrates with **Azure AI Foundry** to create and host persistent agents (not just local simulations)
33+
- **Zero-Touch Deployment**: A single [terraform apply](./terraform-infrastructure/README.md) command handles the entire lifecycle including A2A framework deployment
34+
- **A2A Intelligent Routing**: Enhanced Handoff Service that supports both traditional routing and A2A protocol agent discovery
35+
- **Data Pipeline Automation**: Automatically ingests product catalogs with A2A event notifications and coordination
36+
37+
## About A2A Protocol
38+
39+
`A2A (Agent-to-Agent) Protocol is a standardized communication framework that enables multiple AI agents to collaborate and coordinate tasks seamlessly.`
40+
41+
> What is A2A Protocol?
42+
43+
- **Agent-to-Agent Communication**: Structured messaging between multiple AI agents
44+
- **Task Coordination**: Agents can delegate tasks to specialized agents
45+
- **Event-Driven Architecture**: Real-time event handling for agent interactions
46+
- **Agent Discovery**: Automatic detection and registration of available agents
47+
- **Protocol Standardization**: Consistent API for inter-agent communication
48+
49+
> A2A Components in This Project:
50+
51+
- **Agent Execution Framework**: Manages multiple agent instances (`src/a2a/server/agent_execution.py`)
52+
- **Event Queue System**: Handles inter-agent communication (`src/a2a/server/events/`)
53+
- **Task Management**: Coordinates work between agents (`src/a2a/server/tasks.py`)
54+
- **Request Handlers**: Processes agent-to-agent requests (`src/a2a/server/request_handlers.py`)
55+
- **Coordinator Agent**: Orchestrates multi-agent workflows (`src/a2a/agent/coordinator.py`)
56+
- **API Endpoints**: RESTful and WebSocket APIs for agent communication (`src/a2a/api/`)
57+
58+
> A2A vs Traditional Multi-Agent Systems:
59+
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,25 +140,31 @@ 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">
112-
<img src="https://img.shields.io/badge/Total%20views-1611-limegreen" alt="Total views">
167+
<img src="https://img.shields.io/badge/Total%20views-1624-limegreen" alt="Total views">
113168
<p>Refresh Date: 2025-12-03</p>
114169
</div>
115170
<!-- END BADGE -->

TROUBLESHOOTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ terraform apply
347347

348348
<!-- START BADGE -->
349349
<div align="center">
350-
<img src="https://img.shields.io/badge/Total%20views-1611-limegreen" alt="Total views">
350+
<img src="https://img.shields.io/badge/Total%20views-1624-limegreen" alt="Total views">
351351
<p>Refresh Date: 2025-12-03</p>
352352
</div>
353353
<!-- END BADGE -->

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())

0 commit comments

Comments
 (0)