CrewAI Tutorial (Python): running agents in parallel for advanced developers

By Cyprian AaronsUpdated 2026-04-21
crewairunning-agents-in-parallel-for-advanced-developerspython

This tutorial shows how to run multiple CrewAI agents in parallel from Python, then merge their outputs into a single result. You need this when one task can be split into independent sub-tasks, like research, validation, and summarization, and you want lower latency than a strictly sequential crew.

What You'll Need

  • Python 3.10 or newer
  • crewai
  • crewai-tools
  • An LLM API key, such as:
    • OPENAI_API_KEY
    • or another provider supported by your CrewAI setup
  • Basic familiarity with:
    • Agent
    • Task
    • Crew
    • Process
  • A terminal and virtual environment

Install the packages:

pip install crewai crewai-tools

Set your API key:

export OPENAI_API_KEY="your-key-here"

Step-by-Step

  1. Start by defining a small set of independent agents. The key requirement for parallel execution is that each agent gets a task it can complete without waiting on another agent’s output.
from crewai import Agent

researcher = Agent(
    role="Researcher",
    goal="Find concise technical facts about Python concurrency patterns",
    backstory="You are strong at gathering implementation details from documentation.",
    verbose=True,
)

validator = Agent(
    role="Validator",
    goal="Check whether the proposed approach is safe and production-ready",
    backstory="You focus on edge cases, failure modes, and operational concerns.",
    verbose=True,
)

writer = Agent(
    role="Writer",
    goal="Summarize findings into a practical implementation guide",
    backstory="You turn technical notes into clear developer-facing guidance.",
    verbose=True,
)
  1. Create tasks that do not depend on each other. If you want parallelism, avoid chaining outputs from one task into the next until after the parallel phase completes.
from crewai import Task

research_task = Task(
    description=(
        "List three production-grade patterns for running independent work in parallel "
        "with Python and CrewAI."
    ),
    expected_output="A short list of patterns with practical notes.",
    agent=researcher,
)

validation_task = Task(
    description=(
        "Review common risks when running multiple AI agents in parallel, "
        "including rate limits, retries, and shared-state issues."
    ),
    expected_output="A risk checklist with mitigation advice.",
    agent=validator,
)

writing_task = Task(
    description=(
        "Draft a concise summary of how to structure parallel agent execution "
        "in a Python application."
    ),
    expected_output="A developer-friendly summary paragraph.",
    agent=writer,
)
  1. Run the tasks in separate threads so they execute at the same time. CrewAI itself executes tasks through crews; for true concurrency at the application level, use Python concurrency around independent crews.
from concurrent.futures import ThreadPoolExecutor
from crewai import Crew, Process

def run_crew(task):
    crew = Crew(
        agents=[task.agent],
        tasks=[task],
        process=Process.sequential,
        verbose=True,
    )
    return crew.kickoff()

tasks = [research_task, validation_task, writing_task]

with ThreadPoolExecutor(max_workers=3) as executor:
    futures = [executor.submit(run_crew, task) for task in tasks]
    results = [future.result() for future in futures]

for i, result in enumerate(results, start=1):
    print(f"\n--- Result {i} ---\n{result}")
  1. Merge the outputs after all workers finish. This keeps each agent isolated during execution and gives you one place to assemble the final answer.
combined_report = {
    "research": str(results[0]),
    "validation": str(results[1]),
    "writing": str(results[2]),
}

print("\n=== Combined Report ===")
for section, content in combined_report.items():
    print(f"\n[{section.upper()}]\n{content}")
  1. If you need a final synthesis step, pass the merged text into one last CrewAI task. This is where you turn parallel outputs into a single deliverable.
synthesizer = Agent(
    role="Synthesizer",
    goal="Combine independent findings into one actionable recommendation",
    backstory="You produce final answers from multiple technical inputs.",
)

synthesis_task = Task(
    description=(
        "Using these inputs:\n"
        f"Research: {combined_report['research']}\n\n"
        f"Validation: {combined_report['validation']}\n\n"
        f"Writing: {combined_report['writing']}\n\n"
        "Produce one final recommendation for implementing parallel agents in Python."
    ),
    expected_output="A single polished recommendation.",
    agent=synthesizer,
)

synthesis_crew = Crew(
    agents=[synthesizer],
    tasks=[synthesis_task],
    process=Process.sequential,
)

final_output = synthesis_crew.kickoff()
print("\n=== Final Output ===\n", final_output)

Testing It

Run the script once with verbose logging enabled and confirm that all three worker crews start without waiting on each other’s results. You should see overlapping execution behavior at the application level rather than a strict task chain.

Then add timestamps around each future.result() call or inside run_crew() to confirm wall-clock overlap. If your provider rate-limits requests heavily, reduce max_workers to 2 and verify that concurrency still works under load.

Also check that each output is logically independent: research should not mention validation details unless you intentionally merged them later. If one task fails while others succeed, handle exceptions per future so one bad agent does not kill the whole batch.

Next Steps

  • Add retry logic with exponential backoff around each worker crew
  • Replace plain threads with an async job queue if you need higher throughput
  • Introduce shared artifacts storage so parallel agents can write structured JSON instead of free text

Keep learning

By Cyprian Aarons, AI Consultant at Topiax.

Want the complete 8-step roadmap?

Grab the free AI Agent Starter Kit — architecture templates, compliance checklists, and a 7-email deep-dive course.

Get the Starter Kit

Related Guides