Concept #113Mediumextended-ai-concepts

What are all the different types of agents in Google ADK?

#gen-ai#agents

Answer

Types of Agents in Google ADK

Google ADK supports several agent types, each suited for different use cases in multi-agent architectures.

1. LLM Agent (Base Agent)

The fundamental building block — an agent powered by a language model:

python
from google.adk.agents import LlmAgent
from google.adk.tools import google_search

research_agent = LlmAgent(
    name="researcher",
    model="gemini-2.0-flash",
    description="Searches the web for information",
    instruction="You are a research specialist. Search and summarize accurately.",
    tools=[google_search]
)

Use when: You need an agent that can reason, use tools, and respond in natural language.

2. Sequential Agent

Executes a fixed sequence of sub-agents in order:

python
from google.adk.agents import SequentialAgent

pipeline = SequentialAgent(
    name="research_pipeline",
    description="Research then write then review",
    sub_agents=[
        search_agent,    # Step 1: gather info
        writer_agent,    # Step 2: write content
        reviewer_agent   # Step 3: review output
    ]
)

Use when: Tasks have a clear, fixed order of steps.

3. Parallel Agent

Runs multiple sub-agents simultaneously:

python
from google.adk.agents import ParallelAgent

parallel_researcher = ParallelAgent(
    name="multi_source_research",
    description="Research from multiple sources simultaneously",
    sub_agents=[
        web_search_agent,     # Runs simultaneously
        database_agent,       # Runs simultaneously
        document_agent        # Runs simultaneously
    ]
)
# All three run at once; results are combined

Use when: Subtasks are independent and can be parallelized for speed.

4. Loop Agent

Repeatedly executes sub-agents until a condition is met:

python
from google.adk.agents import LoopAgent

improvement_loop = LoopAgent(
    name="iterative_improver",
    description="Improve content until quality threshold is met",
    sub_agents=[writer_agent, quality_checker_agent],
    max_iterations=5
)

Use when: Tasks need iterative refinement (e.g., write → review → rewrite).

5. Custom Agent (BaseAgent)

Full control over agent behavior:

python
from google.adk.agents import BaseAgent
from google.adk.agents.invocation_context import InvocationContext
from google.adk.events import Event
from typing import AsyncGenerator

class SmartRoutingAgent(BaseAgent):
    '''Custom agent with domain-based routing'''

    async def _run_async_impl(
        self, ctx: InvocationContext
    ) -> AsyncGenerator[Event, None]:
        user_message = ctx.user_content.parts[0].text

        # Custom routing logic
        if "data" in user_message.lower():
            async for event in self.data_agent.run_async(ctx):
                yield event
        elif "code" in user_message.lower():
            async for event in self.code_agent.run_async(ctx):
                yield event
        else:
            async for event in self.general_agent.run_async(ctx):
                yield event

Use when: You need routing logic, conditional execution, or custom orchestration patterns.

Agent Type Selection Guide

Use CaseAgent Type
Q&A with toolsLlmAgent
Data pipelineSequentialAgent
Multi-source researchParallelAgent
Iterative refinementLoopAgent
Dynamic routingCustom (BaseAgent)
Complex orchestrationLlmAgent as orchestrator with sub_agents

Hierarchy Example

python
# Full multi-agent hierarchy
orchestrator = LlmAgent(
    name="coordinator",
    model="gemini-2.0-flash",
    sub_agents=[
        SequentialAgent("research_pipeline", sub_agents=[searcher, analyzer]),
        ParallelAgent("multi_search", sub_agents=[web_agent, db_agent]),
        LoopAgent("refiner", sub_agents=[writer, reviewer])
    ]
)