Skip to content

CrewAI — Multi-Agent AI Framework Guide

DodaTech Updated 2026-06-20 8 min read

In this tutorial, you'll learn about CrewAI. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

CrewAI is a Python framework for orchestrating multiple AI agents that work together on complex tasks, each with defined roles, goals, and tools, enabling collaborative LLM-powered automation.

What You'll Learn

  • How CrewAI's agent, task, and crew architecture works
  • Defining agents with specific roles, backstories, and LLM configurations
  • Creating workflows with sequential and hierarchical task execution
  • Using tools to give agents real-world capabilities like web search and file access

Why CrewAI Matters

Single LLM calls work for simple Q&A, but real-world tasks need coordination. A research task might need a researcher agent, a writer agent, and a reviewer agent working together. CrewAI provides the Orchestration layer for these multi-agent systems. By 2027, Gartner predicts 40% of enterprise AI deployments will use multi-agent architectures.

Doda Browser uses multi-agent patterns for parallel page analysis. Durga Antivirus Pro employs agent swarms for distributed threat detection.

Learning Path

flowchart LR
  A[OpenAI API] --> B[LangChain]
  B --> C[CrewAI<br/>You are here]
  C --> D[LlamaIndex]
  D --> E[Hugging Face]
  style C fill:#dbeafe,stroke:#2563eb

What Is CrewAI?

Think of CrewAI as a project manager for AI agents. You define a team of agents, each with a specific role (researcher, writer, coder, reviewer), give them tasks, and the framework handles who does what, in what order, and how they hand off results.

Core Concepts

Component Purpose Example
Agent An AI worker with a role, goal, and backstory ResearcherAgent — finds information
Task A Unit of Work assigned to an agent "Research the latest 5G standards"
Crew The team that executes tasks together Researcher + Writer + Reviewer
Process How the crew executes tasks Sequential, hierarchical
Tool External capabilities (search, file I/O) Web search tool, calculator
from crewai import Agent, Task, Crew, Process

# Define agents
researcher = Agent(
    role="Senior Research Analyst",
    goal="Find accurate and up-to-date information",
    backstory="Expert researcher with 15 years in technology analysis",
    verbose=True
)

writer = Agent(
    role="Technical Writer",
    goal="Create clear, engaging content from research",
    backstory="Former tech journalist specializing in AI",
    verbose=True
)

# Define tasks
research_task = Task(
    description="Research the latest developments in 5G-Advanced technology",
    expected_output="A detailed research brief with key findings",
    agent=researcher
)

write_task = Task(
    description="Write a blog post based on the research brief",
    expected_output="A complete blog post in markdown format",
    agent=writer
)

# Create the crew
crew = Crew(
    agents=[researcher, writer],
    tasks=[research_task, write_task],
    Process=Process.sequential
)

# Kick off
result = crew.kickoff()
print(result)

Expected output: A blog post about 5G-Advanced technology, researched by the analyst agent and written by the technical writer agent, produced sequentially.

Defining Agents in Depth

Each agent needs a clear role, goal, and backstory. These define its personality and behavior.

from crewai import Agent

support_agent = Agent(
    role="Customer Support Specialist",
    goal="Resolve customer issues quickly and empathetically",
    backstory="""You are a senior support specialist at DodaTech.
    You have deep knowledge of Doda Browser, DodaZIP, and Durga Antivirus Pro.
    You always explain solutions in simple terms and verify the customer
    understands before closing the ticket.""",
    allow_delegation=False,
    verbose=True,
    max_iter=5
)

technical_agent = Agent(
    role="Technical Support Engineer",
    goal="Diagnose and fix complex technical issues",
    backstory="""You handle escalated tickets that require code-level debugging.
    You can access logs, reproduce bugs, and provide patches.""",
    allow_delegation=True,
    verbose=False
)

Expected output: No output — agents are created as objects, ready to be assigned tasks.

Agent Configuration Options

Parameter Purpose Default
role Defines the agent's job function Required
goal What the agent aims to achieve Required
backstory Context that shapes behavior Required
allow_delegation Can this agent assign tasks? True
verbose Print detailed execution logs False
max_iter Maximum reasoning iterations 15
llm Custom LLM configuration Default GPT-4

Tools — Giving Agents Capabilities

Agents need tools to interact with the outside world. CrewAI supports built-in and custom tools:

from crewai_tools import SerperDevTool, ScrapeWebsiteTool, FileReadTool

# Create tools
search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()
file_tool = FileReadTool()

# Assign tools to agents
research_agent = Agent(
    role="Market Research Analyst",
    goal="Find current market data and competitor information",
    backstory="Expert market analyst specializing in tech industry trends",
    tools=[search_tool, scrape_tool],
    verbose=True
)

data_agent = Agent(
    role="Data Analyst",
    goal="Analyze existing datasets and extract insights",
    backstory="Data scientist with expertise in statistical analysis",
    tools=[file_tool],
    verbose=False
)

# Task that uses tools
research_task = Task(
    description="""Search for the latest market share data for web browsers in 2026.
    Then scrape the top 3 results for detailed numbers.""",
    expected_output="A summary table of browser market shares with sources",
    agent=research_agent
)

Expected output: The research agent calls SerperDevTool to search, then ScrapeWebsiteTool to extract data from the top results, producing a market share table.

Sequential vs Hierarchical Processes

Sequential Process

Tasks execute one after another. Output from one task feeds into the next. This is the simplest and most predictable workflow.

