chore: import upstream snapshot with attribution
Continuous Integration / Pre-commit Linter (push) Waiting to run
Continuous Integration / Mypy Check (Python 3.10) (push) Waiting to run
Continuous Integration / Mypy Check (Python 3.11) (push) Waiting to run
Continuous Integration / Mypy Check (Python 3.12) (push) Waiting to run
Continuous Integration / Mypy Check (Python 3.13) (push) Waiting to run
Continuous Integration / Unit Tests (Python 3.10) (push) Waiting to run
Continuous Integration / Unit Tests (Python 3.11) (push) Waiting to run
Continuous Integration / Unit Tests (Python 3.12) (push) Waiting to run
Continuous Integration / Unit Tests (Python 3.13) (push) Waiting to run
Continuous Integration / Unit Tests (Python 3.14) (push) Waiting to run
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Waiting to run
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Waiting to run
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Waiting to run
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Waiting to run
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Waiting to run
Copybara PR Handler / close-imported-pr (push) Waiting to run

This commit is contained in:
wehub-resource-sync
2026-07-13 13:25:13 +08:00
commit ec2b666284
2231 changed files with 491535 additions and 0 deletions
@@ -0,0 +1,56 @@
# 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]`.
1. `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
```mermaid
graph TD
coordinator --> order_collector
coordinator --> payment_collector
coordinator -.->|uses| place_order[place_order tool]
```
## How To
1. Define a sub-agent with `mode="task"` and an output schema:
```python
order_collector = Agent(
name="order_collector",
mode="task",
output_schema=list[OrderItem],
...
)
```
1. Assign it to a parent agent and use it in the instruction to collect the information:
```python
coordinator = Agent(
sub_agents=[order_collector],
instruction="Delegate using `order_collector`...",
...
)
```
## Related Guides
- [LlmAgent Task Mode](../../../../docs/guides/agents/llm_agent/task.md) - Guide explaining the behavior and configuration of task-mode agents.
@@ -0,0 +1,83 @@
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
from google.adk import Agent
from google.adk.tools.function_tool import FunctionTool
from pydantic import BaseModel
from pydantic import Field
class OrderItem(BaseModel):
name: str = Field(description="Name of the food item ordered")
quantity: int = Field(description="Quantity ordered")
class PaymentInfo(BaseModel):
"""Output schema for the payment collection task."""
credit_card_number: str
cvv: str
def place_order(orders: list[OrderItem], payment_info: PaymentInfo) -> str:
"""Mock an order placement operation."""
total_items = sum(item.quantity for item in orders)
return f"Successfully placed order for {total_items} items."
def confirmation() -> str:
"""Confirm proceeding with the order."""
return "Proceeding with order."
order_collector = Agent(
name="order_collector",
mode="task",
output_schema=list[OrderItem],
instruction=("""\
You are an order collection assistant for a food delivery service.
Our menu today has exactly 3 items: 1. Pizza, 2. Burger, 3. Salad.
Ask the user what they would like to order and collect their choice and quantity.
Do not offer anything else.
If the combined quantity of items exceeds 5, you MUST use the `confirmation` tool to get user's confirmation before proceeding.
Do not ask for confirmation in natural language, always use the confirmation tool.
Once you have their final order and confirmation if needed, finish your task.
"""),
description="Collects the food order from the user.",
tools=[FunctionTool(confirmation, require_confirmation=True)],
)
payment_collector = Agent(
name="payment_collector",
mode="task",
output_schema=PaymentInfo,
instruction=("""\
You are a payment collection assistant.
Ask the user for their credit card number and CVV.
Once you have both pieces of information, finish your task.
"""),
description="Collects credit card and CVV from the user.",
)
root_agent = Agent(
name="coordinator",
sub_agents=[order_collector, payment_collector],
tools=[place_order],
instruction="""\
You are a helpful coordinator for a food delivery service.
You need both order and payment information to place an order.
""",
)
@@ -0,0 +1,224 @@
{
"events": [
{
"author": "user",
"content": {
"parts": [
{
"text": "10 burgers"
}
],
"role": "user"
},
"id": "e-1",
"invocationId": "i-1",
"nodeInfo": {
"path": ""
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"functionCall": {
"args": {
"request": "The user wants 10 burgers. Please confirm the details of the burgers and any other items they might want."
},
"id": "fc-1",
"name": "order_collector"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-2",
"invocationId": "i-1",
"longRunningToolIds": [],
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"text": "I've noted that you'd like 10 burgers. Would you like to add any pizza or salad to your order?"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-3",
"invocationId": "i-1",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"author": "user",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-3",
"name": "adk_request_confirmation",
"response": {
"confirmed": true,
"payload": {}
}
}
}
],
"role": "user"
},
"id": "e-4",
"invocationId": "",
"nodeInfo": {
"path": ""
}
},
{
"author": "user",
"content": {
"parts": [
{
"text": "1234-1234"
}
],
"role": "user"
},
"id": "e-5",
"invocationId": "i-2",
"nodeInfo": {
"path": ""
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"text": "I'm sorry, I didn't quite catch that. We offer Pizza, Burgers, and Salads. You've mentioned 10 burgers so far. Would you like to add any pizza or salad to your order, or is that everything?"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-6",
"invocationId": "i-2",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"author": "user",
"content": {
"parts": [
{
"text": "123"
}
],
"role": "user"
},
"id": "e-7",
"invocationId": "i-3",
"nodeInfo": {
"path": ""
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"functionCall": {
"args": {},
"id": "fc-2",
"name": "confirmation"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-8",
"invocationId": "i-3",
"isolationScope": "fc-1",
"longRunningToolIds": [],
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"functionCall": {
"args": {
"originalFunctionCall": {
"args": {},
"id": "fc-2",
"name": "confirmation"
},
"toolConfirmation": {
"confirmed": false,
"hint": "Please approve or reject the tool call confirmation() by responding with a FunctionResponse with an expected ToolConfirmation payload."
}
},
"id": "fc-3",
"name": "adk_request_confirmation"
}
}
],
"role": "model"
},
"id": "e-9",
"invocationId": "i-3",
"isolationScope": "fc-1",
"longRunningToolIds": [
"fc-3"
],
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"actions": {
"requestedToolConfirmations": {
"fc-2": {
"confirmed": false,
"hint": "Please approve or reject the tool call confirmation() by responding with a FunctionResponse with an expected ToolConfirmation payload."
}
},
"skipSummarization": true
},
"author": "order_collector",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-2",
"name": "confirmation",
"response": {
"error": "This tool call requires confirmation, please approve or reject."
}
}
}
],
"role": "user"
},
"id": "e-10",
"invocationId": "i-3",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
}
]
}
@@ -0,0 +1,410 @@
{
"events": [
{
"author": "user",
"content": {
"parts": [
{
"text": "3 burgers"
}
],
"role": "user"
},
"id": "e-1",
"invocationId": "i-1",
"nodeInfo": {
"path": ""
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"functionCall": {
"args": {
"request": "The user wants to order 3 burgers. Please confirm if there are any specific types or details they'd like for these burgers."
},
"id": "fc-1",
"name": "order_collector"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-2",
"invocationId": "i-1",
"longRunningToolIds": [],
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"text": "Hello! We have Pizza, Burgers, and Salads on our menu today. You've chosen 3 Burgers. Would you like to add any Pizza or Salads to your order, or is that all for today?"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-3",
"invocationId": "i-1",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"author": "user",
"content": {
"parts": [
{
"text": "ready to pay"
}
],
"role": "user"
},
"id": "e-4",
"invocationId": "i-2",
"nodeInfo": {
"path": ""
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"functionCall": {
"args": {
"result": [
{
"name": "Burger",
"quantity": 3
}
]
},
"id": "fc-2",
"name": "finish_task"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-5",
"invocationId": "i-2",
"isolationScope": "fc-1",
"longRunningToolIds": [],
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-2",
"name": "finish_task",
"response": {
"result": "Task completed."
}
}
}
],
"role": "user"
},
"id": "e-6",
"invocationId": "i-2",
"isolationScope": "fc-1",
"nodeInfo": {
"outputFor": [
"coordinator@1/order_collector@fc-1"
],
"path": "coordinator@1/order_collector@fc-1"
},
"output": [
{
"name": "Burger",
"quantity": 3
}
]
},
{
"author": "user",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-1",
"name": "order_collector",
"response": {
"output": [
{
"name": "Burger",
"quantity": 3
}
]
}
}
}
],
"role": "user"
},
"id": "e-7",
"invocationId": "i-2",
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"functionCall": {
"args": {
"request": "Please collect the user's credit card number and CVV for their order of 3 burgers."
},
"id": "fc-3",
"name": "payment_collector"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-8",
"invocationId": "i-2",
"longRunningToolIds": [],
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "payment_collector",
"content": {
"parts": [
{
"text": "To process your order for 3 burgers, could you please provide your credit card number and the 3-digit CVV code?"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-9",
"invocationId": "i-2",
"isolationScope": "fc-3",
"nodeInfo": {
"path": "coordinator@1/payment_collector@fc-3"
}
},
{
"author": "user",
"content": {
"parts": [
{
"text": "1234-1234"
}
],
"role": "user"
},
"id": "e-10",
"invocationId": "i-3",
"nodeInfo": {
"path": ""
}
},
{
"author": "payment_collector",
"content": {
"parts": [
{
"text": "Thank you. Could you also provide the 3-digit CVV code for your card?"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-11",
"invocationId": "i-3",
"isolationScope": "fc-3",
"nodeInfo": {
"path": "coordinator@1/payment_collector@fc-3"
}
},
{
"author": "user",
"content": {
"parts": [
{
"text": "123"
}
],
"role": "user"
},
"id": "e-12",
"invocationId": "i-4",
"nodeInfo": {
"path": ""
}
},
{
"author": "payment_collector",
"content": {
"parts": [
{
"functionCall": {
"args": {
"credit_card_number": "1234-1234",
"cvv": "123"
},
"id": "fc-4",
"name": "finish_task"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-13",
"invocationId": "i-4",
"isolationScope": "fc-3",
"longRunningToolIds": [],
"nodeInfo": {
"path": "coordinator@1/payment_collector@fc-3"
}
},
{
"author": "payment_collector",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-4",
"name": "finish_task",
"response": {
"result": "Task completed."
}
}
}
],
"role": "user"
},
"id": "e-14",
"invocationId": "i-4",
"isolationScope": "fc-3",
"nodeInfo": {
"outputFor": [
"coordinator@1/payment_collector@fc-3"
],
"path": "coordinator@1/payment_collector@fc-3"
},
"output": {
"credit_card_number": "1234-1234",
"cvv": "123"
}
},
{
"author": "user",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-3",
"name": "payment_collector",
"response": {
"credit_card_number": "1234-1234",
"cvv": "123"
}
}
}
],
"role": "user"
},
"id": "e-15",
"invocationId": "i-4",
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"functionCall": {
"args": {
"orders": [
{
"name": "Burger",
"quantity": 3
}
],
"payment_info": {
"credit_card_number": "1234-1234",
"cvv": "123"
}
},
"id": "fc-5",
"name": "place_order"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-16",
"invocationId": "i-4",
"longRunningToolIds": [],
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-5",
"name": "place_order",
"response": {
"result": "Successfully placed order for 3 items."
}
}
}
],
"role": "user"
},
"id": "e-17",
"invocationId": "i-4",
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"text": "Your order for 3 burgers has been successfully placed!"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-18",
"invocationId": "i-4",
"nodeInfo": {
"path": "coordinator@1"
}
}
]
}
@@ -0,0 +1,92 @@
{
"events": [
{
"author": "user",
"content": {
"parts": [
{
"text": "3 burgers, credit card 1234-1234, cvv 123"
}
],
"role": "user"
},
"id": "e-1",
"invocationId": "i-1",
"nodeInfo": {
"path": ""
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"functionCall": {
"args": {
"orders": [
{
"name": "burger",
"quantity": 3
}
],
"payment_info": {
"credit_card_number": "1234-1234",
"cvv": "123"
}
},
"id": "fc-1",
"name": "place_order"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-2",
"invocationId": "i-1",
"longRunningToolIds": [],
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-1",
"name": "place_order",
"response": {
"result": "Successfully placed order for 3 items."
}
}
}
],
"role": "user"
},
"id": "e-3",
"invocationId": "i-1",
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"text": "Your order for 3 burgers has been successfully placed."
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-4",
"invocationId": "i-1",
"nodeInfo": {
"path": "coordinator@1"
}
}
]
}
@@ -0,0 +1,96 @@
{
"events": [
{
"author": "user",
"content": {
"parts": [
{
"text": "credit card 1234-1234, cvv 123"
}
],
"role": "user"
},
"id": "e-1",
"invocationId": "i-1",
"nodeInfo": {
"path": ""
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"functionCall": {
"args": {
"request": "The user has provided payment info. Please find out what food they would like to order."
},
"id": "fc-1",
"name": "order_collector"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-2",
"invocationId": "i-1",
"longRunningToolIds": [],
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"text": "Hello! What would you like to order today? We have Pizza, Burgers, and Salads available. Please let me know your choice and the quantity."
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-3",
"invocationId": "i-1",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"author": "user",
"content": {
"parts": [
{
"text": "3 burgers"
}
],
"role": "user"
},
"id": "e-4",
"invocationId": "i-2",
"nodeInfo": {
"path": ""
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"text": "I have added 3 Burgers to your order. Would you like to add any Pizza or Salad, or is that all for today?"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-5",
"invocationId": "i-2",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
}
]
}
@@ -0,0 +1,198 @@
{
"events": [
{
"author": "user",
"content": {
"parts": [
{
"text": "order food"
}
],
"role": "user"
},
"id": "e-1",
"invocationId": "i-1",
"nodeInfo": {
"path": ""
}
},
{
"author": "coordinator",
"content": {
"parts": [
{
"functionCall": {
"args": {
"request": "Please help the user order food by collecting the items and quantities they want."
},
"id": "fc-1",
"name": "order_collector"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-2",
"invocationId": "i-1",
"longRunningToolIds": [],
"nodeInfo": {
"path": "coordinator@1"
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"text": "Hello! What would you like to order today? Our menu includes:\n1. Pizza\n2. Burger\n3. Salad\n\nPlease let me know which items and how many of each you'd like."
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-3",
"invocationId": "i-1",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"author": "user",
"content": {
"parts": [
{
"text": "burger"
}
],
"role": "user"
},
"id": "e-4",
"invocationId": "i-2",
"nodeInfo": {
"path": ""
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"text": "How many burgers would you like to order?"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-5",
"invocationId": "i-2",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"author": "user",
"content": {
"parts": [
{
"text": "3"
}
],
"role": "user"
},
"id": "e-6",
"invocationId": "i-3",
"nodeInfo": {
"path": ""
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"text": "Great! You've ordered 3 burgers. Would you like to add anything else to your order (Pizza or Salad), or is that all for today?"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-7",
"invocationId": "i-3",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"author": "user",
"content": {
"parts": [
{
"text": "1234-1234"
}
],
"role": "user"
},
"id": "e-8",
"invocationId": "i-4",
"nodeInfo": {
"path": ""
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"text": "I'm sorry, I didn't quite understand that. Would you like to add any Pizza or Salad to your order of 3 Burgers, or is that all?"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-9",
"invocationId": "i-4",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
},
{
"author": "user",
"content": {
"parts": [
{
"text": "123"
}
],
"role": "user"
},
"id": "e-10",
"invocationId": "i-5",
"nodeInfo": {
"path": ""
}
},
{
"author": "order_collector",
"content": {
"parts": [
{
"text": "I'm sorry, I'm not sure what you mean by \"123\". Would you like to add 123 of one of our menu items (Pizza or Salad) to your order, or would you like to finish your order with just the 3 burgers?"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-11",
"invocationId": "i-5",
"isolationScope": "fc-1",
"nodeInfo": {
"path": "coordinator@1/order_collector@fc-1"
}
}
]
}