Files
google--adk-python/contributing/workflow_samples/node_output/agent.py
T
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

73 lines
2.2 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.
# NOT WORKING YET
# Pending on correct output passing from LLM node
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. The 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,
),
],
)