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

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,54 @@
# Input and Output Schema
## Overview
This sample demonstrates how to configure structured `input_schema` and `output_schema` on an ADK agent. When configured with these schemas and `mode='single_turn'`, the agent can be seamlessly used as a structured tool by a parent agent.
## Sample Inputs
- `What is the weather in San Jose?`
*The parent agent calls `weather_agent` with `{"city": "San Jose"}`. The sub-agent returns `{"temperature": "26 C", "conditions": "Sunny"}`. The parent agent then formulates a friendly response.*
- `Can you check the weather for Cupertino?`
*The parent agent calls `weather_agent` with `{"city": "Cupertino"}`. The sub-agent returns `{"temperature": "16 C", "conditions": "Foggy"}`.*
## Graph
```mermaid
graph TD
User[User Input] --> RootAgent[root_agent]
RootAgent -- Tool Call: CityQuery --> WeatherAgent[weather_agent]
WeatherAgent -- Structured Output: WeatherInfo --> RootAgent
RootAgent --> Response[User Response]
```
## How To
### Configuring Input and Output Schemas
To define structured input and output contracts for an agent, pass Pydantic models to the `input_schema` and `output_schema` parameters of the `Agent` constructor:
```python
class CityQuery(BaseModel):
city: str = Field(description="The name of the city")
class WeatherInfo(BaseModel):
temperature: str = Field(description="The temperature in Celsius")
conditions: str = Field(description="The weather condition")
weather_agent = Agent(
name="weather_agent",
mode="single_turn",
input_schema=CityQuery,
output_schema=WeatherInfo,
instruction="Provide weather information for the requested city.",
)
```
### Using the Agent as a Tool
When `weather_agent` is included in the `sub_agents` list of `root_agent`, the ADK framework automatically wraps it in an `AgentTool`. The parent agent sees a tool that accepts `CityQuery` parameters and returns `WeatherInfo`.
When the tool is invoked, the framework executes `weather_agent` in an isolated context, validates its input against `input_schema`, and validates its generated response against `output_schema`.
@@ -0,0 +1,53 @@
# 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 pydantic import BaseModel
from pydantic import Field
class CityQuery(BaseModel):
city: str = Field(
description='The name of the city to query weather for, e.g. San Jose'
)
class WeatherInfo(BaseModel):
temperature: str = Field(description='The temperature in Celsius')
conditions: str = Field(description='The weather condition, e.g. Sunny')
weather_agent = Agent(
name='weather_agent',
mode='single_turn',
input_schema=CityQuery,
output_schema=WeatherInfo,
instruction="""\
Provide weather information for the requested city.
For San Jose, return temperature: 26 C, conditions: Sunny.
For Cupertino, return temperature: 16 C, conditions: Foggy.
For any other city, return temperature: unknown, conditions: unknown.
""",
)
root_agent = Agent(
name='root_agent',
instruction="""\
You are a helpful weather concierge assistant. Use the weather_agent tool to get weather information for the user's city, and then answer the user in a friendly manner.
""",
sub_agents=[weather_agent],
)
@@ -0,0 +1,106 @@
{
"events": [
{
"author": "user",
"content": {
"parts": [
{
"text": "What is the weather in Cupertino?"
}
],
"role": "user"
},
"id": "e-1",
"invocationId": "i-1",
"nodeInfo": {
"path": ""
}
},
{
"author": "root_agent",
"content": {
"parts": [
{
"functionCall": {
"args": {
"city": "Cupertino"
},
"id": "fc-1",
"name": "weather_agent"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-2",
"invocationId": "i-1",
"longRunningToolIds": [],
"nodeInfo": {
"path": "root_agent@1"
}
},
{
"author": "weather_agent",
"branch": "weather_agent@fc-1",
"content": {
"parts": [
{
"text": "{\"temperature\": \"16 C\", \"conditions\": \"Foggy\"}"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-3",
"invocationId": "i-1",
"nodeInfo": {
"messageAsOutput": true,
"outputFor": [
"root_agent@1/weather_agent@1"
],
"path": "root_agent@1/weather_agent@1"
}
},
{
"author": "root_agent",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-1",
"name": "weather_agent",
"response": {
"conditions": "Foggy",
"temperature": "16 C"
}
}
}
],
"role": "user"
},
"id": "e-4",
"invocationId": "i-1",
"nodeInfo": {
"path": "root_agent@1"
}
},
{
"author": "root_agent",
"content": {
"parts": [
{
"text": "The weather in Cupertino is Foggy with a temperature of 16 C.\n"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-5",
"invocationId": "i-1",
"nodeInfo": {
"path": "root_agent@1"
}
}
]
}
@@ -0,0 +1,106 @@
{
"events": [
{
"author": "user",
"content": {
"parts": [
{
"text": "What is the weather in San Jose?"
}
],
"role": "user"
},
"id": "e-1",
"invocationId": "i-1",
"nodeInfo": {
"path": ""
}
},
{
"author": "root_agent",
"content": {
"parts": [
{
"functionCall": {
"args": {
"city": "San Jose"
},
"id": "fc-1",
"name": "weather_agent"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-2",
"invocationId": "i-1",
"longRunningToolIds": [],
"nodeInfo": {
"path": "root_agent@1"
}
},
{
"author": "weather_agent",
"branch": "weather_agent@fc-1",
"content": {
"parts": [
{
"text": "{\"temperature\": \"26 C\", \"conditions\": \"Sunny\"}"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-3",
"invocationId": "i-1",
"nodeInfo": {
"messageAsOutput": true,
"outputFor": [
"root_agent@1/weather_agent@1"
],
"path": "root_agent@1/weather_agent@1"
}
},
{
"author": "root_agent",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-1",
"name": "weather_agent",
"response": {
"conditions": "Sunny",
"temperature": "26 C"
}
}
}
],
"role": "user"
},
"id": "e-4",
"invocationId": "i-1",
"nodeInfo": {
"path": "root_agent@1"
}
},
{
"author": "root_agent",
"content": {
"parts": [
{
"text": "The weather in San Jose is sunny with a temperature of 26 degrees Celsius. Enjoy your day!"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-5",
"invocationId": "i-1",
"nodeInfo": {
"path": "root_agent@1"
}
}
]
}
@@ -0,0 +1,106 @@
{
"events": [
{
"author": "user",
"content": {
"parts": [
{
"text": "What is the weather in Tokyo?"
}
],
"role": "user"
},
"id": "e-1",
"invocationId": "i-1",
"nodeInfo": {
"path": ""
}
},
{
"author": "root_agent",
"content": {
"parts": [
{
"functionCall": {
"args": {
"city": "Tokyo"
},
"id": "fc-1",
"name": "weather_agent"
}
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-2",
"invocationId": "i-1",
"longRunningToolIds": [],
"nodeInfo": {
"path": "root_agent@1"
}
},
{
"author": "weather_agent",
"branch": "weather_agent@fc-1",
"content": {
"parts": [
{
"text": "{\"temperature\": \"unknown\", \"conditions\": \"unknown\"}"
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-3",
"invocationId": "i-1",
"nodeInfo": {
"messageAsOutput": true,
"outputFor": [
"root_agent@1/weather_agent@1"
],
"path": "root_agent@1/weather_agent@1"
}
},
{
"author": "root_agent",
"content": {
"parts": [
{
"functionResponse": {
"id": "fc-1",
"name": "weather_agent",
"response": {
"conditions": "unknown",
"temperature": "unknown"
}
}
}
],
"role": "user"
},
"id": "e-4",
"invocationId": "i-1",
"nodeInfo": {
"path": "root_agent@1"
}
},
{
"author": "root_agent",
"content": {
"parts": [
{
"text": "I'm sorry, I don't have the current weather information for Tokyo."
}
],
"role": "model"
},
"finishReason": "STOP",
"id": "e-5",
"invocationId": "i-1",
"nodeInfo": {
"path": "root_agent@1"
}
}
]
}