Researcher Task → Writer Task → Reviewer Task → Final Output
sequential_crew = Crew(
    agents=[researcher, writer, reviewer],
    tasks=[research_task, write_task, review_task],
    Process=Process.sequential
)

Hierarchical Process

A manager agent coordinates worker agents. The manager assigns tasks, reviews progress, and makes decisions about next steps.

manager = Agent(
    role="Project Manager",
    goal="Coordinate the team to produce high-quality output",
    backstory="Experienced PM with technical background in AI",
    allow_delegation=True
)

hierarchical_crew = Crew(
    agents=[manager, researcher, writer],
    tasks=[complex_project_task],
    Process=Process.hierarchical,
    manager_agent=manager
)

Which to use? Sequential for clear linear workflows. Hierarchical for complex tasks where an agent needs to dynamically decide what to do next.

Common Errors

1. Agents with Overlapping Roles

If two agents have similar goals and backstories, they produce redundant work. Each agent should have a distinct, non-overlapping responsibility.

2. Tasks Too Broad

A task like "research everything about AI" overwhelms the agent. Split into focused tasks: "research transformer architectures", "research training methods", "research deployment options."

3. Missing or Incorrect Tools

If an agent needs web search but doesn't have a search tool, it fabricates data. Always verify each agent has the tools required for its tasks.

4. Recursive Delegation Loops

Agents with allow_delegation=True can keep passing tasks in circles. Set max_iter to a reasonable limit (5-10) to prevent infinite loops.

5. Ignoring Token Limits

Multi-agent conversations consume significantly more tokens than single LLM calls. A single crew execution might use 50K-100K tokens. Monitor your token usage.

6. Not Setting Expected Output

Tasks without clear expected_output produce inconsistent results. Be specific: "A JSON array with 5 items, each containing name and description fields."

Practice Questions

  1. What are the three required parameters for a CrewAI agent?
    role, goal, and backstory — these define the agent's identity and behavior.

  2. What is the difference between sequential and hierarchical processes?
    Sequential executes tasks in a fixed order. Hierarchical uses a manager agent that dynamically assigns and coordinates tasks.

  3. Why do agents need tools?
    Agents can't access external data by default. Tools give them capabilities like web search, file reading, API calls, and database queries.

  4. What happens when allow_delegation is set to True?
    The agent can assign sub-tasks to other agents in the crew, enabling dynamic workflow management.

  5. How do you prevent agents from fabricating information?
    Provide the right tools (search, scrape) and set expected_output clearly. Use verbose=True during development to inspect reasoning.

Challenge: Build a three-agent crew that researches a new technology, writes a tutorial about it, and creates practice questions. The agents must pass their outputs sequentially, and each must validate the previous agent's work before proceeding.

Mini Project: Research and Content Crew

Build a crew that researches a topic and produces a structured report:

from crewai import Agent, Task, Crew, Process
from crewai_tools import SerperDevTool

search_tool = SerperDevTool()

researcher = Agent(
    role="Research Analyst",
    goal="Find comprehensive, accurate information",
    backstory="Veteran researcher with a talent for finding reliable sources",
    tools=[search_tool],
    verbose=True
)

analyst = Agent(
    role="Data Analyst",
    goal="Extract key insights and organize them",
    backstory="Data analyst who turns raw research into structured insights",
    verbose=True
)

writer = Agent(
    role="Report Writer",
    goal="Create a clear, well-structured report",
    backstory="Technical writer specializing in AI and technology reports",
    verbose=True
)

research = Task(
    description="Research the current State of open-source LLMs in 2026, including Llama 3, Mistral, and DeepSeek models",
    expected_output="A list of 5 key open-source LLMs with their specifications",
    agent=researcher
)

analyze = Task(
    description="Analyze the research and create a comparison table of the models",
    expected_output="A markdown comparison table with model name, parameters, and strengths",
    agent=analyst
)

write = Task(
    description="Write a 500-word report summarizing the State of open-source LLMs",
    expected_output="A complete report in markdown with introduction, comparison, and conclusion",
    agent=writer
)

crew = Crew(
    agents=[researcher, analyst, writer],
    tasks=[research, analyze, write],
    Process=Process.sequential
)

result = crew.kickoff()
print("Final Report:")
print(result)

Expected output: A complete research report on open-source LLMs, produced by three agents working sequentially. The researcher finds data, the analyst structures it, and the writer produces the final document.

Try it: Replace the research topic with your own area of interest. Add a reviewer agent that checks the report for accuracy before final output.

FAQ

{{< faq "How does CrewAI differ from LangChain?">}} LangChain provides low-level primitives for LLM chains, RAG, and tools. CrewAI is a higher-level framework focused specifically on multi-agent Orchestration — you define agents, tasks, and workflows, not individual chain steps. {{< /faq >}}

Can CrewAI agents use different LLM providers?

Yes. Each agent can be configured with a different LLM using the llm parameter. You can mix GPT-4, Claude, local models, or any provider supported by LangChain's model interface.

What happens if an agent fails a task?

By default, the crew raises an exception. You can set max_retry_on_fail in the task to automatically retry. For production, implement error handling and fallback agents.

How do I save a crew's output?

Use crew.kickoff() which returns the final output as a string. You can also access task.output for individual task results. Save to files, databases, or pass to downstream systems.

What are the token costs of multi-agent systems?

Each agent's reasoning steps consume tokens independently. A typical 3-agent crew might use 3-5x more tokens than a single LLM call. Use verbose=True during development to monitor token consumption


Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro