Files
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

1.9 KiB

ADK Workflow Loop Sample

Overview

This sample demonstrates how to create a feedback loop between different nodes in ADK Workflows.

It takes a user-provided topic and uses the generate_headline agent to write a headline. The evaluate_headline agent then grades the headline as either "tech-related" or "unrelated", providing feedback if it's unrelated. The route_headline function checks this grade. If the headline is "unrelated", the workflow loops back to the generate_headline agent, passing the feedback so it can try again. This process repeats until a "tech-related" headline is generated.

In ADK Workflows, loops allow for iterative refinement and evaluation by conditionally routing execution back to an earlier node in the sequence.

Sample Inputs

  • flower
  • quantum mechanics
  • renewable energy

Graph

                  [ START ]
                      |
                      v
              [ process_input ]
                      |
                      v
          +->[ generate_headline ]
          |           |
          |           v
    (feedback) [ evaluate_headline ]
          |           |
          |           v
          |   [ route_headline ]
          |        /      \
          +--"unrelated"  "tech-related"
                             |
                             v
                        (Loop ends)

How To

  1. Define a node (like route_headline) that yields an Event with a specific route based on a condition:

    def route_headline(node_input: Feedback):
      return Event(route=node_input.grade)
    
  2. In the Workflow edges definition, create a conditional edge that connects the routing node back to a previous node in the workflow, using a routing map dict:

    (route_headline, {"unrelated": generate_headline})
    

    This creates the cycle. If the route yielded by route_headline is "unrelated", execution jumps back to generate_headline.