Google ADK (Python)
Overview
The Google Agent Development Kit (ADK) is a code-first, Python-first toolkit for building agents with Gemini and other models. Core concepts: Agents (LlmAgent, aliased Agent) with instructions and tools, sub-agents / workflows (hierarchical delegation and deterministic orchestration), sessions & state (per-conversation memory), events (the execution stream), and callbacks (interception hooks). Runner executes agents; InMemorySessionService stores sessions.
Ground all code in the official docs. This skill's reference files reproduce the documented API — never invent imports or parameters. Current ADK is v2.x (latest v2.6.2, 2026-08).
Core workflow (hello world)
from google.adk.agents.llm_agent import Agent
def get_current_time(city: str) -> dict:
"""Returns the current time in a specified city."""
return {"status": "success", "city": city, "time": "10:30 AM"}
root_agent = Agent(
model='gemini-flash-latest',
name='root_agent',
description="Tells the current time in a specified city.",
instruction="You are a helpful assistant that tells the current time in cities. Use the 'get_current_time' tool for this purpose.",
tools=[get_current_time],
)
Setup: pip install google-adk (Python 3.10+), then put GOOGLE_API_KEY in .env. Run with adk run my_agent, adk web (dev UI), or programmatically with Runner + InMemorySessionService.
How to use this skill
- Identify what the user is building (single agent → tools → multi-agent → production).
- Read the matching reference file(s) below before writing agent code.
- Use the example scripts in
assets/examples/as starting points; adapt them to the user's needs. - For anything beyond these guides, consult the official docs (
https://adk.dev/); model IDs change and docs examples lag — prefer configurable model selection.
Before implementing
Gather context before writing agent code:
| Source | Gather |
|---|---|
| Codebase | Existing Python project layout, framework (FastAPI/CLI), dependency manager, where the agent will be invoked |
| Conversation | The agent's purpose, who calls it, single-turn vs multi-turn, required model/provider, streaming needs |
| Skill references | The reference file for the feature being built (see decision guide below) |
| User guidelines | Available API keys/secrets (GOOGLE_API_KEY vs Vertex env vars), deployment environment, existing DB for sessions |
Clarify when ambiguous
Ask only what the code cannot tell you — never ask the user to recall SDK API details (this skill embeds them). Limit to 1–2 questions up front.
- Required (ask before building if unknown)
- What does the agent do end-to-end, and who/what invokes it (CLI, web endpoint, background job)?
- Is the interaction multi-turn (needs sessions/state) or single-turn?
- Optional (only if relevant)
- Google AI Studio (
GOOGLE_API_KEY) vs Vertex (GOOGLE_GENAI_USE_ENTERPRISE=TRUE+ project/location)? - Is a persistence backend available (Postgres/Firestore) for sessions, or is in-memory fine?
- Google AI Studio (
Learning path: hello world → production
| Stage | What the user learns to build | Read first |
|---|---|---|
| 1. Hello world | Install, project structure, first agent, Runner, run commands | references/getting-started.md |
| 2. Agents & config | LlmAgent params, instructions, output_schema, generation config, modes |
references/agents.md |
| 3. Tools | Function tools, ToolContext, google_search, AgentTool, code execution | references/tools.md |
| 4. Multi-agent | sub_agents, single_turn/task/chat modes, SequentialAgent, Workflow graphs | references/orchestration.md |
| 5. State | Sessions, state scopes, output_key, state_delta, memory |
references/sessions-and-state.md |
| 6. Events & callbacks | Event stream, is_final_response, interception hooks |
references/events.md, references/callbacks.md |
| 7. Models | Gemini config, auth, retries, Interactions API | references/models-and-config.md |
| 8. Integrations | MCP servers as tools | references/mcp.md |
| 9. Production | Observability, evals, deployment, CLI reference | references/observability-and-production.md |
Decision guide (jump straight to the right file)
- Install / hello world / project structure /
adk runvsadk web/ Runner →getting-started.md - Agent configuration (name, model, instruction, output_schema, generate_content_config, modes) →
agents.md - Tools (function tools, docstring schemas, ToolContext, google_search, AgentTool, code execution) →
tools.md - Multi-agent orchestration (sub_agents vs AgentTool vs workflows, mode semantics) →
orchestration.md - Conversation memory / state / session backends →
sessions-and-state.md - Understanding the event stream / final responses / streaming →
events.md - Intercept or modify agent/LLM/tool behavior →
callbacks.md - Which Gemini model / auth / retries / generation config →
models-and-config.md - Connect an MCP server (stdio, streamable HTTP, SSE) →
mcp.md - Tracing, evals, deployment, production hardening →
observability-and-production.md
Key rules (verified against official docs)
nameis required on every agent;modelandinstructionare strongly recommended.descriptionis recommended for multi-agent routing.agent.pymust define a variable namedroot_agent— ADK's tools discover the agent through it.- Plain Python functions in
tools=are auto-wrapped as function tools; the docstring + type hints generate the LLM-facing schema. - A parameter is required if it has a type hint and no default; optional if it has a default or
Optional[...].*args/**kwargsare ignored. - Return dicts from tools (prefer a
"status"key); other types get wrapped as{"result": ...}. ToolContextinjection: add a parameter typedToolContext— it's auto-injected and hidden from the LLM; parameter name is flexible.- Python callback parameter names must match exactly (
callback_context,llm_request,llm_response,tool,args,tool_context,tool_response) or you get aTypeError. mode="task"agents must call the built-infinish_tasktool to complete;single_turnandtasksub-agents are exposed to parents as tools, not transfer targets.InMemorySessionServiceloses all data on restart — use Database/Vertex/Firestore services for production.- Never mutate
session.statedirectly on a retrieved session; update viaoutput_key,EventActions.state_delta, orcontext.state. - State prefixes: none = session,
user:= per-user,app:= global,temp:= current invocation only (never persisted). google_searchtool is Gemini-2-only and must be the sole tool in the standard path (Interactions API usesbypass_multi_tools_limit=Trueto combine with custom tools).- MCP toolsets must be defined synchronously in
agent.pyfor deployment; async creation only works withadk web. adk webis not for production — useadk api_server, Cloud Run, GKE, or Agent Runtime.- Model IDs change;
gemini-flash-latestis the common alias but regional endpoints may need a pinned version. Configure via env, don't hardcode.
Example scripts (assets/examples/)
Copy and adapt these runnable scripts rather than writing from scratch:
hello_world.py— minimal agent with a tool, programmatic Runner (hello world)function_tools.py— function tools +ToolContextsession statestructured_output.py— Pydanticinput_schema/output_schemaextractionsub_agents.py— hierarchical multi-agent delegationsequential_workflow.py— deterministic pipeline viaSequentialAgent+output_keypropagationcallbacks.py—before_tool_callback/before_model_callback/after_model_callbackgoogle_search.py— grounding with the prebuilt search toolsessions.py— multi-turn session state persistencemcp_tools.py— connect an MCP server (stdio filesystem server) as tools
References
references/getting-started.md— install, project structure, hello world, run commands, Runner/InMemoryRunnerreferences/agents.md— LlmAgent constructor, generation config, structured output, instruction templating, modes, planner, code executionreferences/tools.md— function tools, ToolContext, return values, LongRunningFunctionTool, AgentTool, google_search, code executionreferences/orchestration.md— sub-agents, single_turn/task/chat modes, Sequential/Parallel/Loop agents, Workflow graphsreferences/sessions-and-state.md— sessions, state scopes, state update methods, persistence, memoryreferences/events.md— Event structure, final responses, control signalsreferences/callbacks.md— callback types, parameter names, skip/continue semanticsreferences/models-and-config.md— Gemini models, auth env vars, generation/thinking config, retries, Interactions APIreferences/mcp.md— McpToolset, connection types, filtering, deployment patternsreferences/observability-and-production.md— plugins, metrics, evals, deployment targets, CLI reference