Run This Ai
EN DE

Building Your First AI Agent Team with CrewAI — Tutorial

Step-by-step tutorial to build a multi-agent research team with CrewAI including Researcher, Writer, and Editor agents.

CrewAI

Building Your First AI Agent Team with CrewAI

In this tutorial, you will build a multi-agent research team using CrewAI. By the end, you will have a working crew of three agents — a Researcher, a Writer, and an Editor — collaborating to produce a well-researched article on any topic.

Prerequisites

Before you start, make sure you have Python 3.10+ installed. CrewAI works with any LLM provider including OpenAI, Anthropic, and Ollama.

pip install crewai crewai-tools

Step 1: Define Your Agents

In CrewAI, every agent has a role, a goal, and a backstory. These attributes guide the agent behavior and communication style.

from crewai import Agent

researcher = Agent(
    role="Senior Research Analyst",
    goal="Uncover cutting-edge developments in AI",
    backstory="You are an expert analyst with 15 years of experience...",
    allow_delegation=False,
    verbose=True
)

writer = Agent(
    role="Technical Writer",
    goal="Craft compelling articles from research findings",
    backstory="You are a skilled writer who transforms complex ideas...",
    allow_delegation=True,
    verbose=True
)

editor = Agent(
    role="Editor-in-Chief",
    goal="Ensure the final article meets publication standards",
    backstory="You are a meticulous editor with an eye for detail...",
    allow_delegation=False,
    verbose=True
)
CrewAI Studio

Step 2: Define Tasks

Tasks describe what each agent should do. Each task has a description, an expected output, and an assigned agent:

from crewai import Task

research_task = Task(
    description="Research the latest trends in AI agents",
    expected_output="A detailed bullet-point report with sources",
    agent=researcher
)

writing_task = Task(
    description="Write a 500-word article from the research",
    expected_output="A polished draft article ready for review",
    agent=writer
)

editing_task = Task(
    description="Review and polish the draft article",
    expected_output="A publication-ready article with corrections",
    agent=editor
)

Step 3: Create the Crew and Run It

Now bring everything together. The crew defines the agents, tasks, and execution process:

from crewai import Crew

crew = Crew(
    agents=[researcher, writer, editor],
    tasks=[research_task, writing_task, editing_task],
    verbose=True,
    process="sequential"
)

result = crew.kickoff()
print(result)

CrewAI handles all the coordination — passing results between agents, managing context, and ensuring each task completes before the next one starts.

Step 4: Add Tools for Real-World Power

Give your researcher web search capability:

from crewai_tools import SerperDevTool, ScrapeWebsiteTool

search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()

researcher_with_tools = Agent(
    role="Senior Research Analyst",
    goal="Uncover cutting-edge developments in AI",
    backstory="You are an expert analyst...",
    tools=[search_tool, scrape_tool],
    allow_delegation=False
)

Now your researcher can browse the web, gather real-time information, and pass structured research to the writer agent.

Tips for Production

Use Ollama or a local LLM to keep costs down during development. Use human-in-the-loop approval gates for critical decisions. Set max_iterations to prevent runaway agent loops, and always log agent interactions for debugging.

Conclusion

CrewAI makes multi-agent development accessible and practical. In just a few lines of Python, you can build sophisticated agent teams that research, write, edit, and produce results autonomously. Start building your first crew today!

#crewai #tutorial #multi-agent #python #ai-agents