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.
Quick 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
Parallel Workflow
Run multiple agents at the same time instead of waiting for each one.
Speed Comparison
| Sequential | Parallel | |
|---|---|---|
| Time | 3 seconds | ~1 second |
| Speed | 1x | 3x faster |
When to Use
Code
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
Failure Handling
Choose how parallel execution responds to failures.
Strategy 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.