Parallel Workflow

Execute multiple agents simultaneously for faster results

Run independent agents at the same time, then merge their outputs in a final step.

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")

The user runs parallel steps for speed, then lets a summariser agent combine the results.

Diagram

Parallel

📋 Request

⚡ Run at Once

✅ Combined Result

Quick Start

  1. 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")
  2. 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")
  3. 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

Diagram
Parallel AgentsAgentFlowUserParallel AgentsAgentFlowUserstart(“task”)Launch all at onceparallel_outputs listCombined result

Parallel Workflow

Run multiple agents at the same time instead of waiting for each one.

Diagram

📝 Request

⚡ Split

🔍 AI Research

🔍 ML Research

🔍 NLP Research

📋 Combine

✅ Combined Result


Speed Comparison

Diagram
00000000000101010101020202020203Agent 1 Agent 1 Agent 2 Agent 3 Agent 2 Agent 3 SequentialParallelSequential vs Parallel (3 tasks × 1 second each)
SequentialParallel
Time3 seconds~1 second
Speed1x3x faster

When to Use

Diagram

❌ Use Sequential

Tasks depend on each other

Order matters

✅ Use Parallel

Independent tasks

Multiple data sources

Speed matters


Code

python
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

Diagram

⚡ parallel()

Agent 1
→ ‘AI is growing’

Agent 2
→ ‘ML is advancing’

Agent 3
→ ‘NLP improves’

📋 parallel_outputs

[‘AI is growing’, ‘ML is advancing’, ‘NLP improves’]


Failure Handling

Choose how parallel execution responds to failures.

Diagram

What if an agent fails?

partial_ok – Default

fail_fast

fail_all

Continue with partial results
Failed: ‘Error: message’

Stop immediately
Throw WorkflowStepError

Wait for all, then fail
Collect all errors

Strategy Examples

python
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.


Related