From 758282656ca354b017123a444ec1333017d8a4d9 Mon Sep 17 00:00:00 2001 From: geekdevtr Date: Sun, 23 Nov 2025 21:53:51 +0530 Subject: [PATCH 1/4] chore : Adding Readme for dice_agent_rest --- .../python/agents/dice_agent_rest/README.md | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/samples/python/agents/dice_agent_rest/README.md b/samples/python/agents/dice_agent_rest/README.md index e69de29b..f6e1acc2 100644 --- a/samples/python/agents/dice_agent_rest/README.md +++ b/samples/python/agents/dice_agent_rest/README.md @@ -0,0 +1,52 @@ +# Dice Agent (REST) + +A minimal A2A agent that rolls dice and returns the result over the HTTP/JSON transport. Good for testing connectivity and latency without LLM overhead. + +## Prerequisites +- Python 3.10+ +- `uv` (or `pip`) to install dependencies + +## Install +```bash +cd samples/python/agents/dice_agent_rest +uv sync # or: pip install -r requirements.txt +``` + +## Run the agent +```bash +uv run . +# Agent listens on http://0.0.0.0:9999 by default +``` + +## Try it with curl +```bash +curl -X POST http://localhost:9999/message \ + -H 'Content-Type: application/json' \ + -d '{ + "id": "req-1", + "params": { + "message": { + "role": "user", + "parts": [{"kind": "text", "text": "roll a d6"}], + "messageId": "msg-1" + } + } + }' +``` + +Example response (simplified): +```json +{ + "result": { + "parts": [{"kind": "text", "text": "You rolled a 4"}] + } +} +``` + +## Agent card +The public agent card is available at: +``` +http://localhost:9999/.well-known/agent-card.json +``` + + From b0c1cd426fb8952ebef874d937b83ff3105e9dc3 Mon Sep 17 00:00:00 2001 From: geekdevtr Date: Sun, 23 Nov 2025 22:31:10 +0530 Subject: [PATCH 2/4] chore : Add README.md for dice_agent_rest --- .../python/agents/dice_agent_rest/README.md | 135 +++++++++++++----- 1 file changed, 101 insertions(+), 34 deletions(-) diff --git a/samples/python/agents/dice_agent_rest/README.md b/samples/python/agents/dice_agent_rest/README.md index f6e1acc2..ea934688 100644 --- a/samples/python/agents/dice_agent_rest/README.md +++ b/samples/python/agents/dice_agent_rest/README.md @@ -1,52 +1,119 @@ -# Dice Agent (REST) +# Dice Agent REST Example -A minimal A2A agent that rolls dice and returns the result over the HTTP/JSON transport. Good for testing connectivity and latency without LLM overhead. +## 1. Prerequisites -## Prerequisites -- Python 3.10+ -- `uv` (or `pip`) to install dependencies +- **Python** 3.11 or higher + ```bash + python3 --version + ``` +- **Git** (if you need to clone the repo) + ```bash + git --version + ``` + +## 2. Get the Source Code + +If you don’t have the repo yet: + +```bash +git clone https://github.com/google/a2a-samples.git +cd a2a-samples/samples/python/agents/dice_agent_rest +``` + +If you already have it: + +```bash +cd a2a-samples/samples/python/agents/dice_agent_rest +``` + + +## 3. Create and Activate a Virtual Environment + +### macOS / Linux + +```bash +python3 -m venv .venv +source .venv/bin/activate +``` + +### Windows (PowerShell) + +```powershell +python -m venv .venv +.\.venv\Scripts\activate +``` + +You should now see `(.venv)` in your terminal prompt. + + +## 4. Install Dependencies + +You can use **`uv`** (if installed) or **`pip`**. + +### Option A: Using `uv` (uses `uv.lock`) + +From the `dice_agent_rest` directory: -## Install ```bash -cd samples/python/agents/dice_agent_rest -uv sync # or: pip install -r requirements.txt +uv sync ``` -## Run the agent +(Optional sanity check for uv environment): + +```bash +uv run python -c "print('uv environment ready')" +``` + +### Option B: Using `pip` + +Make sure your virtual environment is active (`(.venv)` visible), then run: + ```bash -uv run . -# Agent listens on http://0.0.0.0:9999 by default +pip install . ``` -## Try it with curl +(Optional, if you want editable mode while developing): + +```bash +pip install -e . +``` + + +## 5. Set the Google GenAI API Key + +You must set `GOOGLE_API_KEY` before running anything that calls Gemini. + +### macOS / Linux + ```bash -curl -X POST http://localhost:9999/message \ - -H 'Content-Type: application/json' \ - -d '{ - "id": "req-1", - "params": { - "message": { - "role": "user", - "parts": [{"kind": "text", "text": "roll a d6"}], - "messageId": "msg-1" - } - } - }' +export GOOGLE_API_KEY="YOUR_API_KEY_HERE" ``` -Example response (simplified): -```json -{ - "result": { - "parts": [{"kind": "text", "text": "You rolled a 4"}] - } -} +### Windows (PowerShell) + +```powershell +setx GOOGLE_API_KEY "YOUR_API_KEY_HERE" ``` -## Agent card -The public agent card is available at: +Then open a **new** terminal window (for `setx` to take effect) and, if using `venv`, activate it again. + +Verify: + +```bash +echo $GOOGLE_API_KEY # macOS / Linux ``` -http://localhost:9999/.well-known/agent-card.json + +```powershell +echo $Env:GOOGLE_API_KEY # Windows PowerShell ``` +## 6. Environment Sanity Check + +With the virtual environment active and dependencies installed: + +```bash +python -c "import google.adk, google.genai; print('Environment OK')" +``` + +If you see `Environment OK` with no errors, the setup is complete. From 535339278db9c464054cacb4e569e62bd4c9c6bd Mon Sep 17 00:00:00 2001 From: geekdevtr Date: Sun, 23 Nov 2025 22:33:35 +0530 Subject: [PATCH 3/4] chore : Add README.md for dice_agent_rest --- samples/python/agents/dice_agent_rest/README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/samples/python/agents/dice_agent_rest/README.md b/samples/python/agents/dice_agent_rest/README.md index ea934688..189993e5 100644 --- a/samples/python/agents/dice_agent_rest/README.md +++ b/samples/python/agents/dice_agent_rest/README.md @@ -1,4 +1,12 @@ -# Dice Agent REST Example +# ADK A2A Dice Roll REST Agent Example + +This example shows how to build a small **tool-using LLM agent** with the **Google Agent Development Kit (ADK)**, designed to be exposed over REST (and/or A2A). +The agent: + +- Rolls an N-sided dice on request. +- Checks whether numbers are prime using a tool. +- Keeps **conversational state** via in-memory sessions. +- Supports **streaming responses**, suitable for REST, WebSockets, or A2A. ## 1. Prerequisites From 6318d10f99cb4c2ca2f4090b65eaa944ea68f31b Mon Sep 17 00:00:00 2001 From: geekdevtr Date: Sun, 23 Nov 2025 23:05:03 +0530 Subject: [PATCH 4/4] chore : Add README.md for dice_agent_rest --- samples/python/agents/dice_agent_rest/README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/samples/python/agents/dice_agent_rest/README.md b/samples/python/agents/dice_agent_rest/README.md index 189993e5..d343b95a 100644 --- a/samples/python/agents/dice_agent_rest/README.md +++ b/samples/python/agents/dice_agent_rest/README.md @@ -12,7 +12,7 @@ The agent: - **Python** 3.11 or higher ```bash - python3 --version + python3 --version # On macOS/Linux; use `python --version` on Windows ``` - **Git** (if you need to clone the repo) ```bash @@ -100,11 +100,9 @@ export GOOGLE_API_KEY="YOUR_API_KEY_HERE" ### Windows (PowerShell) ```powershell -setx GOOGLE_API_KEY "YOUR_API_KEY_HERE" +$Env:GOOGLE_API_KEY = "YOUR_API_KEY_HERE" ``` -Then open a **new** terminal window (for `setx` to take effect) and, if using `venv`, activate it again. - Verify: ```bash