Files
google--adk-python/contributing/task_samples/task_sub_agent
Wei (Jack) Sun 1c64a41b53 feat: ADK 2.0 alpha
Introduces two major capabilities:
- Workflow runtime: graph-based execution engine for composing
  deterministic execution flows for agentic apps, with support for
  routing, fan-out/fan-in, loops, retry, state management, dynamic
  nodes, human-in-the-loop, and nested workflows
- Task API: structured agent-to-agent delegation with multi-turn
  task mode, single-turn controlled output, mixed delegation
  patterns, human-in-the-loop, and task agents as workflow nodes

Co-Authored-By: Bo Yang <ybo@google.com>
Co-Authored-By: George Weale <gweale@google.com>
Co-Authored-By: Sean Zhou <seanzhougoogle@google.com>
Co-Authored-By: Shangjie Chen <deanchen@google.com>
Co-Authored-By: Swapnil Agarwal <swapnilag@google.com>
Co-Authored-By: Wei Sun <weisun@google.com>
Co-Authored-By: Xuan Yang <xygoogle@google.com>
Co-Authored-By: Yifan Wang <wanyif@google.com>
Change-Id: I35932c50cfe29ff68559e3781713dbb5eb7b3382
2026-03-17 23:24:58 -07:00
..
2026-03-17 23:24:58 -07:00
2026-03-17 23:24:58 -07:00

ADK Task as Sub-agent Sample

Overview

This sample demonstrates how a "task mode" agent can act as a sub-agent to an LLM agent, effectively extracting structured data from a conversational flow.

The main agent (coordinator) delegates interactions to two sub-agents:

  1. order_collector: A task agent that collects the user's food order (from a menu of Pizza, Burger, Salad) and returns a structured list of selected items as a list[OrderItem].
  2. payment_collector: A task agent that collects the user's credit card and CVV information, returning a PaymentInfo object.

Once the tasks are completed, the coordinator automatically uses a place_order tool with the structured data returned by both agents.

Sample Inputs

  • I would like to order some food please.
  • I want 2 pizzas and 1 salad.
  • My credit card is 1234-5678-9012-3456 and my CVV is 123.

Graph

               [ coordinator ] --(uses)--> [ place_order (tool) ]
              /               \
             v                 v
   [ order_collector ]  [ payment_collector ]

How To

  1. Define a sub-agent with mode="task" and an output schema:

    order_collector = Agent(
        name="order_collector",
        mode="task",
        output_schema=list[OrderItem],
        ...
    )
    
  2. Assign it to a parent agent and use it in the instruction to collect the information:

    coordinator = Agent(
        sub_agents=[order_collector],
        instruction="Delegate using `order_collector`...",
        ...
    )