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

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

This tutorial shows you how to run multiple CrewAI agents in parallel from Python, then combine their outputs into a single result. You need this when one task can be split into independent sub-tasks, like researching vendors, summarizing policies, or comparing claims data without waiting for each agent to finish in sequence.

What You'll Need

  • Python 3.10 or newer
  • crewai installed
  • python-dotenv for loading API keys from .env
  • An OpenAI API key set as OPENAI_API_KEY
  • Basic familiarity with CrewAI agents, tasks, and crews
  • A terminal and a project folder

Install the packages:

pip install crewai python-dotenv

Step-by-Step

  1. Create a small project with two independent agents. The key idea is that each agent handles one task that does not depend on the other, so they can run in parallel without shared state.
from crewai import Agent, Task, Crew, Process
from dotenv import load_dotenv

load_dotenv()

researcher = Agent(
    role="Research Analyst",
    goal="Find concise facts about insurance operations",
    backstory="You are strong at extracting structured insights from business topics.",
    verbose=True,
)

writer = Agent(
    role="Policy Analyst",
    goal="Summarize operational implications clearly",
    backstory="You turn research into practical recommendations.",
    verbose=True,
)
  1. Define tasks that can be executed independently. Do not make task B depend on task A if you want true parallelism; keep the inputs separate and merge later in Python.
research_task = Task(
    description="List three common reasons insurance claims get delayed.",
    expected_output="A short bullet list with three reasons.",
    agent=researcher,
)

summary_task = Task(
    description="List three controls that reduce claims processing errors.",
    expected_output="A short bullet list with three controls.",
    agent=writer,
)
  1. Build the crew using Process.parallel. This tells CrewAI to execute eligible tasks at the same time instead of chaining them one after another.
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, summary_task],
    process=Process.parallel,
    verbose=True,
)
  1. Kick off the crew and capture both outputs. The result comes back as a combined object/string depending on your CrewAI version, so print it first and inspect the structure before wiring it into downstream code.
result = crew.kickoff()

print("\n=== RAW RESULT ===\n")
print(result)
  1. If you need a clean application-level output, wrap the crew call in a function and normalize the response. In production, this is where you map each task output into a dictionary for logging, storage, or an API response.
def run_parallel_workflow():
    result = crew.kickoff()
    return {
        "raw_result": str(result),
        "tasks": [
            "claims delay reasons",
            "error reduction controls",
        ],
    }

if __name__ == "__main__":
    output = run_parallel_workflow()
    print("\n=== NORMALIZED OUTPUT ===\n")
    print(output["raw_result"])

Testing It

Run the script from your terminal and watch the logs. With verbose=True, you should see both agents start without waiting for one another to finish first.

If one task depends on another, it will no longer be parallelizable, so keep the test tasks fully independent. A good sanity check is to compare runtime against a sequential version using Process.sequential; parallel execution should feel faster when both prompts are non-trivial.

Also verify that your OPENAI_API_KEY is loaded correctly from .env. If you get authentication errors, print os.getenv("OPENAI_API_KEY")[:6] in a local debug branch to confirm the variable is present without exposing the full key.

Next Steps

  • Learn how to use Task.output_pydantic for structured outputs instead of plain text.
  • Add a post-processing step that merges parallel results into one JSON payload.
  • Explore hierarchical crews when you need a manager agent to assign work dynamically rather than running fixed parallel tasks.

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