How to Build Multi-Agent Systems with ADK (Agent Development Kit)
Here’s a comprehensive step-by-step guide to building multi-agent systems using Google’s Agent Development Kit (ADK)
1. Environment Setup
Prerequisites
- Google Cloud account
- Python 3.9
- Basic understanding of Python programming
Installation Steps
# Install ADK
export PATH=$PATH:"/home/${USER}/.local/bin"
python3 -m pip install google-adk==1.0.0
# Install additional requirements
python3 -m pip install -r adk_multiagent_systems/requirements.txt
The `requirements.txt` file lists the three libraries that need to be installed.
langchain-community==0.3.20
wikipedia==1.4.0
crewai-tools==0.38.1
2. Project Structure Setup
Create the following directory structure:
adk_multiagent_systems/
├── parent_and_subagents/
│ ├── agent.py
│ ├── __init__.py
│ └── .env
└── workflow_agents/
├── agent.py
├── __init__.py
└── .env
3. Configuration
Create .env files
cd ~/adk_multiagent_systems
cat << EOF > parent_and_subagents/.env
GOOGLE_GENAI_USE_VERTEXAI=TRUE
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_CLOUD_LOCATION=us-central1
MODEL=gemini-2.0-flash-001
EOF
cp parent_and_subagents/.env workflow_agents/.env
4. Building a Parent-Subagent System
parent_and_subagents/agent.py
import os
import sys
sys.path.append("..")
from callback_logging import log_query_to_model, log_model_response
from dotenv import load_dotenv
from google.adk import Agent
from google.genai import types
from typing import Optional, List, Dict
from google.adk.tools.tool_context import ToolContext
load_dotenv()
model_name = os.getenv("MODEL")
# Tool definition
def save_attractions_to_state(
tool_context: ToolContext,
attractions: List[str]
) -> dict[str, str]:
"""Saves the list of attractions to state["attractions"]."""
existing_attractions = tool_context.state.get("attractions", [])
tool_context.state["attractions"] = existing_attractions + attractions
return {"status": "success"}
# Agent definitions
attractions_planner = Agent(
name="attractions_planner",
model=model_name,
description="Build a list of attractions to visit in a country.",
instruction="""
- Provide the user options for attractions to visit within their selected country.
- When they reply, use your tool to save their selected attraction
and then provide more possible attractions.
- If they ask to view the list, provide a bulleted list of
{{ attractions? }} and then suggest some more.
""",
before_model_callback=log_query_to_model,
after_model_callback=log_model_response,
tools=[save_attractions_to_state]
)
travel_brainstormer = Agent(
name="travel_brainstormer",
model=model_name,
description="Help a user decide what country to visit.",
instruction="""
Provide a few suggestions of popular countries for travelers.
Help a user identify their primary goals of travel:
adventure, leisure, learning, shopping, or viewing art
Identify countries that would make great destinations
based on their priorities.
""",
before_model_callback=log_query_to_model,
after_model_callback=log_model_response,
)
root_agent = Agent(
name="steering",
model=model_name,
description="Start a user on a travel adventure.",
instruction="""
Ask the user if they know where they'd like to travel
or if they need some help deciding.
If they need help deciding, send them to
'travel_brainstormer'.
If they know what country they'd like to visit,
send them to the 'attractions_planner'.
""",
generate_content_config=types.GenerateContentConfig(
temperature=0,
),
sub_agents=[travel_brainstormer, attractions_planner]
)
Running the system
cd ~/adk_multiagent_systems
adk run parent_and_subagents
Run parent_and_subagents on UI
adk web
5. Building a Workflow Agent System
workflow_agents/agent.py
import os
import logging
import google.cloud.logging
from dotenv import load_dotenv
from google.adk import Agent
from google.adk.agents import SequentialAgent, LoopAgent, ParallelAgent
from google.adk.tools.tool_context import ToolContext
from google.adk.tools.langchain_tool import LangchainTool
from google.adk.tools.crewai_tool import CrewaiTool
from google.genai import types
from langchain_community.tools import WikipediaQueryRun
from langchain_community.utilities import WikipediaAPIWrapper
from crewai_tools import FileWriterTool
from google.adk.tools import exit_loop
# Setup logging
cloud_logging_client = google.cloud.logging.Client()
cloud_logging_client.setup_logging()
load_dotenv()
model_name = os.getenv("MODEL")
# Tool definition
def append_to_state(
tool_context: ToolContext, field: str, response: str
) -> dict[str, str]:
"""Append new output to an existing state key."""
existing_state = tool_context.state.get(field, [])
tool_context.state[field] = existing_state + [response]
logging.info(f"[Added to {field}] {response}")
return {"status": "success"}
# Agent definitions
box_office_researcher = Agent(
name="box_office_researcher",
model=model_name,
description="Considers the box office potential of this film",
instruction="""
PLOT_OUTLINE: {{ PLOT_OUTLINE? }}
INSTRUCTIONS:
Write a report on the box office potential of a movie like that described in PLOT_OUTLINE.
""",
output_key="box_office_report"
)
casting_agent = Agent(
name="casting_agent",
model=model_name,
description="Generates casting ideas for this film",
instruction="""
PLOT_OUTLINE: {{ PLOT_OUTLINE? }}
INSTRUCTIONS:
Generate ideas for casting for the characters described in PLOT_OUTLINE.
""",
output_key="casting_report"
)
preproduction_team = ParallelAgent(
name="preproduction_team",
sub_agents=[box_office_researcher, casting_agent]
)
critic = Agent(
name="critic",
model=model_name,
description="Reviews the outline so that it can be improved.",
instruction="""
INSTRUCTIONS:
Consider these questions about the PLOT_OUTLINE:
- Does it meet a satisfying three-act cinematic structure?
- Do the characters' struggles seem engaging?
- Does it feel grounded in a real time period in history?
- Does it sufficiently incorporate historical details from the RESEARCH?
""",
tools=[append_to_state, exit_loop],
)
file_writer = Agent(
name="file_writer",
model=model_name,
description="Creates marketing details and saves a pitch document.",
instruction="""
PLOT_OUTLINE: {{ PLOT_OUTLINE? }}
BOX_OFFICE_REPORT: {{ box_office_report? }}
CASTING_REPORT: {{ casting_report? }}
INSTRUCTIONS:
- Create a marketable, contemporary movie title.
- Use your 'file_writer_tool' to create a new txt file.
""",
tools=[CrewaiTool(
name="file_writer_tool",
description="Writes a file to disk",
tool=FileWriterTool(),
)]
)
screenwriter = Agent(
name="screenwriter",
model=model_name,
description="Writes a logline and plot outline for a biopic.",
instruction="""
INSTRUCTIONS:
Your goal is to write a logline and three-act plot outline.
- If there is CRITICAL_FEEDBACK, use those thoughts to improve.
- If there is RESEARCH provided, use details from it.
""",
tools=[append_to_state],
)
researcher = Agent(
name="researcher",
model=model_name,
description="Answer research questions using Wikipedia.",
instruction="""
INSTRUCTIONS:
- Use your wikipedia tool to do research
- Add your research to the field 'research'.
""",
tools=[
LangchainTool(tool=WikipediaQueryRun(api_wrapper=WikipediaAPIWrapper())),
append_to_state,
],
)
writers_room = LoopAgent(
name="writers_room",
description="Iterates through research and writing to improve a movie plot.",
sub_agents=[researcher, screenwriter, critic],
max_iterations=3,
)
film_concept_team = SequentialAgent(
name="film_concept_team",
description="Write a film plot outline and save it as a text file.",
sub_agents=[writers_room, preproduction_team, file_writer],
)
root_agent = Agent(
name="greeter",
model=model_name,
description="Guides the user in crafting a movie plot.",
instruction="""
- Let the user know you will help them write a pitch for a hit movie.
- Ask them for a historical figure to create a movie about.
""",
tools=[append_to_state],
sub_agents=[film_concept_team],
)
Running the workflow system
cd ~/adk_multiagent_systems
adk run workflow_agents
Run parent_and_subagents on UI
adk web
Reference URL to learn more!
About Me
As the world increasingly adopts cloud-based solutions, I bring over 16 years of industry expertise to help businesses transition seamlessly to the cloud. Currently serving as a Google Cloud Principal Architect, I specialize in building highly scalable, secure, and efficient solutions on the Google Cloud Platform (GCP). My areas of expertise include cloud infrastructure design, zero-trust security, Google Cloud networking, and infrastructure automation using Terraform.
I am proud to hold multiple cloud certifications that Google Cloud, HashiCorp Terraform, Microsoft Azure, and Amazon AWS, reflecting my commitment to continuous learning and multi-cloud proficiency.
Multi-Cloud Certified
- Google Cloud Certified — Cloud Digital Leader
- Google Cloud Certified — Associate Cloud Engineer
- Google Cloud Certified — Professional Cloud Architect
- Google Cloud Certified — Professional Data Engineer
- Google Cloud Certified — Professional Cloud Network Engineer
- Google Cloud Certified — Professional Cloud Developer Engineer
- Google Cloud Certified — Professional Cloud DevOps Engineer
- Google Cloud Certified — Professional Security Engineer
- Google Cloud Certified — Professional Database Engineer
- Google Cloud Certified — Professional Workspace Administrator
- Google Cloud Certified — Professional Machine Learning Engineer
- HashiCorp Certified — Terraform Associate
- Microsoft Azure AZ-900 Certified
- Amazon AWS Certified Practitioner
Empowering Others
Beyond my professional work, I am passionate about helping professionals and students build successful careers in the cloud. Through my content and mentorship, I aim to demystify complex cloud technologies, making them accessible and practical for all skill levels. My areas of guidance include Google Cloud, AWS, Microsoft Azure, and Terraform.
I regularly share insights, tutorials, and resources on various platforms. Whether you’re preparing for a certification exam, exploring cloud architecture, or tackling DevOps challenges, my goal is to provide clear, actionable content that supports your learning journey.
Connect With Me
Stay updated with the latest in cloud computing by following me on these platforms:
- YouTube: Grow with Google Cloud
- Topmate: Consult with Me
- Medium: My Blogs
- Telegram: Community Channel
- Twitter: Follow Me
- Instagram: Connect on Instagram
- LinkedIn: Professional Profile
- GitHub: My Projects
- Facebook: Follow on Facebook
- Linktree: All Resources
I’m here to help — together, we can achieve great heights in the cloud.
Let’s connect and grow! 😊