chore: import upstream snapshot with attribution
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / Pre-commit Linter (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.10) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.11) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.12) (push) Has been cancelled
Continuous Integration / Mypy Check (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.12) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / Unit Tests (Python 3.14) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.10) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.11) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.12) (push) Has been cancelled
Copybara PR Handler / close-imported-pr (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.13) (push) Has been cancelled
Continuous Integration / A2A v0.3 Tests (Python 3.14) (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
# ADK Workflow Multi-Triggers Sample
|
||||
|
||||
## Overview
|
||||
|
||||
This sample demonstrates how a single node can fan out to execute multiple downstream nodes concurrently, and how multiple upstream nodes can trigger a single downstream node independently in **ADK Workflows**.
|
||||
|
||||
In this example, the `START` node fans out to three different processing functions (`make_uppercase`, `count_characters`, and `reverse_string`). Each of these functions receives the initial user input string, processes it, and then independently outputs its result.
|
||||
|
||||
Because the subsequent `send_message` node receives a continuous flow of outputs and does not use an aggregation mechanism (like `JoinNode`), it is triggered multiple times—once for every upstream event.
|
||||
|
||||
## Sample Inputs
|
||||
|
||||
- `Hello World`
|
||||
|
||||
- `ADK workflows`
|
||||
|
||||
- `testing concurrent nodes`
|
||||
|
||||
## Graph
|
||||
|
||||
```mermaid
|
||||
graph TD
|
||||
START --> make_uppercase
|
||||
START --> count_characters
|
||||
START --> reverse_string
|
||||
make_uppercase --> send_message
|
||||
count_characters --> send_message
|
||||
reverse_string --> send_message
|
||||
```
|
||||
|
||||
## How To
|
||||
|
||||
1. You can specify a tuple of nodes within an edge to create a parallel fan-out segment where the same input is provided to multiple nodes:
|
||||
|
||||
```python
|
||||
(
|
||||
"START",
|
||||
(make_uppercase, count_characters, reverse_string),
|
||||
# ...
|
||||
)
|
||||
```
|
||||
|
||||
1. By continuing the sequence to another node after the tuple, the outputs of all nodes in the tuple will independently trigger that target node:
|
||||
|
||||
```python
|
||||
(
|
||||
"START",
|
||||
(make_uppercase, count_characters, reverse_string),
|
||||
send_message,
|
||||
)
|
||||
```
|
||||
|
||||
In this case, `send_message` will be executed once for `make_uppercase`'s output, once for `count_characters`'s output, and once for `reverse_string`'s output.
|
||||
@@ -0,0 +1,45 @@
|
||||
# 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 typing import Any
|
||||
|
||||
from google.adk import Event
|
||||
from google.adk import Workflow
|
||||
|
||||
|
||||
def make_uppercase(node_input: str):
|
||||
return node_input.upper()
|
||||
|
||||
|
||||
def count_characters(node_input: str):
|
||||
return len(node_input)
|
||||
|
||||
|
||||
def reverse_string(node_input: str):
|
||||
return node_input[::-1]
|
||||
|
||||
|
||||
async def send_message(node_input: Any):
|
||||
yield Event(message=f"Triggered for input: {node_input}")
|
||||
|
||||
|
||||
root_agent = Workflow(
|
||||
name="root_agent",
|
||||
edges=[(
|
||||
"START",
|
||||
(make_uppercase, count_characters, reverse_string),
|
||||
send_message,
|
||||
)],
|
||||
input_schema=str,
|
||||
)
|
||||
@@ -0,0 +1,118 @@
|
||||
{
|
||||
"appName": "multi_triggers",
|
||||
"events": [
|
||||
{
|
||||
"author": "user",
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"text": "go"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
},
|
||||
"id": "e-1",
|
||||
"invocationId": "i-1",
|
||||
"nodeInfo": {
|
||||
"path": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"author": "root_agent",
|
||||
"branch": "make_uppercase@1",
|
||||
"id": "e-2",
|
||||
"invocationId": "i-1",
|
||||
"nodeInfo": {
|
||||
"outputFor": [
|
||||
"root_agent@1/make_uppercase@1"
|
||||
],
|
||||
"path": "root_agent@1/make_uppercase@1"
|
||||
},
|
||||
"output": "GO"
|
||||
},
|
||||
{
|
||||
"author": "root_agent",
|
||||
"branch": "count_characters@1",
|
||||
"id": "e-3",
|
||||
"invocationId": "i-1",
|
||||
"nodeInfo": {
|
||||
"outputFor": [
|
||||
"root_agent@1/count_characters@1"
|
||||
],
|
||||
"path": "root_agent@1/count_characters@1"
|
||||
},
|
||||
"output": 2
|
||||
},
|
||||
{
|
||||
"author": "root_agent",
|
||||
"branch": "reverse_string@1",
|
||||
"id": "e-4",
|
||||
"invocationId": "i-1",
|
||||
"nodeInfo": {
|
||||
"outputFor": [
|
||||
"root_agent@1/reverse_string@1"
|
||||
],
|
||||
"path": "root_agent@1/reverse_string@1"
|
||||
},
|
||||
"output": "og"
|
||||
},
|
||||
{
|
||||
"author": "root_agent",
|
||||
"branch": "make_uppercase@1",
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"text": "Triggered for input: GO"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
},
|
||||
"id": "e-5",
|
||||
"invocationId": "i-1",
|
||||
"nodeInfo": {
|
||||
"path": "root_agent@1/send_message@1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"author": "root_agent",
|
||||
"branch": "count_characters@1",
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"text": "Triggered for input: 2"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
},
|
||||
"id": "e-6",
|
||||
"invocationId": "i-1",
|
||||
"nodeInfo": {
|
||||
"path": "root_agent@1/send_message@2"
|
||||
}
|
||||
},
|
||||
{
|
||||
"author": "root_agent",
|
||||
"branch": "reverse_string@1",
|
||||
"content": {
|
||||
"parts": [
|
||||
{
|
||||
"text": "Triggered for input: og"
|
||||
}
|
||||
],
|
||||
"role": "user"
|
||||
},
|
||||
"id": "e-7",
|
||||
"invocationId": "i-1",
|
||||
"nodeInfo": {
|
||||
"path": "root_agent@1/send_message@3"
|
||||
}
|
||||
}
|
||||
],
|
||||
"id": "5cf6403e-fd4e-4fef-ad66-8ae78d26ba29",
|
||||
"state": {
|
||||
"__session_metadata__": {
|
||||
"displayName": "go"
|
||||
}
|
||||
},
|
||||
"userId": "user"
|
||||
}
|
||||
Reference in New Issue
Block a user