Skip to content

Commit 6302738

Browse files
authored
Merge pull request #616 from YashPandit4u/a2a-agents-on-md
Added a2a agent sample in model deployment.
2 parents 1a9505e + 6bbb566 commit 6302738

File tree

16 files changed

+4463
-0
lines changed

16 files changed

+4463
-0
lines changed
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
# Agent-to-Agent (A2A) Communication on OCI Model Deployment
2+
3+
This project demonstrates a sophisticated agent-to-agent communication system deployed on Oracle Cloud Infrastructure (OCI) Model Deployment service. The system consists of two specialized agents that work together to provide comprehensive weather information through collaborative AI interactions.
4+
5+
## Architecture Overview
6+
7+
```
8+
┌─────────────────────────────────────────────────────────────────┐
9+
│ Client Application │
10+
│ │ │
11+
│ ▼ │
12+
┌─────────────────────────────────────────────────────────────────┐
13+
│ OCI Model Deployment Service │
14+
│ │
15+
│ ┌─────────────────┐ ┌─────────────────┐ │
16+
│ │ Agent A │ │ Agent B │ │
17+
│ │ (Primary Agent) │ │ (Specialized) │ │
18+
│ │ │ │ │ │
19+
│ │ • Bengaluru │◄─── A2A Protocol ─►│ • Mumbai │ │
20+
│ │ Weather │ │ Weather │ │
21+
│ │ • Orchestrates │ │ • Weather Info │ │
22+
│ │ Communication │ │ Return │ │
23+
│ │ • Aggregates │ │ │ │
24+
│ │ Results │ │ │ │
25+
│ └─────────────────┘ └─────────────────┘ │
26+
└─────────────────────────────────────────────────────────────────┘
27+
```
28+
29+
## System Capabilities
30+
31+
### Agent A (Primary Agent)
32+
- **Role**: Orchestrator and aggregator
33+
- **Responsibilities**:
34+
- Receives client requests for weather information
35+
- Provides Bengaluru weather information
36+
- Communicates with Agent B to retrieve Mumbai weather information
37+
- Aggregates and returns comprehensive weather data from both cities
38+
- **Port**: 9999
39+
- **Skills**: Bengaluru weather information and inter-agent communication
40+
41+
### Agent B (Specialized Agent)
42+
- **Role**: Specialized weather provider
43+
- **Responsibilities**:
44+
- Provides Mumbai weather information
45+
- Responds to A2A protocol requests from Agent A
46+
- Maintains focused expertise on Mumbai weather data
47+
- **Port**: 9998
48+
- **Skills**: Mumbai weather information and reporting
49+
50+
## Quick Start
51+
52+
### Prerequisites
53+
- Oracle Cloud Infrastructure (OCI) account
54+
- OCI CLI installed locally
55+
- Python UV package manger: https://docs.astral.sh/uv/guides/install-python/
56+
- Docker installed locally (for testing)
57+
- Access to OCI Model Deployment service
58+
59+
### Local Development Setup
60+
61+
1. **Clone and navigate to the project**:
62+
```bash
63+
cd model-deployment/A2A_agents_on_MD/
64+
```
65+
66+
2. **Set up Agent A**:
67+
```bash
68+
cd agent_a
69+
uv sync
70+
uv run .
71+
```
72+
73+
3. **Set up Agent B** (in a separate terminal):
74+
```bash
75+
cd agent_b
76+
uv sync
77+
uv run .
78+
```
79+
80+
## Docker Deployment
81+
82+
### Local Docker Testing
83+
84+
**Agent A**:
85+
```bash
86+
cd agent_a
87+
docker build -t agent-a .
88+
docker run -p 9999:9999 \
89+
-e AGENT_A_URL="http://localhost:9999/a2a" \
90+
-e AGENT_B_URL="http://localhost:9998/a2a" \
91+
agent-a
92+
```
93+
94+
**Agent B**:
95+
```bash
96+
cd agent_b
97+
docker build -t agent-b .
98+
docker run -p 9998:9998 \
99+
-e AGENT_A_URL="http://localhost:9999/a2a" \
100+
-e AGENT_B_URL="http://localhost:9998/a2a" \
101+
agent-b
102+
```
103+
104+
## OCI Model Deployment
105+
106+
### Step 1: Build and Push Docker Images
107+
108+
**For Agent A**:
109+
```bash
110+
# Login to OCIR
111+
docker login <region>.ocir.io
112+
113+
# Build and tag
114+
docker build -t <region>.ocir.io/<tenancy>/<repo>/agent-a:latest ./agent_a
115+
116+
# Push to OCIR
117+
docker push <region>.ocir.io/<tenancy>/<repo>/agent-a:latest
118+
```
119+
120+
**For Agent B**:
121+
```bash
122+
# Build and tag
123+
docker build -t <region>.ocir.io/<tenancy>/<repo>/agent-b:latest ./agent_b
124+
125+
# Push to OCIR
126+
docker push <region>.ocir.io/<tenancy>/<repo>/agent-b:latest
127+
```
128+
129+
### Step 2: Deploy on OCI Model Deployment Service
130+
131+
1. **Deploy Agent B First**:
132+
- Navigate to OCI Data Science → Model Deployments
133+
- Create new deployment using the Agent B Docker image
134+
- Configure environment variables:
135+
```
136+
AGENT_A_URL=https://<agent-a-deployment-url>/predict/a2a
137+
AGENT_B_URL=https://<agent-b-deployment-url>/predict/a2a
138+
CUSTOM_PREDICT_URL_ID=agent-b
139+
MODEL_DEPLOY_CUSTOM_ENDPOINTS=[{"endpointURI": "/a2a/", "httpMethods": ["POST"]},{"endpointURI": "/a2a", "httpMethods": ["POST"]},{"endpointURI": "/.well-known/agent.json", "httpMethods": ["GET"]},{"endpointURI": "/a2a/.well-known/agent.json", "httpMethods": ["GET"]},{"endpointURI": "/health", "httpMethods": ["GET"]}]
140+
WEB_CONCURRENCY=1
141+
```
142+
- Set port to 9998
143+
- Deploy and note the deployment URL
144+
145+
2. **Deploy Agent A**:
146+
- Create new deployment using the Agent A Docker image
147+
- Configure environment variables:
148+
```
149+
AGENT_A_URL=https://<agent-a-deployment-url>/predict/a2a
150+
AGENT_B_URL=https://<agent-b-deployment-url>/predict/a2a
151+
CUSTOM_PREDICT_URL_ID=agent-a
152+
MODEL_DEPLOY_CUSTOM_ENDPOINTS=[{"endpointURI": "/a2a/", "httpMethods": ["POST"]},{"endpointURI": "/a2a", "httpMethods": ["POST"]},{"endpointURI": "/.well-known/agent.json", "httpMethods": ["GET"]},{"endpointURI": "/a2a/.well-known/agent.json", "httpMethods": ["GET"]},{"endpointURI": "/health", "httpMethods": ["GET"]}]
153+
WEB_CONCURRENCY=1
154+
```
155+
- Set port to 9999
156+
- Deploy
157+
158+
### Step 3: Configure Authentication
159+
160+
Both agents use OCI Resource Principal Signer (RPS) for authentication when deployed on OCI. The authentication is handled automatically by the A2A SDK in the Agent A code.
161+
162+
## Configuration
163+
164+
### Environment Variables
165+
166+
| Variable | Description |
167+
|----------|-------------|
168+
| `AGENT_A_URL` | Agent A's deployment URL |
169+
| `AGENT_B_URL` | Agent B's deployment URL |
170+
| `CUSTOM_PREDICT_URL_ID` | Custom URL identifier for Model Deployment |
171+
| `MODEL_DEPLOY_CUSTOM_ENDPOINTS` | Custom endpoints configuration for A2A protocol |
172+
| `WEB_CONCURRENCY` | Number of worker processes for web server |
173+
174+
### Port Configuration (in byoc panel)
175+
176+
- **Agent A**: Port 9999
177+
- **Agent B**: Port 9998
178+
179+
## Usage Examples
180+
181+
### Using the Test Client (Recommended)
182+
183+
The `agent_a/test_client.py` file provides a complete example of how to interact with the A2A agents using OCI authentication.
184+
185+
```bash
186+
# Navigate to agent_a directory
187+
cd agent_a
188+
189+
# Run the test client
190+
uv run python test_client.py
191+
```
192+
193+
### Expected Response
194+
```json
195+
{
196+
"this_agent_result": "Bengaluru Weather: 25°C, Sunny, Humidity: 60%, Wind: 8 km/h",
197+
"other_agent_result": "Mumbai Weather: 28°C, Partly Cloudy, Humidity: 75%, Wind: 12 km/h"
198+
}
199+
```
200+
201+
---
202+
203+
**Note**: This is a demonstration system using dummy weather data. In production, replace the dummy data with real weather API integrations for accurate weather information.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Python-generated files
2+
__pycache__/
3+
*.py[oc]
4+
build/
5+
dist/
6+
wheels/
7+
*.egg-info
8+
9+
# Virtual environments
10+
.venv
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.12
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# syntax=docker/dockerfile:1
2+
FROM ghcr.io/astral-sh/uv:debian
3+
4+
# Set work directory
5+
WORKDIR /app
6+
7+
# Copy project files
8+
COPY . .
9+
10+
# Install dependencies using uv (preferred for pyproject.toml)
11+
RUN uv sync
12+
13+
# Expose the port the app runs on
14+
EXPOSE 9999
15+
16+
# Run the app
17+
# CMD ["python", "-m", "__main__"]
18+
CMD ["uv", "run", "."]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Agent A - Bengaluru Weather Agent
2+
3+
An agent-to-agent communication system built with the A2A SDK that provides weather information for Bengaluru and collaborates with other agents to get Mumbai weather information. This project demonstrates how to create an intelligent agent that can communicate with other agents to gather and process information collaboratively.
4+
5+
## Architecture
6+
7+
```
8+
┌─────────────────┐ HTTP/A2A Protocol ┌─────────────────┐
9+
│ Agent A │ ◄─────────────────────► │ Agent B │
10+
│ (This Project) │ │ (External) │
11+
│ │ │ │
12+
│ • Bengaluru │ │ • Mumbai │
13+
│ Weather │ │ Weather │
14+
│ │ │ │
15+
│ │ │ │
16+
└─────────────────┘ └─────────────────┘
17+
```
18+
19+
## Quick Start
20+
21+
```bash
22+
# Install dependencies
23+
uv sync
24+
25+
# Run the agent
26+
uv run .
27+
```
28+
29+
## Environment Variables
30+
31+
| Variable | Description | Default |
32+
|----------|-------------|---------|
33+
| `AGENT_A_URL` | URL for this agent's deployment | Required |
34+
| `AGENT_B_URL` | URL for the other agent to communicate with | Required |
35+
36+
## Exposed Endpoints
37+
38+
- `GET /health` - Health check endpoint
39+
- `GET /a2a/.well-known/agent.json` - Agent card information
40+
- `POST /a2a/messages` - Send messages to the agent
41+
42+
### Docker Deployment
43+
44+
```bash
45+
# Build and run
46+
docker build -t agent-a .
47+
docker run -p 9999:9999 \
48+
-e AGENT_A_URL="https://your-deployment-url.com/predict/a2a" \
49+
-e AGENT_B_URL="https://your-deployment-url.com/predict/a2a" \
50+
agent-a
51+
```
52+
53+
You can push this docker image to OCIR and then use Model Deployment service to run it. You can add the environment variables in the Model Deployment environment variables section.

0 commit comments

Comments
 (0)