|
| 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. |
0 commit comments