Workflow Parallel Execution
Execute multiple steps concurrently and combine their results. This pattern is ideal for independent tasks that can run simultaneously.Quick Start
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 |
Best Practices
- Independent tasks only - Parallel steps shouldn’t depend on each other
- Handle errors gracefully - One failure shouldn’t break all tasks
- Aggregate results - Always follow with a step that combines outputs
- Consider rate limits - Don’t overwhelm external APIs
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 |

