|
| 1 | +# A2A Root Sample Agent |
| 2 | + |
| 3 | +This sample demonstrates how to use a **remote Agent-to-Agent (A2A) agent as the root agent** in the Agent Development Kit (ADK). This is a simplified approach where the main agent is actually a remote A2A service, also showcasing how to run remote agents using uvicorn command. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The A2A Root sample consists of: |
| 8 | + |
| 9 | +- **Root Agent** (`agent.py`): A remote A2A agent proxy as root agent that talks to a remote a2a agent running on a separate server |
| 10 | +- **Remote Hello World Agent** (`remote_a2a/hello_world/agent.py`): The actual agent implementation that handles dice rolling and prime number checking running on remote server |
| 11 | + |
| 12 | +## Architecture |
| 13 | + |
| 14 | +``` |
| 15 | +┌─────────────────┐ ┌────────────────────┐ |
| 16 | +│ Root Agent │───▶│ Remote Hello │ |
| 17 | +│ (RemoteA2aAgent)│ │ World Agent │ |
| 18 | +│ (localhost:8000)│ │ (localhost:8001) │ |
| 19 | +└─────────────────┘ └────────────────────┘ |
| 20 | +``` |
| 21 | + |
| 22 | +## Key Features |
| 23 | + |
| 24 | +### 1. **Remote A2A as Root Agent** |
| 25 | +- The `root_agent` is a `RemoteA2aAgent` that connects to a remote A2A service |
| 26 | +- Demonstrates how to use remote agents as the primary agent instead of local agents |
| 27 | +- Shows the flexibility of the A2A architecture for distributed agent deployment |
| 28 | + |
| 29 | +### 2. **Uvicorn Server Deployment** |
| 30 | +- The remote agent is served using uvicorn, a lightweight ASGI server |
| 31 | +- Demonstrates a simple way to deploy A2A agents without using the ADK CLI |
| 32 | +- Shows how to expose A2A agents as standalone web services |
| 33 | + |
| 34 | +### 3. **Agent Functionality** |
| 35 | +- **Dice Rolling**: Can roll dice with configurable number of sides |
| 36 | +- **Prime Number Checking**: Can check if numbers are prime |
| 37 | +- **State Management**: Maintains roll history in tool context |
| 38 | +- **Parallel Tool Execution**: Can use multiple tools in parallel |
| 39 | + |
| 40 | +### 4. **Simple Deployment Pattern** |
| 41 | +- Uses the `to_a2a()` utility to convert a standard ADK agent to an A2A service |
| 42 | +- Minimal configuration required for remote agent deployment |
| 43 | + |
| 44 | +## Setup and Usage |
| 45 | + |
| 46 | +### Prerequisites |
| 47 | + |
| 48 | +1. **Start the Remote A2A Agent server**: |
| 49 | + ```bash |
| 50 | + # Start the remote agent using uvicorn |
| 51 | + uvicorn contributing.samples.a2a_root.remote_a2a.hello_world.agent:a2a_app --host localhost --port 8001 |
| 52 | + ``` |
| 53 | + |
| 54 | +2. **Run the Main Agent**: |
| 55 | + ```bash |
| 56 | + # In a separate terminal, run the adk web server |
| 57 | + adk web contributing/samples/ |
| 58 | + ``` |
| 59 | + |
| 60 | +### Example Interactions |
| 61 | + |
| 62 | +Once both services are running, you can interact with the root agent: |
| 63 | + |
| 64 | +**Simple Dice Rolling:** |
| 65 | +``` |
| 66 | +User: Roll a 6-sided die |
| 67 | +Bot: I rolled a 4 for you. |
| 68 | +``` |
| 69 | + |
| 70 | +**Prime Number Checking:** |
| 71 | +``` |
| 72 | +User: Is 7 a prime number? |
| 73 | +Bot: Yes, 7 is a prime number. |
| 74 | +``` |
| 75 | + |
| 76 | +**Combined Operations:** |
| 77 | +``` |
| 78 | +User: Roll a 10-sided die and check if it's prime |
| 79 | +Bot: I rolled an 8 for you. |
| 80 | +Bot: 8 is not a prime number. |
| 81 | +``` |
| 82 | + |
| 83 | +**Multiple Rolls with Prime Checking:** |
| 84 | +``` |
| 85 | +User: Roll a die 3 times and check which results are prime |
| 86 | +Bot: I rolled a 3 for you. |
| 87 | +Bot: I rolled a 7 for you. |
| 88 | +Bot: I rolled a 4 for you. |
| 89 | +Bot: 3, 7 are prime numbers. |
| 90 | +``` |
| 91 | + |
| 92 | +## Code Structure |
| 93 | + |
| 94 | +### Root Agent (`agent.py`) |
| 95 | + |
| 96 | +- **`root_agent`**: A `RemoteA2aAgent` that connects to the remote A2A service |
| 97 | +- **Agent Card URL**: Points to the well-known agent card endpoint on the remote server |
| 98 | + |
| 99 | +### Remote Hello World Agent (`remote_a2a/hello_world/agent.py`) |
| 100 | + |
| 101 | +- **`roll_die(sides: int)`**: Function tool for rolling dice with state management |
| 102 | +- **`check_prime(nums: list[int])`**: Async function for prime number checking |
| 103 | +- **`root_agent`**: The main agent with comprehensive instructions |
| 104 | +- **`a2a_app`**: The A2A application created using `to_a2a()` utility |
| 105 | + |
| 106 | + |
| 107 | + |
| 108 | +## Troubleshooting |
| 109 | + |
| 110 | +**Connection Issues:** |
| 111 | +- Ensure the uvicorn server is running on port 8001 |
| 112 | +- Check that no firewall is blocking localhost connections |
| 113 | +- Verify the agent card URL in the root agent configuration |
| 114 | +- Check uvicorn logs for any startup errors |
| 115 | + |
| 116 | +**Agent Not Responding:** |
| 117 | +- Check the uvicorn server logs for errors |
| 118 | +- Verify the agent instructions are clear and unambiguous |
| 119 | +- Ensure the A2A app is properly configured with the correct port |
| 120 | + |
| 121 | +**Uvicorn Issues:** |
| 122 | +- Make sure the module path is correct: `contributing.samples.a2a_root.remote_a2a.hello_world.agent:a2a_app` |
| 123 | +- Check that all dependencies are installed |
0 commit comments