docs/guides/workflow/parallel_worker/index.md
ParallelWorker is a workflow node wrapper that executes a wrapped node in parallel for each item in an input list.
When processing a list of items (e.g., a list of documents to analyze, queries to run, or topics to explain), running them sequentially can be slow, especially if the processing node performs I/O-bound operations like calling an LLM or an external API. ParallelWorker solves this by executing the wrapped node concurrently for all items in the input list, significantly reducing total execution time.
Key features:
max_parallel_workers).There are two ways to enable parallel worker mode:
@node decorator (Recommended for functions)You can wrap a Python function in a parallel worker by setting parallel_worker=True in the @node decorator.
from google.adk.workflow import node
@node(parallel_worker=True)
async def process_item(item: str) -> str:
# This function will receive a single item from the list
# and runs in parallel for each item.
return f"Processed: {item}"
Agent configuration (Recommended for Agents)You can configure an Agent to run in parallel worker mode when used as a workflow node.
from google.adk import Agent
analyzer_agent = Agent(
name="analyzer",
instruction="Analyze the following text: {node_input}",
parallel_worker=True
)
list as input. If it receives a single non-list item, it automatically wraps it in a single-element list.ctx.run_node(..., use_sub_branch=True). This creates a sub-branch for each task (e.g., parent_node@1/worker_node@1, parent_node@1/worker_node@2).If the wrapped node triggers an interrupt (e.g., RequestInput), the parallel worker handles it. However, because tasks run concurrently, multiple tasks might trigger interrupts. The workflow engine will handle these interrupts, but the user experience may vary depending on how the runner manages multiple active interrupts.