Files
google--adk-python/contributing/workflow_samples/node_output
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
..
2026-03-17 23:24:58 -07:00
2026-03-17 23:24:58 -07:00

ADK Workflow Node Output Sample

Overview

This sample demonstrates how to manage component outputs and structure data between nodes in an ADK Workflow.

When stringing nodes together, it's critical to know how the ADK framework passes data along edges. This sample shows:

  1. Returning a raw string (it gets automatically wrapped in an Event).
  2. Returning an explicit Event for more granular control over routes and state.
  3. Generating a structured dictionary via Agent(output_schema=MyModel).
  4. Automatically coercing that raw dictionary back into a fully formed Pydantic model simply by defining it as a type-hint parameter in the Python function.

Sample Inputs

  • cyberpunk future
  • gardening tips for beginners

Graph

         [ START ]
             |
             v
 [ generate_string_output ]
             |
             v
 [ generate_event_output ]
             |
             v
[ generate_pydantic_output ]
             |
             v
 [ consume_pydantic_output ]

How To

  1. Return raw types (string, dict, list): The node runner will automatically wrap primitives in an Event(output=...).

    def generate_string_output(node_input: str):
        return "Processed input: " + node_input
    
  2. Return an Event explicitly: Use this when you also need to emit a route or modify ctx.state.

    def generate_event_output(node_input: str):
        return Event(output=f"Wrapped output: {node_input}")
    
  3. Generate structured data from an LLM: Pass a Pydantic class to the Agent's output_schema. The LLM returns a dictionary/JSON matching the structure.

    class TopicDetails(BaseModel):
        title: str
        description: str
        category: str
    
    generate_pydantic_output = Agent(
        name="generate_pydantic_output",
        output_schema=TopicDetails,
    )
    
  4. Consume structured data in a function: Simply type-hint the parameter. FunctionNode leverages Pydantic to parse the dictionary back into your fully accessible TopicDetails class automatically before your function starts running.

    def consume_pydantic_output(node_input: TopicDetails):
        # Type coercion converts dict to model. Now you have .title, .category, etc.
        return f"Title: {node_input.title}"