Building Multi-Agent Systems with CrewAI and Python

By · · AI Engineering

The idea of a single AI model doing everything is quickly giving way to teams of AI agents working together, each with a specialized role. This is the core idea behind multi-agent systems, and CrewAI makes building them in Python pretty simple.

CrewAI, which picked up a lot of users since its release in late 2023, gives you a clean abstraction for multi-agent orchestration. Instead of wrestling with low-level prompt chaining or complex state management, you define agents with roles, assign them tasks, and organize them into a crew that collaborates to produce results. I will walk through the core concepts and build a working multi-agent system from scratch.

Why multi-agent systems?

Traditional single-agent approaches hit limitations quickly. A single LLM prompt trying to research a topic, analyze data, and write a report will often produce shallow results. By decomposing work across specialized agents, each one can focus on what it does best, much like a real team of professionals.

Multi-agent architectures offer several advantages:

Getting started with CrewAI

First, install CrewAI and its dependencies:

pip install crewai crewai-tools langchain-openai

You will also need an OpenAI API key (or another supported LLM provider) set as an environment variable:

export OPENAI_API_KEY="your-api-key-here"

Core concepts

CrewAI is built around three fundamental primitives: Agents, Tasks, and Crews.

Agents

An agent is defined by its role, goal, and backstory. These aren't just labels; they directly influence how the LLM behaves when acting as that agent.

from crewai import Agent

researcher = Agent(
    role="Senior Research Analyst",
    goal="Discover and summarize the latest trends in renewable energy technology",
    backstory=(
        "You are a seasoned research analyst with 15 years of experience "
        "in energy markets. You excel at finding credible sources, identifying "
        "emerging patterns, and distilling complex technical information into "
        "clear, actionable insights."
    ),
    verbose=True,
    allow_delegation=False,
)

writer = Agent(
    role="Technical Content Writer",
    goal="Write an engaging, well-structured article based on research findings",
    backstory=(
        "You are a skilled technical writer who specializes in making complex "
        "topics accessible to a broad audience. You focus on clarity, logical "
        "flow, and supporting claims with evidence."
    ),
    verbose=True,
    allow_delegation=False,
)

The allow_delegation parameter controls whether an agent can hand off work to other agents in the crew. Setting it to False ensures each agent completes its own assigned task.

Tasks

Tasks define the specific work an agent must perform. Each task has a description, an expected output, and is assigned to an agent.

from crewai import Task

research_task = Task(
    description=(
        "Conduct thorough research on the latest developments in renewable "
        "energy technology for 2024. Focus on solar, wind, and battery storage "
        "innovations. Identify at least 5 significant trends with supporting "
        "data points and sources."
    ),
    expected_output=(
        "A detailed research brief with 5 or more trends, each including "
        "a description, key statistics, and source references."
    ),
    agent=researcher,
)

writing_task = Task(
    description=(
        "Using the research findings provided, write a comprehensive article "
        "about renewable energy trends in 2024. The article should be engaging, "
        "well-organized with clear sections, and approximately 800 words."
    ),
    expected_output=(
        "A polished article in markdown format with an introduction, "
        "sections for each major trend, and a conclusion."
    ),
    agent=writer,
)

Crews

A crew brings agents and tasks together, defining the execution strategy. CrewAI supports sequential and hierarchical process types.

from crewai import Crew, Process

crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, writing_task],
    process=Process.sequential,
    verbose=True,
)

result = crew.kickoff()
print(result)

In a sequential process, tasks execute one after another. The output of the research task automatically becomes context for the writing task. The writer agent receives the researcher's findings and builds on them.

Adding tools for real-world capability

Agents become much more useful when you give them tools. CrewAI integrates with a variety of tool providers:

from crewai_tools import SerperDevTool, WebsiteSearchTool

search_tool = SerperDevTool()
web_tool = WebsiteSearchTool()

researcher_with_tools = Agent(
    role="Senior Research Analyst",
    goal="Discover the latest trends in renewable energy technology",
    backstory=(
        "You are a seasoned research analyst with deep expertise in energy "
        "markets. You always verify information from multiple sources."
    ),
    tools=[search_tool, web_tool],
    verbose=True,
    allow_delegation=False,
)

With these tools, the researcher agent can perform live web searches and scrape specific websites, grounding its analysis in real, current data rather than relying solely on the LLM's training data.

A more complex example: three-agent content pipeline

Let us build a more realistic pipeline with a reviewer agent that provides quality assurance:

from crewai import Agent, Task, Crew, Process

researcher = Agent(
    role="Research Specialist",
    goal="Gather comprehensive, accurate information on the given topic",
    backstory="Expert researcher who values accuracy and thoroughness.",
    verbose=True,
)

writer = Agent(
    role="Content Writer",
    goal="Produce clear, engaging content based on research",
    backstory="Experienced writer who excels at making technical topics accessible.",
    verbose=True,
)

reviewer = Agent(
    role="Editorial Reviewer",
    goal="Review content for accuracy, clarity, and completeness",
    backstory=(
        "Meticulous editor with a sharp eye for factual errors, logical gaps, "
        "and unclear language. You provide specific, actionable feedback."
    ),
    verbose=True,
)

research_task = Task(
    description="Research the current state of quantum computing applications in finance.",
    expected_output="A structured research brief with key findings and data points.",
    agent=researcher,
)

writing_task = Task(
    description="Write an article based on the research findings.",
    expected_output="A well-structured article of approximately 800 words in markdown.",
    agent=writer,
)

review_task = Task(
    description=(
        "Review the article for accuracy, clarity, and completeness. "
        "Provide a final corrected version with any necessary improvements."
    ),
    expected_output="A final, polished version of the article ready for publication.",
    agent=reviewer,
)

content_crew = Crew(
    agents=[researcher, writer, reviewer],
    tasks=[research_task, writing_task, review_task],
    process=Process.sequential,
    verbose=True,
)

final_output = content_crew.kickoff()
print(final_output)

Each agent builds on the previous one's output, creating a pipeline that mirrors how real editorial teams operate. The reviewer catches issues the writer might have missed and produces a refined final version.

Configuration tips

A few practical tips from my experience working with CrewAI:

When to use CrewAI

CrewAI works well when you need structured collaboration between specialized agents: content generation pipelines, research and analysis workflows, code review systems, and data processing chains. It is less suited for real-time interactive applications or cases where you need fine-grained control over individual LLM calls.

Conclusion

CrewAI gives you a clean model for multi-agent systems. By thinking in terms of roles, tasks, and crews, you can build AI workflows that are easy to understand and extend. The framework handles the orchestration logic (prompt chaining, context passing, output management) so you can focus on designing the right team of agents for your problem. If you have been building single-agent applications and hitting their limits, CrewAI is a natural next step.