Fun with agentic workflows in ADK and how to use them
ADK provides us with a number of different options for workflows and how to use them (in sequence, parallel and loops), it's like programming using the AI (or AIs?) as variables. Let's try it out!
Agents, that’s the hot topic word, you’ve heard it everywhere right? What does that mean? In the simplest terms, its an AI which can perform an action on your behalf, this action usually being an API call, function call, or use of any similar tools.
Making these tools has been the biggest challenge for people historically, because even if they do it right once, it used to take a lot of different libraries to put it together, and then, of course, deploy it. Everyone had their own way, but that has been simplified now with ADK.
What’s an ADK?
ADK stands for Agent Development Kit. What is that? It’s a tool to develop agents. It simplifies the process to develop your first agent and has examples on how to develop agents in such a way as to reuse them in developing custom agents of your own. It also has a UI test environment and multiple ways to deploy your agent, including an Agent Egnine, Cloud Run and even Kubernetes. Basically, it can cover all the aspects of building an agent, from ideation to implementation and testing.
Initial setup
The initial setup for an ADK workload, even on your local machine is very simple. The AI part, however, does require that you have access either to Vertex AI or AI Studio. AI Studio, is the free option for development, with the ability to switch over to the paid AI Studio or Vertex AI for larger deployments.
The actual setup is not that difficult, you can do it from any command line, and you can serve it from any port. The quickstart will walk you through the process:
Agent workflow triggering
We are going to try out three different agent workflow examples, each showing a different way to orchestrate agents and tools.
Sequential
Multiple agents often need to work in a sequence in order to produce a refined result. In this example, we will use three agents in sequence to rewrite a short story based on criticism. And here is the code:
from google.adk.agents import LlmAgent, SequentialAgent
GEMINI_MODEL = "gemini-2.0-flash-001"
#Writer Agent
writer_agent = LlmAgent(
name="WriterAgent",
model=GEMINI_MODEL,
instruction="""You are a story writer.
Based on the user's prompt, write a short story around 1000 words.
Output *only* the text from the story.
""",
description="Writes a short story based on user input.",
output_key="story_text"
)
#Editor Agent
editor_agent = LlmAgent(
name="EditorAgent",
model=GEMINI_MODEL,
instruction="""You are an experienced literary editor with a keen eye for storytelling.
Your task is to provide constructive feedback on the provided short story.
**Story to Review:**
{story_text}
**Review Criteria:**
1. **Plot and Pacing:** Is the story engaging? Does the plot unfold at a good pace? Are there any plot holes or inconsistencies?
2. **Character Development:** Are the characters compelling and believable? Are their motivations clear and consistent?
3. **Prose and Style:** Is the writing clear, vivid, and evocative? Are there issues with grammar, spelling, or punctuation?
4. **Dialogue:** Does the dialogue sound natural for the characters? Does it effectively reveal character and advance the plot?
5. **Theme and Tone:** Is there a central theme? Is the tone consistent and effective for the story being told?
**Output:**
Provide your feedback as a concise, bulleted list. Focus on the most important points for improvement, offering specific examples from the text where possible.
If the story is excellent and requires no major changes, simply state: "An excellent story with no major issues found."
Output *only* the review comments or the "no major issues" statement.
""",
description="Edits the story and provides feedback",
output_key="review_comments",
)
#Rewriter Agent
rewriter_agent = LlmAgent(
name="RewriterAgent",
model=GEMINI_MODEL,
instruction="""You are a creative writing AI.
Your goal is to improve the given short story based on the provided editorial comments.
**Original Story:**
{story_text}
**Editorial Comments:**
{review_comments}
**Task:**
Carefully apply the suggestions from the comments to rewrite the original story.
If the comments state "An excellent story with no major issues found," return the original story unchanged.
Preserve the core plot and characters while improving the prose, pacing, and dialogue as suggested.
**Output:**
Output *only* the final, rewritten story.
Do not add any other text before or after the story.
""",
description="Rewritten story based on feedback",
output_key="rewritten_story",
)
writing_process_agent = SequentialAgent(
name="WritingProcessAgent",
sub_agents=[writer_agent, editor_agent, rewriter_agent],
description="Executes a sequence of writing, editing, and rewriting.",
)
root_agent = writing_process_agent
The code executes in the form of writer→editor→rewriter. And here’s an example of the criticism it produces:
And when you feed that edited story back into the editor agent:
So, it sticks to it’s guns! Excellent. But what happens when you try to execute multiple agents at the same time?
Parallel
This example will show an agent running two other agents (for a topic and against) and then passing that information to another agent in order to produce a summary.
Here is the code for the agent:
from google.adk.agents import LlmAgent, ParallelAgent, SequentialAgent
GEMINI_MODEL = "gemini-2.0-flash-001"
#For Agent
for_agent = LlmAgent(
name="ForAgent",
model=GEMINI_MODEL,
instruction="""You are very in favor of the topic suggested.
Based on the user's prompt, write a paragraph that is in favor of the topic.
Output *only* the text.
""",
description="Writes a text in favor of the topic.",
output_key="for_text"
)
#Against Agent
against_agent = LlmAgent(
name="AgainstAgent",
model=GEMINI_MODEL,
instruction="""You are very against of the topic suggested.
Based on the user's prompt, write a paragraph that is against the topic.
Output *only* the text.
""",
description="Writes a text against the topic.",
output_key="against_text"
)
parallel_argument_agent = ParallelAgent(
name="ParallelArgumentAgent",
sub_agents=[for_agent, against_agent],
description="Runs multiple agents in parallel to gather information."
)
#Compilation Agent
compilation_agent = LlmAgent(
name="CompilationAgent",
model=GEMINI_MODEL,
instruction="""
Compile the information from {for_text} and {against_text} and compare the two.
Produce a neutral conclusion along with a summary of what each text discusses.
""",
description="Produces a comparison of for and against texts.",
output_key="compilation",
)
display_agent = SequentialAgent(
name="DisplayAgent",
sub_agents=[parallel_argument_agent, compilation_agent],
description="Produces a final display of comparisons",
)
root_agent = display_agent
And it works quite well. The topic I gave it was tea, and here is the result:
Good work, exactly what you’d want. And since there is no influence in between the two for and against, it creates very good reportage.
Loop
Loop are meant to automate in a way in which you can do one tedious task as many times as you need to as long as its consistent. You know what’s tedious? Writing more code, so we’re going to recycle our sequential code for this one, putting the editor and rewriter in a loop after initial story writing.
from google.adk.agents import LlmAgent, SequentialAgent, LoopAgent
GEMINI_MODEL = "gemini-2.0-flash-001"
#Writer Agent
writer_agent = LlmAgent(
name="WriterAgent",
model=GEMINI_MODEL,
instruction="""You are a story writer.
Based on the user's prompt, write a short story around 1000 words.
Output *only* the text from the story.
""",
description="Writes a short story based on user input.",
output_key="story_text"
)
#Editor Agent
editor_agent = LlmAgent(
name="EditorAgent",
model=GEMINI_MODEL,
instruction="""You are an experienced literary editor with a keen eye for storytelling.
Your task is to provide constructive feedback on the provided short story.
**Story to Review:**
{story_text}
**Review Criteria:**
1. **Plot and Pacing:** Is the story engaging? Does the plot unfold at a good pace? Are there any plot holes or inconsistencies?
2. **Character Development:** Are the characters compelling and believable? Are their motivations clear and consistent?
3. **Prose and Style:** Is the writing clear, vivid, and evocative? Are there issues with grammar, spelling, or punctuation?
4. **Dialogue:** Does the dialogue sound natural for the characters? Does it effectively reveal character and advance the plot?
5. **Theme and Tone:** Is there a central theme? Is the tone consistent and effective for the story being told?
**Output:**
Provide your feedback as a concise, bulleted list. Focus on the most important points for improvement, offering specific examples from the text where possible.
If the story is excellent and requires no major changes, simply state: "An excellent story with no major issues found."
Output *only* the review comments or the "no major issues" statement.
""",
description="Edits the story and provides feedback",
output_key="review_comments",
)
#Rewriter Agent
rewriter_agent = LlmAgent(
name="RewriterAgent",
model=GEMINI_MODEL,
instruction="""You are a creative writing AI.
Your goal is to improve the given short story based on the provided editorial comments.
**Original Story:**
{story_text}
**Editorial Comments:**
{review_comments}
**Task:**
Carefully apply the suggestions from the comments to rewrite the original story.
If the comments state "An excellent story with no major issues found," return the original story unchanged.
Preserve the core plot and characters while improving the prose, pacing, and dialogue as suggested.
**Output:**
Output *only* the final, rewritten story.
Do not add any other text before or after the story.
""",
description="Rewritten story based on feedback",
output_key="story_text",
)
editor_loop_agent = LoopAgent(name="RefinementLoop",
sub_agents=[
editor_agent,
rewriter_agent,
],
max_iterations=5
)
writing_process_agent = SequentialAgent(
name="WritingProcessAgent",
sub_agents=[writer_agent, editor_loop_agent],
description="Executes a sequence of writing, editing, and rewriting.",
)
root_agent = writing_process_agent
You can see the code loop running on the request and response loop for criticizing the story:
For future improvements, an exit condition for the loop is recommended.
In conclusion, lots of fun ways to start your ADK journey. But don’t take my word for it, try it out yourself.