|
| 1 | +# A2A Python SDK — Samples |
| 2 | + |
| 3 | +This directory contains runnable examples demonstrating how to build and interact with an A2A-compliant agent using the Python SDK. |
| 4 | + |
| 5 | +## Contents |
| 6 | + |
| 7 | +| File | Role | Description | |
| 8 | +|---|---|---| |
| 9 | +| `hello_world_agent.py` | **Server** | A2A agent server | |
| 10 | +| `cli.py` | **Client** | Interactive terminal client | |
| 11 | + |
| 12 | +All three samples are designed to work together out of the box: the agent listens on `http://127.0.0.1:41241`, which is the default URL used by both clients. |
| 13 | +--- |
| 14 | + |
| 15 | +## `hello_world_agent.py` — Agent Server |
| 16 | + |
| 17 | +Implements an A2A agent that responds to simple greeting messages (e.g., "hello", "how are you", "bye") with text replies, simulating a 1-second processing delay. |
| 18 | + |
| 19 | +Demonstrates: |
| 20 | +- Subclassing `AgentExecutor` and implementing `execute()` / `cancel()` |
| 21 | +- Publishing streaming status updates and artifacts via `TaskUpdater` |
| 22 | +- Exposing all three transports in both protocol versions (v1.0 and v0.3 compat) simultaneously: |
| 23 | + - **JSON-RPC** (v1.0 and v0.3) at `http://127.0.0.1:41241/a2a/jsonrpc` |
| 24 | + - **HTTP+JSON (REST)** (v1.0 and v0.3) at `http://127.0.0.1:41241/a2a/rest` |
| 25 | + - **gRPC v1.0** on port `50051` |
| 26 | + - **gRPC v0.3 (compat)** on port `50052` |
| 27 | +- Serving the agent card at `http://127.0.0.1:41241/.well-known/agent-card.json` |
| 28 | + |
| 29 | +**Run:** |
| 30 | + |
| 31 | +```bash |
| 32 | +uv run python samples/hello_world_agent.py |
| 33 | +``` |
| 34 | + |
| 35 | +--- |
| 36 | + |
| 37 | +## `cli.py` — Client |
| 38 | + |
| 39 | +An interactive terminal client with full visibility into the streaming event flow. Each `TaskStatusUpdate` and `TaskArtifactUpdate` event is printed as it arrives. |
| 40 | + |
| 41 | +Features: |
| 42 | +- Transport selection via `--transport` flag (`JSONRPC`, `HTTP+JSON`, `GRPC`) |
| 43 | +- Session management (`context_id` persisted across messages, `task_id` per task) |
| 44 | +- Graceful error handling for HTTP and gRPC failures |
| 45 | + |
| 46 | +**Run:** |
| 47 | + |
| 48 | +```bash |
| 49 | +# Connect to the local hello_world_agent (default): |
| 50 | +uv run python samples/cli.py |
| 51 | + |
| 52 | +# Connect to a different URL, using gRPC: |
| 53 | +uv run python samples/cli.py --url http://192.168.1.10:41241 --transport GRPC |
| 54 | +``` |
| 55 | + |
| 56 | +Type `/quit` or `/exit` to stop, or press `Ctrl+C`. |
| 57 | + |
| 58 | +--- |
| 59 | + |
| 60 | + |
| 61 | +## Quick Start |
| 62 | + |
| 63 | +In two separate terminals: |
| 64 | + |
| 65 | +```bash |
| 66 | +# Terminal 1 — start the agent |
| 67 | +uv run python samples/hello_world_agent.py |
| 68 | + |
| 69 | +# Terminal 2 — start the client |
| 70 | +uv run python samples/cli.py |
| 71 | +``` |
| 72 | + |
| 73 | +Then type a message like `hello` and press Enter. |
0 commit comments