Back to Blog
CrewAI AI Agents Python November 15, 2024

Multi-Agent AI Systems with CrewAI: Teams Instead of Solo Players

How to orchestrate specialized AI agents that collaborate like a real team. A practical guide with code examples.

A single AI agent can accomplish impressive things. But for complex, multi-step tasks, it quickly reaches its limits. The solution? Multiple specialized agents that work together like a real team.

CrewAI is a Python framework that enables exactly that: orchestrating AI agents into a crew where each agent takes on a specific role.

The Concept: Think Like a Manager

CrewAI is based on a simple idea: Instead of building one agent that can do everything, assemble a team. The questions you should ask yourself:

  1. What is the goal? What should be achieved in the end?
  2. What steps are needed? Which subtasks lead to the goal?
  3. Who can do it best? Which specialists do you need?

Just like a manager assembling a team, you define roles, responsibilities, and workflows.

The Three Core Concepts

1. Agents: The Specialists

Each agent has a specific role, a goal, and a backstory. The more precisely you define these, the better the results.

from crewai import Agent

content_planner = Agent(
    role="Content Strategist",
    goal="Research topics and create article structures",
    backstory="""You are an experienced content strategist with
    10 years of experience in tech journalism. You know
    how to structure complex topics and
    captivate readers.""",
    tools=[search_tool, scrape_tool],
    allow_delegation=False
)

Best Practice: Specific Roles

Instead of "Researcher," use "FINRA-certified financial analyst" or "HR specialist focused on German labor law." The more specific the role, the more focused the agent works.

2. Tasks: The Assignments

Tasks define what needs to be done. Each task has a description, expected output, and an assigned agent.

from crewai import Task

plan_task = Task(
    description="""Research the topic {topic} and create
    a detailed article plan with:
    - Key theses
    - Structure with headings
    - Important points per section""",
    expected_output="Markdown document with article structure",
    agent=content_planner
)

3. Crew: The Team

The crew brings agents and tasks together and defines how they collaborate.

from crewai import Crew, Process

crew = Crew(
    agents=[planner, writer, editor],
    tasks=[plan_task, write_task, edit_task],
    process=Process.sequential,
    verbose=True
)

result = crew.kickoff(inputs={"topic": "AI in Healthcare"})

Practical Example: Content Creation

A classic use case: automated blog articles. Three agents work together:

Content Strategist

Researches the topic, identifies key points, creates the article structure

Content Writer

Writes the article based on the plan, focuses on style and readability

Editor

Checks for errors, improves phrasing, ensures brand consistency

The crucial point: Each agent receives the output of the previous agent as context. The writer sees the strategist's plan. The editor sees the finished article. This creates a natural workflow.

Sequential vs. Hierarchical

CrewAI supports two process types:

Sequential Process

Tasks are processed one after another. Agent A delivers to Agent B, who delivers to Agent C. Ideal for linear workflows like content creation or data processing.

crew = Crew(
    process=Process.sequential,
    ...
)

Hierarchical Process

A manager LLM coordinates the agents dynamically. It decides on its own which agent to deploy and when. Ideal for complex tasks with dependencies.

from langchain_openai import ChatOpenAI

crew = Crew(
    process=Process.hierarchical,
    manager_llm=ChatOpenAI(model="gpt-4-turbo"),
    ...
)

Tools: The Agents' Toolbox

Agents become powerful through their tools. CrewAI offers built-in tools and allows custom ones:

from crewai_tools import SerperDevTool, ScrapeWebsiteTool

# Built-in tools
search_tool = SerperDevTool()  # Web search
scrape_tool = ScrapeWebsiteTool()  # Extract website content

# Custom Tool
from crewai_tools import BaseTool

class SentimentTool(BaseTool):
    name = "Sentiment Analysis"
    description = "Analyzes the sentiment of a text"

    def _run(self, text: str) -> str:
        # Implementation here
        return "positive"

Tool Design Principles

Tools should be versatile (covering multiple scenarios), fault-tolerant (handling errors gracefully), and efficient (caching for repeated calls).

Real-World Use Cases

Multi-agent systems are particularly well-suited for tasks that require different perspectives or expertise:

Sales Automation

Lead research, profile analysis, personalized email campaigns

Financial Analysis

Collecting market data, developing strategy, assessing risk

Customer Support

Ticket analysis, solution proposals, quality control

Event Planning

Venue coordination, logistics, marketing

Structured Outputs with Pydantic

For consistent results, you can define the output format with Pydantic:

from pydantic import BaseModel

class ArticlePlan(BaseModel):
    title: str
    summary: str
    sections: list[str]
    target_audience: str

plan_task = Task(
    description="Create an article plan...",
    output_json=ArticlePlan,
    output_file="./output/plan.json",
    agent=planner
)

Key Learnings

"A well-assembled agent team significantly outperforms a single 'super agent' on complex tasks."

1. Define Specific Roles

Generic roles like "Researcher" lead to generic results. "Senior Financial Analyst focused on tech startups" delivers significantly better outputs.

2. Clearly Delineate Tasks

Each task should have a clear goal and a defined output. Overlaps lead to duplicates and inconsistencies.

3. Assign Tools Deliberately

Not every agent needs all tools. An editor doesn't need web search. A researcher doesn't need file writing. Less is often more.

4. Plan for Iteration

Multi-agent systems require tuning. Start with a simple setup and expand gradually based on the results.

Conclusion

CrewAI makes it easy to transition from individual agents to collaborative teams. The key lies in carefully defining roles, tasks, and workflows. Think like a manager assembling a team, and you will build AI systems that reliably solve complex tasks.


Tools used:

CrewAI DeepLearning.AI

Planning a multi-agent system? Get in touch, I'm happy to help with architecture and implementation.