Files
google--adk-python/contributing/samples/workflows/node_output/agent.py
T
wehub-resource-sync ec2b666284
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
chore: import upstream snapshot with attribution
2026-07-13 13:25:13 +08:00

71 lines
2.1 KiB
Python

# 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 google.adk import Agent
from google.adk import Event
from google.adk import Workflow
from pydantic import BaseModel
from pydantic import Field
class TopicDetails(BaseModel):
title: str = Field(description="The title of the generated topic.")
description: str = Field(description="A short description of the topic.")
category: str = Field(description="The broad category of the topic.")
def generate_string_output(node_input: str):
"""Returns a simple string. Framework automatically wraps it in an Event."""
return f"Processed input: {node_input}"
def generate_event_output(node_input: str):
"""Explicitly returns an Event object for more control."""
return Event(output=f"Event wrapped output: {node_input}")
generate_pydantic_output = Agent(
name="generate_pydantic_output",
instruction="Generate a creative topic based on the following input.",
output_schema=TopicDetails,
)
def consume_pydantic_output(node_input: TopicDetails):
"""
Relying on the FunctionNode's automatic type parsing.
The framework will coerce the dictionary or JSON into a TopicDetails
object automatically.
"""
return (
"Received Pydantic Model!\n"
f"Title: {node_input.title}\n"
f"Description: {node_input.description}\n"
f"Category: {node_input.category}"
)
root_agent = Workflow(
name="root_agent",
edges=[
(
"START",
generate_string_output,
generate_event_output,
generate_pydantic_output,
consume_pydantic_output,
),
],
)