|
| 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 OCI realm status 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 | +│ │ • Handles OC4-6 │◄─── A2A Protocol ─►│ • Handles OC1-3 │ │ |
| 20 | +│ │ • Orchestrates │ │ • Status │ │ |
| 21 | +│ │ Communication │ │ Reporter │ │ |
| 22 | +│ │ • Aggregates │ │ • Data │ │ |
| 23 | +│ │ Results │ │ Processing │ │ |
| 24 | +│ └─────────────────┘ └─────────────────┘ │ |
| 25 | +└─────────────────────────────────────────────────────────────────┘ |
| 26 | +``` |
| 27 | + |
| 28 | +## System Capabilities |
| 29 | + |
| 30 | +### Agent A (Primary Agent) |
| 31 | +- **Role**: Orchestrator and aggregator |
| 32 | +- **Responsibilities**: |
| 33 | + - Receives client requests for OCI realm status (OC1-OC6) |
| 34 | + - Manages its own status data for OC4-OC6 |
| 35 | + - Communicates with Agent B to retrieve status for OC1-OC3 |
| 36 | + - Aggregates and returns comprehensive status information |
| 37 | +- **Port**: 9999 |
| 38 | +- **Skills**: OCI realm status aggregation and inter-agent communication |
| 39 | + |
| 40 | +### Agent B (Specialized Agent) |
| 41 | +- **Role**: Specialized status provider |
| 42 | +- **Responsibilities**: |
| 43 | + - Provides status information for OC1-OC3 realms |
| 44 | + - Responds to A2A protocol requests from Agent A |
| 45 | + - Maintains focused expertise on specific realm data |
| 46 | +- **Port**: 9998 |
| 47 | +- **Skills**: OCI realm status reporting for older realms |
| 48 | + |
| 49 | +## Quick Start |
| 50 | + |
| 51 | +### Prerequisites |
| 52 | +- Oracle Cloud Infrastructure (OCI) account |
| 53 | +- OCI CLI installed locally |
| 54 | +- Python UV package manger: https://docs.astral.sh/uv/guides/install-python/ |
| 55 | +- Docker installed locally (for testing) |
| 56 | +- Access to OCI Model Deployment service |
| 57 | + |
| 58 | +### Local Development Setup |
| 59 | + |
| 60 | +1. **Clone and navigate to the project**: |
| 61 | +```bash |
| 62 | +cd model-deployment/A2A_agents_on_MD/ |
| 63 | +``` |
| 64 | + |
| 65 | +2. **Set up Agent A**: |
| 66 | +```bash |
| 67 | +cd agent_a |
| 68 | +uv sync |
| 69 | +uv run . |
| 70 | +``` |
| 71 | + |
| 72 | +3. **Set up Agent B** (in a separate terminal): |
| 73 | +```bash |
| 74 | +cd agent_b |
| 75 | +uv sync |
| 76 | +uv run . |
| 77 | +``` |
| 78 | + |
| 79 | +## Docker Deployment |
| 80 | + |
| 81 | +### Local Docker Testing |
| 82 | + |
| 83 | +**Agent A**: |
| 84 | +```bash |
| 85 | +cd agent_a |
| 86 | +docker build -t agent-a . |
| 87 | +docker run -p 9999:9999 \ |
| 88 | + -e AGENT_A_URL="http://localhost:9999/a2a" \ |
| 89 | + -e AGENT_B_URL="http://localhost:9998/a2a" \ |
| 90 | + agent-a |
| 91 | +``` |
| 92 | + |
| 93 | +**Agent B**: |
| 94 | +```bash |
| 95 | +cd agent_b |
| 96 | +docker build -t agent-b . |
| 97 | +docker run -p 9998:9998 \ |
| 98 | + -e AGENT_A_URL="http://localhost:9999/a2a" \ |
| 99 | + -e AGENT_B_URL="http://localhost:9998/a2a" \ |
| 100 | + agent-b |
| 101 | +``` |
| 102 | + |
| 103 | +## OCI Model Deployment |
| 104 | + |
| 105 | +### Step 1: Build and Push Docker Images |
| 106 | + |
| 107 | +**For Agent A**: |
| 108 | +```bash |
| 109 | +# Login to OCIR |
| 110 | +docker login <region>.ocir.io |
| 111 | + |
| 112 | +# Build and tag |
| 113 | +docker build -t <region>.ocir.io/<tenancy>/<repo>/agent-a:latest ./agent_a |
| 114 | + |
| 115 | +# Push to OCIR |
| 116 | +docker push <region>.ocir.io/<tenancy>/<repo>/agent-a:latest |
| 117 | +``` |
| 118 | + |
| 119 | +**For Agent B**: |
| 120 | +```bash |
| 121 | +# Build and tag |
| 122 | +docker build -t <region>.ocir.io/<tenancy>/<repo>/agent-b:latest ./agent_b |
| 123 | + |
| 124 | +# Push to OCIR |
| 125 | +docker push <region>.ocir.io/<tenancy>/<repo>/agent-b:latest |
| 126 | +``` |
| 127 | + |
| 128 | +### Step 2: Deploy on OCI Model Deployment Service |
| 129 | + |
| 130 | +1. **Deploy Agent B First**: |
| 131 | + - Navigate to OCI Data Science → Model Deployments |
| 132 | + - Create new deployment using the Agent B Docker image |
| 133 | + - Configure environment variables: |
| 134 | + ``` |
| 135 | + AGENT_A_URL=https://<agent-a-deployment-url>/predict/a2a |
| 136 | + AGENT_B_URL=https://<agent-b-deployment-url>/predict/a2a |
| 137 | + CUSTOM_PREDICT_URL_ID=agent-b |
| 138 | + 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"]}] |
| 139 | + WEB_CONCURRENCY=1 |
| 140 | + ``` |
| 141 | + - Set port to 9998 |
| 142 | + - Deploy and note the deployment URL |
| 143 | +
|
| 144 | +2. **Deploy Agent A**: |
| 145 | + - Create new deployment using the Agent A Docker image |
| 146 | + - Configure environment variables: |
| 147 | + ``` |
| 148 | + AGENT_A_URL=https://<agent-a-deployment-url>/predict/a2a |
| 149 | + AGENT_B_URL=https://<agent-b-deployment-url>/predict/a2a |
| 150 | + CUSTOM_PREDICT_URL_ID=agent-a |
| 151 | + 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"]}] |
| 152 | + WEB_CONCURRENCY=1 |
| 153 | + ``` |
| 154 | + - Set port to 9999 |
| 155 | + - Deploy |
| 156 | +
|
| 157 | +### Step 3: Configure Authentication |
| 158 | +
|
| 159 | +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. |
| 160 | +
|
| 161 | +## Configuration |
| 162 | +
|
| 163 | +### Environment Variables |
| 164 | +
|
| 165 | +| Variable | Description | |
| 166 | +|----------|-------------| |
| 167 | +| `AGENT_A_URL` | Agent A's deployment URL | |
| 168 | +| `AGENT_B_URL` | Agent B's deployment URL | |
| 169 | +| `CUSTOM_PREDICT_URL_ID` | Custom URL identifier for Model Deployment | |
| 170 | +| `MODEL_DEPLOY_CUSTOM_ENDPOINTS` | Custom endpoints configuration for A2A protocol | |
| 171 | +| `WEB_CONCURRENCY` | Number of worker processes for web server | |
| 172 | +
|
| 173 | +### Port Configuration (in byoc panel) |
| 174 | +
|
| 175 | +- **Agent A**: Port 9999 |
| 176 | +- **Agent B**: Port 9998 |
| 177 | +
|
| 178 | +## Usage Examples |
| 179 | +
|
| 180 | +### Using the Test Client (Recommended) |
| 181 | +
|
| 182 | +The `agent_a/test_client.py` file provides a complete example of how to interact with the A2A agents using OCI authentication. |
| 183 | +
|
| 184 | +```bash |
| 185 | +# Navigate to agent_a directory |
| 186 | +cd agent_a |
| 187 | +
|
| 188 | +# Run the test client |
| 189 | +uv run python test_client.py |
| 190 | +``` |
| 191 | + |
| 192 | +### Expected Response |
| 193 | +```json |
| 194 | +{ |
| 195 | + "this_agent_result": "🟩 New Realms Status 🟩: OC4 ✅, OC5 ✅, OC6 ✅", |
| 196 | + "other_agent_result": "🟨 Old Realms status 🟨: OC1 ✅, OC2 ✅, OC3 ✅" |
| 197 | +} |
| 198 | +``` |
| 199 | + |
| 200 | +--- |
0 commit comments