docs/guides/agents/llm_agent/task.md
This guide explains the behavior of LlmAgent in task mode. It covers how
task agents are used for delegated, goal-oriented execution, how they signal
completion using the finish_task tool, and how they enforce structured inputs
and outputs.
In ADK, mode="task" is designed for agents that are assigned a specific,
self-contained task. Unlike chat mode (which supports ongoing back-and-forth
conversation and peer transfers) or single_turn mode (which is stateless and
immediate), a task agent:
finish_task
tool to end its execution.output_schema before returning it to the caller.When used as a sub-agent, a task agent is exposed to its parent as a tool. Calling this tool suspends the parent agent and runs the task agent to completion.
The primary use case for task agents is delegation in a multi-agent hierarchy.
single_turn agents, a task agent is
exposed to its parent as a tool, not a transfer target.finish_task.finish_task is validated and
returned to the parent agent as the tool result.Here is how to define a task agent with structured inputs and outputs and delegate to it.
from google.adk.agents import LlmAgent
from pydantic import BaseModel, Field
# 1. Define schemas for Input and Output
class ResearchInput(BaseModel):
topic: str = Field(description="The topic to research.")
depth: str = Field(default="brief", description="Depth of research: brief or detailed.")
class ResearchOutput(BaseModel):
summary: str = Field(description="A summary of the findings.")
sources: list[str] = Field(description="List of sources used.")
# 2. Define the Task Agent
researcher_agent = LlmAgent(
name="researcher",
instruction="Research the given topic and provide a structured summary.",
mode="task",
input_schema=ResearchInput,
output_schema=ResearchOutput,
# Add tools needed for the task
tools=[...]
)
# 3. Define the Parent Agent
writer_agent = LlmAgent(
name="writer",
instruction="Write a blog post. Use the researcher agent to get info on the topic.",
sub_agents=[researcher_agent] # Exposes 'researcher' agent to writer
)
A task agent is not limited to one-shot execution. If the task is unclear or requires user input, the agent can converse with the user:
finish_task.finish_task with the final result.finish_task ToolEvery agent configured with mode="task" automatically receives the
finish_task tool.
finish_task only when the task is fully
complete.finish_task(output=...), the
framework validates the output against the agent's output_schema.output_schema is specified, the agent defaults
to returning a simple string (result).Task mode is currently not supported in workflows. Full support for running task agents within workflows is coming soon.
transfer_to_agent. They must be invoked as tools.finish_task: If a task agent fails to call finish_task
(e.g., due to a bug or limit reach), the task will not complete
successfully.