Complete Tutorial: Google Agent Development Kit (ADK) for Building AI Agents with Python
Google Agent Development Kit (ADK) is an open-source framework from Google for building, managing, and orchestrating AI agents. The framework is designed to let developers create modular, composable, and production-ready agents. ADK integrates directly with the Google Cloud ecosystem and supports various LLM models including Gemini, Claude, and GPT.
In this tutorial, we will learn how to use Google ADK from basics to advanced features, complete with code examples you can run immediately.
Why Google ADK?
Before jumping into implementation, it is important to understand ADK's advantages over other agent frameworks:
- Multi-Agent Architecture: ADK natively supports multi-agent orchestration, enabling you to build complex agent systems with ease
- Google Cloud Integration: Directly integrates with Vertex AI, Gemini API, and other Google Cloud services
- Model Agnostic: While optimized for Gemini, ADK can be used with any LLM model through LiteLLM
- Built-in Tools: Provides ready-to-use tools for Google Search, code execution, and more
- Session Management: Integrated session and memory management system
- Streaming Support: Supports streaming responses for a better user experience
Installation and Setup
System Requirements
Make sure you have Python 3.9 or later installed on your system.
python --version # Minimum Python 3.9
Installing ADK
Install Google ADK using pip:
pip install google-adk
For additional features like evaluation and deployment:
pip install google-adk[eval]
pip install google-adk[a2a]
Configuring the API Key
ADK requires an API key to access LLM models. You can use a Gemini API key or Google Cloud credentials.
Using Gemini API Key:export GOOGLEAPIKEY="your-gemini-api-key"
Using Google Cloud:
export GOOGLECLOUDPROJECT="your-project-id"
export GOOGLECLOUDLOCATION="us-central1"
gcloud auth application-default login
Project Structure
ADK uses a specific folder structure convention. Create the following project structure:
myagentproject/
├── myagent/
│ ├── init.py
│ └── agent.py
└── requirements.txt
The init.py file must export an agent variable:
from .agent import agent
Creating Your First Agent
Simple Agent
Let's start by creating a simple agent that can answer questions:
# myagent/agent.py
from google.adk.agents import Agent
agent = Agent(
model="gemini-2.0-flash",
name="assistant",
description="An AI assistant agent that helps answer questions",
instruction="""You are a friendly and helpful AI assistant.
Answer user questions clearly and concisely.
Provide accurate and well-structured responses.""",
)
Running the Agent
There are several ways to run an agent:
Using CLI:adk run myagent
Using Web UI:
adk web myagent
Programmatically:
import asyncio
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
async def main():
sessionservice = InMemorySessionService()
runner = Runner(
agent=agent,
appname="myapp",
sessionservice=sessionservice,
)
session = await sessionservice.createsession(
appname="myapp",
userid="user1",
)
from google.genai.types import Content, Part
response = runner.run(
userid="user1",
sessionid=session.id,
newmessage=Content(
role="user",
parts=[Part(text="What is machine learning?")]
),
)
async for event in response:
if event.content and event.content.parts: