adk_server.py
"""
Google ADK A2A Server for Cookbook Examples.
Uses Google's ADK to create an A2A-compatible agent.
Requires GOOGLE_API_KEY environment variable.
This server exposes a facts-agent that provides interesting facts,
using pure JSON-RPC at root "/" endpoint (Google ADK style).
Start this server before running 05_remote_adk_agent.py
"""
import os
from a2a.types import AgentCapabilities, AgentCard
from google.adk import Agent
from google.adk.a2a.utils.agent_to_a2a import to_a2a
from google.adk.tools import google_search
# ---------------------------------------------------------------------------
# Create Example
# ---------------------------------------------------------------------------
port = int(os.getenv("PORT", "7780"))
agent = Agent(
name="facts_agent",
model="gemini-2.5-flash-lite",
description="Agent that provides interesting facts.",
instruction="You are a helpful agent who provides interesting facts.",
tools=[google_search],
)
# Define A2A agent card
agent_card = AgentCard(
name="facts_agent",
description="Agent that provides interesting facts.",
url=f"http://localhost:{port}",
version="1.0.0",
capabilities=AgentCapabilities(
streaming=True, push_notifications=False, state_transition_history=False
),
skills=[],
default_input_modes=["text/plain"],
default_output_modes=["text/plain"],
)
app = to_a2a(agent, port=port, agent_card=agent_card)
# ---------------------------------------------------------------------------
# Run Example
# ---------------------------------------------------------------------------
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=port)
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno a2a uvicorn
3
Run the example
Save the code above as
adk_server.py, then run:python adk_server.py