task_sub_agent

command
v2.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 10, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

README

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 []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

graph TD
    coordinator --> order_collector
    coordinator --> payment_collector
    coordinator -.->|uses| place_order[place_order tool]

How To

  1. Define a sub-agent with Mode: llmagent.ModeTask and an output schema:

    orderCollector, err := llmagent.New(llmagent.Config{
        Name:         "order_collector",
        Model:        model,
        Mode:         llmagent.ModeTask,
        OutputSchema: orderListSchema,
        // ...
    })
    
  2. Assign it to a parent agent and use it in the instruction to collect the information:

    coordinator, err := llmagent.New(llmagent.Config{
        SubAgents:   []agent.Agent{orderCollector},
        Instruction: "Delegate using `order_collector`...",
        // ...
    })
    

Run

Set your API key and run the sample with the console launcher:

export GOOGLE_API_KEY=...
go run ./examples/multiagent/task_sub_agent console

Documentation

Overview

Package main 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 coordinator agent delegates interactions to two task sub-agents:

  • order_collector collects the user's food order (from a menu of Pizza, Burger, Salad) and returns a structured list of OrderItem.
  • payment_collector collects credit card and CVV information, returning a PaymentInfo object.

Once both tasks finish, the coordinator invokes the place_order tool with the structured data returned by the sub-agents.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL