Trace a Google ADK router agent with Comet Opik.
This example runs a Google ADK router agent that decides whether each query should use local RAG over the IMF Financial Access Survey PDF or live web search. It indexes the PDF into a local Qdrant database, exposes retrieve_docs and web_search tools, and traces the routing decision and tool calls with Opik.
This is a uv project — dependencies live in pyproject.toml.
uv syncCopy .env.example to .env (or export the variables). With GOOGLE_API_KEY / Opik credentials unset, the example runs in DRY_RUN and prints what it would do instead of calling Gemini/Opik.
| Variable | Required | Description |
|---|---|---|
GOOGLE_API_KEY |
for a live run | Gemini API key (Google AI Studio). Unset → DRY_RUN. |
OPIK_API_KEY |
for a live run | Opik API key from comet.com/opik. Unset → DRY_RUN. |
OPIK_WORKSPACE |
for a live run | Your Opik workspace. Unset → DRY_RUN. |
OPIK_PROJECT_NAME |
no | Project traces are logged to (default google-adk-rag). |
GADK_MODEL |
no | Gemini model the router runs on (default gemini-2.5-flash). |
uv run python index.py # build the local Qdrant index from the IMF PDF
uv run python main.py # run the traced ADK router
# or both, the way CI does:
bash run.sh- Index the PDF —
index.pydownloads the IMF report, chunks it, embeds it, and writes vectors into the localdbdirectory. - Expose tools —
tools.pydefinesretrieve_docsfor Qdrant search andweb_searchfor DuckDuckGo search. - Run the router —
main.pycreates therouter_agent, traces it withOpikTracer(logging toOPIK_PROJECT_NAME, defaultgoogle-adk-rag), and runs one query through ADK.