Quick Start
Output:API Reference
parallel()
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
steps | List | — | List of steps to execute concurrently |
max_workers | Optional[int] | None | Cap on ThreadPoolExecutor workers. Defaults to min(3, len(steps)) |
on_failure | "partial_ok" | "fail_fast" | "fail_all" | "partial_ok" | Failure-handling strategy |
Accessing Results
After parallel execution, results are available inctx.variables:
| Variable | Type | Description |
|---|---|---|
parallel_outputs | List[str] | List of all outputs in order |
Examples
With Agents
Mixed Steps
Nested Parallel
Performance
Parallel execution uses Python’sThreadPoolExecutor:
- Concurrent I/O: Ideal for API calls, file operations
- Thread-safe: Each step gets its own copy of variables
- Automatic joining: All results collected before next step
Use Cases
| Use Case | Description |
|---|---|
| Multi-source Research | Query multiple APIs simultaneously |
| Data Processing | Process independent data chunks |
| Report Generation | Generate sections in parallel |
| Validation | Run multiple validators concurrently |
| A/B Comparison | Run different approaches and compare |
How It Works
| Phase | What happens |
|---|---|
| 1. Fan-out | parallel() submits each step to a thread pool simultaneously |
| 2. Execute | Steps run concurrently; each receives the same workflow context |
| 3. Collect | All results gather into ctx.variables["parallel_outputs"] in completion order |
| 4. Continue | Next workflow step (aggregator) receives the merged outputs |
Best Practices
Parallelise only independent steps
Parallelise only independent steps
Branches must not depend on each other’s output in the same parallel group.
Cap concurrency for external APIs
Cap concurrency for external APIs
Rate-limited tools may need sequential execution or throttling despite parallel support.
Collect and inspect branch errors
Collect and inspect branch errors
Read the aggregated error list after
ParallelExecutionError before retrying.Keep branch outputs small
Keep branch outputs small
Large parallel results inflate context — summarise before merging downstream.
Failure Handling
Choose how a parallel block reacts when a branch fails using theon_failure parameter.
Failure Strategies
| Strategy | Behavior | Use Case |
|---|---|---|
partial_ok | Continue with partial results. Failed branches return "Error: <msg>" | Data aggregation where some sources may be unavailable |
fail_fast | Cancel remaining branches and raise WorkflowStepError on first failure | Critical workflows where any failure invalidates results |
fail_all | Wait for all branches, then raise WorkflowStepError if any failed | Comprehensive error reporting and debugging |
Examples
Error Handling with partial_ok
Exception Handling with fail_fast/fail_all
Related
Workflow Patterns
Overview of routing, parallel, loop, and repeat
Workflow Routing
Decision-based branching
Workflow Loop
Iterate over lists and files
Workflow Repeat
Repeat until a condition is met

