Concept #178Hardsystem-designgoogle-adk

How to design a multi-agent orchestration system using Google ADK's workflow agents (Sequential, Parallel, Loop)?

#google-adk#orchestration#workflow#sequential#parallel#loop#design

Answer

Multi-Agent Orchestration with Workflow Agents

Agent Workflow
Agent Workflow

Google ADK's workflow agents provide deterministic orchestration patterns for building complex multi-agent systems without relying on LLM-driven routing.


Workflow Patterns

PatternAgentFlow ControlUse Case
PipelineSequentialAgentA -> B -> CETL, RAG ingestion
Fan-outParallelAgentA, B, C (concurrent)Multi-source search
IterationLoopAgent[A -> B] x NDraft refinement
HybridNested agentsMixedComplex workflows

Pattern 1: Pipeline (Sequential)

python
from google.adk.agents import Agent, SequentialAgent

collector = Agent(
    name="collector",
    model="gemini-2.5-flash",
    instruction="Collect relevant data about the topic.",
    output_key="raw_data",
)

analyzer = Agent(
    name="analyzer",
    model="gemini-2.5-pro",
    instruction="Analyze this data: {raw_data}",
    output_key="analysis",
)

summarizer = Agent(
    name="summarizer",
    model="gemini-2.5-flash",
    instruction="Create a concise summary from: {analysis}",
    output_key="summary",
)

pipeline = SequentialAgent(
    name="research_pipeline",
    sub_agents=[collector, analyzer, summarizer],
)

Pattern 2: Fan-out (Parallel)

python
from google.adk.agents import Agent, ParallelAgent, SequentialAgent

web_searcher = Agent(
    name="web_searcher",
    model="gemini-2.5-flash",
    instruction="Search the web for information.",
    tools=[google_search],
    output_key="web_results",
)

academic_searcher = Agent(
    name="academic_searcher",
    model="gemini-2.5-flash",
    instruction="Search academic papers.",
    tools=[search_arxiv],
    output_key="academic_results",
)

kb_searcher = Agent(
    name="kb_searcher",
    model="gemini-2.5-flash",
    instruction="Search the internal knowledge base.",
    tools=[search_documents],
    output_key="kb_results",
)

# Fan-out: search all sources simultaneously
fan_out = ParallelAgent(
    name="multi_search",
    sub_agents=[web_searcher, academic_searcher, kb_searcher],
)

# Then merge results
merger = Agent(
    name="merger",
    model="gemini-2.5-pro",
    instruction="""Merge and deduplicate results from:
    Web: {web_results}
    Academic: {academic_results}
    Knowledge Base: {kb_results}""",
    output_key="merged_results",
)

search_pipeline = SequentialAgent(
    name="comprehensive_search",
    sub_agents=[fan_out, merger],
)

Pattern 3: Iterative Refinement (Loop)

python
from google.adk.agents import Agent, LoopAgent

writer = Agent(
    name="writer",
    model="gemini-2.5-flash",
    instruction="""Write or improve content based on feedback.
    Previous feedback: {review_feedback}
    Write a high-quality draft.""",
    output_key="draft",
)

reviewer = Agent(
    name="reviewer",
    model="gemini-2.5-pro",
    instruction="""Review this draft: {draft}
    If quality is sufficient, respond with 'APPROVED' and set escalate=True.
    Otherwise, provide specific feedback for improvement.""",
    output_key="review_feedback",
)

refinement_loop = LoopAgent(
    name="draft_refiner",
    max_iterations=5,
    sub_agents=[writer, reviewer],
)

Pattern 4: Hybrid (Complex Orchestration)

python
# Combine all patterns
full_pipeline = SequentialAgent(
    name="content_pipeline",
    sub_agents=[
        # Step 1: Gather from multiple sources
        ParallelAgent(
            name="gather",
            sub_agents=[search_agent, data_agent],
        ),
        # Step 2: Iteratively write and refine
        LoopAgent(
            name="refine",
            max_iterations=3,
            sub_agents=[writer, reviewer],
        ),
        # Step 3: Publish
        publisher_agent,
    ],
)

Design Guidelines

GuidelineReason
Use
text
output_key
for state passing
Enables data flow between agents
Use
text
{variable}
in instructions
Dynamic context from state
Keep agents focused (SRP)One agent = one responsibility
Use ParallelAgent for independent tasksReduces latency
Set
text
max_iterations
on LoopAgent
Prevent infinite loops
Use distinct state keys in ParallelAgentAvoid race conditions

Learn more at Workflow Agents and Multi-Agents.