Google ADK with Python for AI Agents
Build, test and ship a bounded support agent with Google's Agent Development Kit.
Build a bounded support assistant with Google's Agent Development Kit (ADK) in Python: it answers from public product docs and reads synthetic ticket status through typed, read-only tools. Along the way you learn when a direct model call, a deterministic workflow, a single agent or several agents fits the job. The path pins one stable ADK 2.x release, uses the matching docs and labels preview features. Modules 1–2 are beginner ADK, modules 3–6 are intermediate agent building, and modules 7–10 cover advanced evaluation, deployment and architecture. You should know Python functions, type hints and packages, HTTP and JSON, Git, and have made at least one model API call; Python from Zero and AI Engineering with Python cover those. Every exercise has a local mock-model or fixture path, so a paid Gemini or Google Cloud account is optional, and the managed runtime topic can be done as a design-only comparison.
01Agents, workflows and the local development loop
Beginner. When an agent is the right tool, a pinned ADK setup, and the first traced request. Prerequisites: Python packages, HTTP and JSON, and one model API call.
- Model call, workflow or ADK agent: choosing the right shapeNot every AI feature needs an agent. A single model call suits one well-defined transformation, a deterministic workflow suits steps you already know in advance, and a tool-using agent suits requests where the model must decide which lookups to make. Picking the simplest shape that meets the requirement keeps the system cheaper, faster and easier to test.11 min
- Install a pinned Google ADK release and run a first agentThis path pins google-adk 2.15.1, the stable release current in late 2026, which needs Python 3.11 or newer. You install it in a virtual environment, keep the model key in a .env file that Git ignores, and lay out an agent package that the adk command can find. Then you run it in the terminal with adk run and in the browser with adk web.10 min
- Trace your first ADK request from prompt to responseOne ADK request passes through the runner, which loads the session, builds a model request from the agent's instructions and the history, calls the model and any tools, and saves each step as an event. The final answer is simply the last event that is a complete reply with no pending tool calls. Reading these events in adk web, and replaying them with a fake model, is the fastest way to understand and test an agent.11 min
02Runners, events and session lifecycle
Beginner. How the runner drives an agent, what sessions, state and memory hold, and how to keep users apart.
- How the ADK runner, apps and events fit togetherIn ADK the agent describes behaviour, the optional App groups the root agent with app-wide settings such as plugins, and the Runner executes one user message at a time against a session. Execution starts when you call runner.run_async with a user ID, a session ID and the new message, and the runner yields events as it goes. Your code picks the answer by checking event.is_final_response().10 min
- ADK sessions, state, memory and artifacts comparedADK keeps agent data in five places: session events (the conversation history), state (small key-value facts), temp state (values for one invocation only), memory (searchable knowledge across past sessions) and artifacts (named, versioned files). State keys use prefixes to set scope: no prefix for this session, user: for all of one user's sessions, app: for every user, temp: for the current invocation. In-memory services lose everything on restart; database or managed services keep it.11 min
- Per-user session isolation and retention in ADKADK scopes every session by app name, user ID and session ID, but it trusts whatever user ID you pass. Isolation is therefore your job: take the user ID from the verified login, never from the request body, and look sessions up only under that user. ADK has no automatic expiry, so you also write the retention job that deletes old sessions, and you prove both with two synthetic users.11 min
03Structured tools and grounded behavior
Intermediate. Typed read-only function tools, contract tests outside the model, and grounded lookups with source IDs.
- Write typed read-only function tools for an ADK agentA function tool is an ordinary Python function that an ADK agent may ask to run. ADK reads the function name, type hints, default values and docstring to build the schema the model sees, so those parts are the tool's real interface. A good support tool is read-only, takes a small typed input, returns a dictionary with a clear status and reports problems as data instead of crashing the run.12 min
- Contract tests for ADK tools with pytest and fakesA tool contract is the promise a tool makes: which arguments it accepts, who may call it, how long it may take and which results and errors it can return. You enforce that contract in Python code, because a prompt can be ignored or misread by the model. Then you prove it with fast pytest tests that call the tool directly with fake dependencies, so no model, network or Google account is needed.11 min
- Grounded doc lookup with source IDs in ADKGrounding means the agent answers from text you supplied instead of from the model's memory. A small lookup tool searches a fixed set of public product docs, returns each passage with a source ID, and returns no_match when nothing scores high enough so the agent can say it does not know. Retrieved text is treated as data, stays inside your app, and every claim in the reply points back to a source ID.11 min
04Predictable workflows and agent coordination
Intermediate. Fixed workflows, delegation to specialised agents, and hard limits on steps, time and tool calls.
- Sequential, parallel and loop workflows in ADKA workflow is a route you fix in code: which step runs first, what runs next, what runs in parallel and when a loop stops. In ADK 2.x you build it with the Workflow class, a list of edges between nodes, and nodes that are plain Python functions or agents. Because the code decides the order, a workflow is cheaper, faster and easier to test than letting a model choose every step.11 min
- Routing, sub-agents or direct tools: delegation in ADKDelegation means one agent hands work to another agent. ADK offers three main shapes: sub-agents the model transfers control to, an agent wrapped as a tool with AgentTool, and one agent that simply has more tools. Every extra agent adds at least one model call and another place for context to leak, so delegate only when a specialist really needs its own instructions, tools or model.11 min
- Cap ADK agent steps, time and tool callsAn agent that can call tools can also loop, stall or wait forever on a slow system. Bounded execution sets hard limits on each run: how many model calls, how many tool calls, how long it may take and how many failures in a row are allowed. When a limit is hit, the agent gives a safe fallback reply and, when needed, hands the case to a person with enough context to continue.11 min
05API, streaming, MCP and A2A
Intermediate. Serve the agent over HTTP with streamed events, connect an MCP server, and see where A2A fits.
- Serve and stream an ADK agent over HTTPAn agent becomes useful to an app once it sits behind an HTTP endpoint. ADK ships an API server (adk api_server) that exposes session and run endpoints, including /run_sse for streamed events, and you can also wrap the Runner in your own small FastAPI app. The wrapper is where you check the caller's identity, create sessions for that user only, stream events and handle errors and disconnects.13 min
- Connect a read-only MCP server to an ADK agentThe Model Context Protocol (MCP) is an open standard for giving AI apps tools and data through a separate server process. In ADK you attach an MCP server with McpToolset, which discovers the server's tools and offers them to the agent. You stay in charge: filter which tools are exposed, make sure the server itself can only read, set timeouts, and swap the server for a fake in tests.11 min
- Agent-to-agent (A2A) with ADK: concepts and a demo peerAgent2Agent (A2A) is an open protocol that lets independent agents, often run by different teams, call each other over HTTP as peers. Each A2A agent publishes an agent card, a JSON file describing its name, skills and endpoint. ADK can expose an agent over A2A with to_a2a() or adk api_server --a2a, and call a remote one with RemoteA2aAgent; for this course it is optional and only used with a fixed, trusted demo peer.11 min
06Bound application actions
Intermediate. Keep untrusted text from changing what the agent may do, require approval for writes, and trace without leaking data.
- Keep ADK tools scoped when inputs are untrustedAn ADK agent reads text from several places: your instruction, the user's message, tool results and retrieved docs. Only your instruction and code are trusted; any of the others can contain words that try to change what the agent does, which is called prompt injection. The defence is to keep every permission decision in code, such as which tools exist and whose tickets a tool may read, and to prove it with harmless fixtures that contain conflicting instructions.13 min
- Human approval and dry-run actions in ADKSome actions change the outside world, such as closing a ticket or sending an email, and a person should approve them. In this course the agent never performs writes: a tool returns a dry-run proposal, ADK's tool confirmation pauses the run until a person approves or rejects it, and a separate executor with its own credentials carries out approved changes. Every step is recorded so you can show who approved what and when.11 min
- Trace ADK model and tool calls with redactionADK emits OpenTelemetry traces: a span for each agent invocation, model call and tool call, with timing, errors and token counts. Traces are how you find a slow tool or a costly prompt, but by default they can also contain prompts, responses and tool arguments. Turn on tracing, tag spans with execution IDs, compute cost from token counts, and switch off content capture or redact it before anything leaves the process.11 min
07Verify outputs and trajectories
Advanced. Evaluation datasets, tool-trajectory scoring and CI gates that separate fixtures from live-model checks.
- Build an evaluation dataset for an ADK agentAn evaluation dataset is a set of saved conversations that say what the agent should answer and which tools it should call. ADK stores them as eval sets: JSON files of eval cases, each with one or more turns, the expected tool uses and a reference answer. A good set covers the main user intents plus the awkward cases: grounding, escalation, denied tools, isolation between users and fallback when something fails.11 min
- Score ADK tool trajectories and final answersA trajectory is the sequence of tool calls an agent makes on the way to its answer. ADK scores it with tool_trajectory_avg_score, which compares actual calls to expected ones using EXACT, IN_ORDER or ANY_ORDER matching, and scores the final answer with criteria such as response_match_score or an LLM judge. Efficiency numbers for tool calls, model calls, tokens and duration are reported alongside, so you can see cost and speed next to correctness.11 min
- Regression gates for agents: fixtures vs live modelsA regression gate is a CI check that stops a change from merging if agent behaviour gets worse. Split it in two: fast fixture tests with a scripted fake model and stubbed tools run on every commit and must pass every time, while live-model evaluations run on a schedule or before release, are repeated several times and pass when they meet a threshold. Keep the evidence from each run so a failing case can be triaged instead of retried until it goes green.11 min
08From a local agent to a maintained service
Advanced. Deploy one authenticated Cloud Run service, compare the managed agent runtime, and plan for failures.
- Deploy an authenticated ADK agent to Cloud RunCloud Run runs your ADK agent as a container that scales with traffic, and ADK can build and deploy it for you with adk deploy cloud_run or you can deploy your own FastAPI entry point with gcloud run deploy. A production setup is private (callers need an identity token), runs as its own service account with only the roles it needs, reads secrets from Secret Manager and keeps sessions in a database rather than in container memory. Every deploy creates a new revision, so rolling back means sending traffic to the previous one.11 min
- Local, Cloud Run or Agent Runtime for ADK agentsYou can run an ADK agent on your own machine, on Cloud Run, or on Agent Runtime, Google's managed service for agents in the Gemini Enterprise Agent Platform (formerly Vertex AI Agent Engine). Each moves more work to Google and adds its own prerequisites, regions and costs. Agent Runtime gives managed sessions and Memory Bank but needs a billed project and supported regions; Cloud Run gives more control and you bring your own session store.11 min
- Run an ADK agent in production: limits and incident drillsAn agent in production needs limits on money, requests and time, a safe way to release new versions, and a rehearsed plan for when a tool or the model fails. Budgets alert you, rate limits and max_llm_calls cap spend per user and per turn, and timeouts must shrink from the client inward so the user always gets an answer. Gradual rollouts with tagged Cloud Run revisions and regular incident drills turn outages into routine work.12 min
09Review real design trade-offs
Advanced. State topology across instances and the cost and latency of routing, tools and retrieval, argued from traces.
- ADK state across instances: concurrency and duplicatesOn one instance with InMemorySessionService, every request sees the same memory, so state looks simple until the process restarts or a second instance starts. With many instances, sessions must live in a shared store such as DatabaseSessionService on PostgreSQL, and you must decide what happens when two turns hit one session at once or when a client retries the same request. Writing that choice down in a short decision record stops the team from relearning it during an incident.13 min
- Cost and latency of ADK routing, tools and retrievalEvery model call, tool call and retrieved passage shows up in a trace as time and tokens, so cost and latency questions can be answered from evidence instead of guesses. The big levers are the number of model calls (routing hops add one each), whether independent tools run in parallel, how much retrieved text you send back to the model, and whether a stable prompt prefix can be cached. Change one lever at a time and compare traces before and after.13 min
10Support assistant with evaluated behavior
Advanced. Define, build and release a read-only support assistant with mock tickets, an evaluation matrix and a rollback guide.
- ADK capstone: write the support assistant contractBefore writing agent code, write the contract: what the support assistant may do, for whom, in what shape it answers, when it stops or hands off to a person, and how you will know it works. The contract lists two read-only tools, per-user session rules, a typed response schema, escalation and stop rules, a cost and time budget, and evaluation targets. Every later build and release step is checked against this one page.11 min
- ADK capstone: build the doc and ticket support agentThe build wires the contract into code: a doc lookup that returns passages with source IDs, a read-only lookup over mock tickets filtered by the caller's user ID, per-user sessions in a durable store, and a FastAPI endpoint that verifies the token and streams ADK events as structured server-sent events. A fake model and local stubs make the whole thing run offline and repeatably. You also build one alternative, a graph workflow that routes ticket questions in code, to compare against the single-agent baseline.12 min
- ADK capstone: evaluate, release and document rollbackRelease means proving the contract, not just deploying code. You run the evaluation matrix on fixtures in CI and on a live model before release, demonstrate denial and fallback cases, publish a few redacted traces, draw the request and session-isolation diagrams, and write a guide that covers deployment, cost, version and rollback. A release that cannot be rolled back in one command is not ready.12 min