Google ADK Complete Guide 2026: Build Intelligent AI Agents with Code
What is Google ADK?
Google ADK (Agent Development Kit) is an open source AI Agent development framework launched by Google, designed for developers who want to integrate AI Agents into real applications. Unlike frameworks like LangChain and LlamaIndex, ADK adopts a "code-first" design philosophy, making Agent behavior as predictable and testable as traditional software.
Core Features
- Code First: Define Agent behavior using pure Python, no complex YAML configuration needed
- Type Safe: Full use of Python type hints, providing IDE autocomplete and error checking
- Testable: Agent logic can be unit tested like ordinary functions
- Production Ready: Built-in logging, monitoring, error handling and other production essentials
- Multi-Model Support: Supports Gemini, GPT-4, Claude and other mainstream LLMs
Use Cases
- Customer service chatbots
- Automated workflow assistants
- Data analysis and report generation
- Code review and programming assistance
- Enterprise internal knowledge Q&A systems
Installation and Configuration
System Requirements
- Python 3.10 or higher
- pip package manager
- Google Cloud account (when using Gemini model)
Installation Steps
# Create virtual environment (recommended)
python3 -m venv adk-env
source adk-env/bin/activate # Linux/macOS
# adk-env\Scripts\activate # Windows
# Install Google ADK
pip install google-adk
# Install extra dependencies (as needed)
pip install google-adk[cli] # Includes CLI tools
pip install google-adk[testing] # Includes testing tools
# Verify installation
python -c "from google.adk import Agent; print('ADK installed!')"
Configuration
# config.py
from google.adk import Config
config = Config(
api_key="your-gemini-api-key", # Or use environment variable
model="gemini-pro",
temperature=0.7,
max_tokens=2048,
log_level="INFO"
)
Core Concepts
1. Agent
The basic building block of ADK:
from google.adk import Agent
# Define an agent
@Agent.define
def customer_support_agent(query: str) -> str:
"""Handle customer support inquiries."""
return f"Processing: {query}"
# Use the agent
response = customer_support_agent("How do I reset my password?")
print(response)
2. Tools
Extend agent capabilities with custom tools:
from google.adk import Tool
@Tool.define
def search_knowledge_base(query: str) -> str:
"""Search the company knowledge base."""
# Your implementation
return "Search results..."
@Tool.define
def create_support_ticket(issue: str, priority: str) -> dict:
"""Create a support ticket."""
return {
"id": "12345",
"issue": issue,
"priority": priority,
"status": "open"
}
# Agent with tools
@Agent.define(tools=[search_knowledge_base, create_support_ticket])
def support_agent(query: str) -> str:
"""Customer support with tools."""
return f"Helping with: {query}"
3. Workflows
Chain multiple agents together:
from google.adk import Workflow
# Define workflow
workflow = Workflow(
name="Customer Support Workflow",
steps=[
("classify", classify_agent),
("search", search_agent),
("respond", respond_agent)
]
)
# Run workflow
result = workflow.run(user_query="My order hasn't arrived")
4. Memory
Add persistence to agents:
from google.adk import Memory
# In-memory storage
memory = Memory(type="in_memory")
# Database storage
memory = Memory(
type="database",
connection_string="postgresql://user:pass@localhost/adk"
)
# Redis storage
memory = Memory(
type="redis",
host="localhost",
port=6379
)
# Agent with memory
@Agent.define(memory=memory)
def personalized_agent(user_id: str, query: str) -> str:
"""Agent with user context."""
return f"Hello again! Processing: {query}"
Building Your First Agent
Step 1: Define the Agent
# agent.py
from google.adk import Agent, Tool
@Tool.define
def get_weather(city: str) -> str:
"""Get current weather for a city."""
# Mock implementation
return f"Sunny, 25°C in {city}"
@Tool.define
def get_news(topic: str) -> list:
"""Get latest news on a topic."""
return [f"News about {topic}..."]
@Agent.define(
name="assistant",
model="gemini-pro",
tools=[get_weather, get_news],
description="A helpful AI assistant"
)
def assistant(query: str, user_id: str = None) -> str:
"""General purpose AI assistant."""
return f"Helping with: {query}"
Step 2: Test the Agent
# test_agent.py
from google.adk.testing import AgentTester
from agent import assistant
# Create tester
tester = AgentTester(assistant)
# Run tests
def test_weather_query():
response = tester.run("What's the weather in London?")
assert "weather" in response.lower()
print("✅ Weather test passed")
def test_news_query():
response = tester.run("Latest tech news")
assert "news" in response.lower()
print("✅ News test passed")
# Run all tests
test_weather_query()
test_news_query()
Step 3: Deploy the Agent
# deploy.py
from google.adk import Server
# Create server
server = Server(
agent=assistant,
host="0.0.0.0",
port=8080
)
# Start server
if __name__ == "__main__":
server.start()
# Run server
python deploy.py
# Test endpoint
curl http://localhost:8080/query \
-H "Content-Type: application/json" \
-d '{"query": "Hello!", "user_id": "123"}'
Advanced Features
Multi-Agent Systems
from google.adk import MultiAgentSystem
# Define specialized agents
researcher = Agent.define(name="researcher")(research_agent)
writer = Agent.define(name="writer")(write_agent)
editor = Agent.define(name="editor")(edit_agent)
# Create multi-agent system
system = MultiAgentSystem(
agents=[researcher, writer, editor],
coordinator="auto" # Auto-select agent based on task
)
# Run system
result = system.run("Write a blog post about AI trends")
Custom Prompts
from google.adk import PromptTemplate
# Define template
template = PromptTemplate(
system="You are a {{role}} with {{experience}} years of experience.",
user="{{query}}"
)
# Use template
@Agent.define(prompt=template)
def expert_agent(role: str, experience: int, query: str) -> str:
"""Expert agent with custom prompt."""
pass
Error Handling
from google.adk import Agent, ErrorHandler
@ErrorHandler.handle(ValueError)
def handle_value_error(error):
return "Invalid input. Please try again."
@ErrorHandler.handle(Exception)
def handle_general_error(error):
return "Something went wrong. Please contact support."
@Agent.define(error_handlers=[handle_value_error, handle_general_error])
def robust_agent(query: str) -> str:
"""Agent with error handling."""
if not query:
raise ValueError("Query cannot be empty")
return f"Processing: {query}"
Best Practices
1. Keep Agents Focused
# ✅ Good: Single responsibility
@Agent.define
def email_classifier(email: str) -> str:
"""Classify emails by category."""
pass
# ❌ Bad: Too many responsibilities
@Agent.define
def do_everything(input: str) -> str:
"""Classify, respond, and send emails."""
pass
2. Use Type Hints
# ✅ Good: Clear types
@Agent.define
def process_order(
order_id: str,
quantity: int,
priority: str = "normal"
) -> dict:
pass
# ❌ Bad: No types
@Agent.define
def process_order(*args, **kwargs):
pass
3. Write Tests
def test_agent():
tester = AgentTester(my_agent)
# Test normal case
assert tester.run("valid input") is not None
# Test edge cases
assert tester.run("") is not None
assert tester.run("very long input" * 1000) is not None
# Test error handling
with pytest.raises(ValueError):
tester.run(None)
4. Monitor Performance
from google.adk import Metrics
# Enable metrics
@Agent.define(metrics=Metrics(enable=True))
def monitored_agent(query: str) -> str:
pass
# View metrics
metrics = monitored_agent.get_metrics()
print(f"Average latency: {metrics.avg_latency}ms")
print(f"Success rate: {metrics.success_rate}%")
Troubleshooting
Issue 1: API Connection Fails
Solution:
# Check API key
import os
print(os.environ.get("GOOGLE_API_KEY"))
# Test connection
from google.adk import test_connection
test_connection()
Issue 2: Slow Response Times
Solution:
# Use smaller model
@Agent.define(model="gemini-fast")
# Enable caching
@Agent.define(cache=True)
# Reduce max tokens
@Agent.define(max_tokens=512)
Issue 3: Agent Makes Wrong Decisions
Solution:
# Improve prompt
@Agent.define(
prompt=PromptTemplate(
system="You are an expert. Think step by step."
)
)
# Add more examples
@Agent.define(examples=[
{"input": "example1", "output": "expected1"},
{"input": "example2", "output": "expected2"}
])
Resources
- Official Website: https://google.github.io/adk
- GitHub: https://github.com/google/adk
- Documentation: https://google.github.io/adk/docs
- PyPI: https://pypi.org/project/google-adk
- Examples: https://github.com/google/adk/tree/main/examples
Conclusion
Google ADK is a powerful, developer-friendly framework for building AI Agents in 2026. With its code-first approach, type safety, and production-ready features, it's an excellent choice for developers who want to integrate AI into their applications.
Key Takeaways:
- ✅ Code-first design - no YAML needed
- ✅ Type-safe with full IDE support
- ✅ Easily testable like regular code
- ✅ Production-ready with monitoring
- ✅ Multi-model support
Who Should Use Google ADK?
- Python developers building AI applications
- Teams needing production-grade agents
- Anyone wanting type-safe AI development
Start building intelligent agents with Google ADK today!
Related Reading: - Dify AI Platform Complete Guide - Pydantic AI Framework Guide - Best Free AI Coding Tools 2026