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:
- Returning a raw string (it gets automatically wrapped in an
Event). - Returning an explicit
Eventfor more granular control over routes and state. - Generating a structured dictionary via
Agent(output_schema=MyModel). - 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.
cyberpunk futuregardening tips for beginners
[ START ]
|
v
[ generate_string_output ]
|
v
[ generate_event_output ]
|
v
[ generate_pydantic_output ]
|
v
[ consume_pydantic_output ]
-
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
-
Return an Event explicitly: Use this when you also need to emit a
routeor modifyctx.state.def generate_event_output(node_input: str): return Event(output=f"Wrapped output: {node_input}")
-
Generate structured data from an LLM: Pass a Pydantic class to the
Agent'soutput_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, )
-
Consume structured data in a function: Simply type-hint the parameter.
FunctionNodeleverages Pydantic to parse the dictionary back into your fully accessibleTopicDetailsclass 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}"