Parallel Workflow
Execute multiple agents simultaneously for faster results
Run independent agents at the same time, then merge their outputs in a final step.
from praisonaiagents import Agent, AgentFlow, parallel
ai = Agent(name="AI", instructions="Research AI trends")
ml = Agent(name="ML", instructions="Research ML trends")
summary = Agent(name="Summary", instructions="Combine research")
flow = AgentFlow(steps=[parallel([ai, ml]), summary])
flow.start("Research latest developments")The user runs parallel steps for speed, then lets a summariser agent combine the results.
graph LR
subgraph "Parallel"
U[📋 Request] --> A[⚡ Run at Once]
A --> O[✅ Combined Result]
end
classDef input fill:#6366F1,stroke:#7C90A0,color:#fff
classDef process fill:#189AB4,stroke:#7C90A0,color:#fff
classDef output fill:#10B981,stroke:#7C90A0,color:#fff
class U input
class A process
class O outputQuick Start
- Simple Usage
Run two agents together, then summarise with a third.
python from praisonaiagents import Agent, AgentFlow, parallel ai = Agent(name="AI", instructions="Research AI trends") ml = Agent(name="ML", instructions="Research ML trends") summary = Agent(name="Summary", instructions="Combine research") flow = AgentFlow(steps=[parallel([ai, ml]), summary]) flow.start("Research latest developments") - With Configuration
Choose how the group reacts to a failing agent.
python from praisonaiagents import Agent, AgentFlow, parallel flow = AgentFlow(steps=[ parallel([ai, ml], on_failure="fail_fast"), summary, ]) flow.start("Research latest developments") - Timing out
Set
timeout=<seconds>to bound the whole parallel block — the run no longer hangs if one agent is stuck.python # Give up on the whole fan-out after 10 seconds flow = AgentFlow(steps=[parallel([ai, ml], timeout=10), summary])
How It Works
sequenceDiagram
participant User
participant AgentFlow
participant Agents as Parallel Agents
User->>AgentFlow: start("task")
AgentFlow->>Agents: Launch all at once
Agents-->>AgentFlow: parallel_outputs list
AgentFlow-->>User: Combined resultParallel Workflow
Run multiple agents at the same time instead of waiting for each one.
graph TB
Input([📝 Request]) --> Split((⚡ Split))
Split --> A1[🔍 AI Research]
Split --> A2[🔍 ML Research]
Split --> A3[🔍 NLP Research]
A1 --> Merge((📋 Combine))
A2 --> Merge
A3 --> Merge
Merge --> Output([✅ Combined Result])
classDef io fill:#8B0000,stroke:#7C90A0,color:#fff
classDef agent fill:#189AB4,stroke:#7C90A0,color:#fff
classDef split fill:#10B981,stroke:#7C90A0,color:#fff
class Input,Output io
class A1,A2,A3 agent
class Split,Merge splitSpeed Comparison
gantt
title Sequential vs Parallel (3 tasks × 1 second each)
dateFormat ss
axisFormat %S
section Sequential
Agent 1 :a1, 00, 1s
Agent 2 :a2, after a1, 1s
Agent 3 :a3, after a2, 1s
section Parallel
Agent 1 :b1, 00, 1s
Agent 2 :b2, 00, 1s
Agent 3 :b3, 00, 1s| Sequential | Parallel | |
|---|---|---|
| Time | 3 seconds | ~1 second |
| Speed | 1x | 3x faster |
When to Use
graph LR
subgraph "✅ Use Parallel"
A[Independent tasks]
B[Multiple data sources]
C[Speed matters]
end
subgraph "❌ Use Sequential"
D[Tasks depend on each other]
E[Order matters]
end
classDef good fill:#10B981,stroke:#7C90A0,color:#fff
classDef bad fill:#EF4444,stroke:#7C90A0,color:#fff
class A,B,C good
class D,E badCode
from praisonaiagents import Agent, AgentFlow
from praisonaiagents import parallel
# Create agents
ai_researcher = Agent(name="AI", instructions="Research AI trends")
ml_researcher = Agent(name="ML", instructions="Research ML trends")
nlp_researcher = Agent(name="NLP", instructions="Research NLP trends")
summarizer = Agent(name="Summary", instructions="Combine all research")
# Run in parallel, then summarize
flow = AgentFlow(steps=[
parallel([ai_researcher, ml_researcher, nlp_researcher]),
summarizer
])
result = flow.start("Research latest developments")How Results Combine
graph TB
subgraph Parallel["⚡ parallel()"]
A1["Agent 1<br/>→ 'AI is growing'"]
A2["Agent 2<br/>→ 'ML is advancing'"]
A3["Agent 3<br/>→ 'NLP improves'"]
end
Parallel --> Results["📋 parallel_outputs"]
Results --> List["['AI is growing', 'ML is advancing', 'NLP improves']"]
classDef agent fill:#189AB4,stroke:#7C90A0,color:#fff
classDef result fill:#10B981,stroke:#7C90A0,color:#fff
class A1,A2,A3 agent
class Results,List resultFailure Handling
Choose how parallel execution responds to failures.
graph TB
A{What if an agent fails?} --> B[partial_ok - Default]
A --> C[fail_fast]
A --> D[fail_all]
B --> B1[Continue with partial results<br/>Failed: 'Error: message']
C --> C1[Stop immediately<br/>Throw WorkflowStepError]
D --> D1[Wait for all, then fail<br/>Collect all errors]
classDef decision fill:#6366F1,stroke:#7C90A0,color:#fff
classDef strategy fill:#F59E0B,stroke:#7C90A0,color:#fff
classDef result fill:#10B981,stroke:#7C90A0,color:#fff
class A decision
class B,C,D strategy
class B1,C1,D1 resultStrategy Examples
from praisonaiagents import WorkflowStepError
# Default: Continue with partial results
flow = AgentFlow(steps=[
parallel([agent_a, agent_b, agent_c]), # Some might fail
summarizer # Gets whatever succeeded
])
# Stop fast: First failure cancels others
flow = AgentFlow(steps=[
parallel([agent_a, agent_b, agent_c], on_failure="fail_fast"),
# This step never runs if any agent fails
])
# Fail all: Wait for everything, then report errors
try:
flow = AgentFlow(steps=[
parallel([agent_a, agent_b, agent_c], on_failure="fail_all"),
])
result = flow.start("Process")
except WorkflowStepError as e:
print(f"Failed agents: {len(e.errors)}")Best Practices
Only parallelise independent work
parallel gives no benefit when a step depends on an earlier result. Use it for genuinely independent research or data pulls.
Pick a failure strategy on purpose
partial_ok (default) keeps going with what succeeded; fail_fast cancels the rest on the first error; fail_all collects every error. Choose per the cost of missing data.
Read results from parallel_outputs
Parallel steps return a list in parallel_outputs. Have the summariser combine that list rather than expecting a single string.
Import parallel from the top level
from praisonaiagents import parallel uses the friendly re-export, keeping the sample short and matching the SDK’s recommended surface.