How to Define Specialized AI Agents and Build a Multi-Agent Crew Using CrewAI
The power of CrewAI comes from its multi-agent architecture — specialized agents with distinct roles collaborating on complex tasks. This tutorial walks you through defining agents, assigning tools, creating tasks, and orchestrating a complete crew from scratch using CrewAI’s Python framework.
Step 1: Install CrewAI
Open your terminal and run: pip install crewai crewai-tools. This installs the core framework and the standard tool library. Verify installation with: python -c "import crewai; print(crewai.__version__)".
Step 2: Define Your Agents
Create a new Python file content_crew.py. Define agents with roles, goals, and backstories:
from crewai import Agent
researcher = Agent(
role="Senior Market Researcher",
goal="Discover emerging trends and gather data-driven insights about the target topic",
backstory="You are an experienced researcher with 15 years in market analysis. You prioritize data accuracy, cite sources, and identify patterns that others miss. You never make claims without evidence.",
verbose=True
)
writer = Agent(
role="Expert Content Writer",
goal="Transform research insights into compelling, SEO-optimized blog articles",
backstory="You are a seasoned content writer who specializes in turning complex information into engaging narratives. You write with clarity, incorporate keywords naturally, and always structure content for reader comprehension.",
verbose=True
)
editor = Agent(
role="Senior Content Editor",
goal="Review and polish content for brand alignment, accuracy, and publication readiness",
backstory="You are a meticulous editor who ensures every article meets quality standards. You check facts, improve flow, eliminate jargon, and verify SEO compliance before approving content for publication.",
verbose=True
)
Step 3: Assign Tools to Agents
Give each agent the tools they need to execute their role:
from crewai_tools import SerperDevTool, ScrapeWebsiteTool, FileWriterTool
researcher.tools = [SerperDevTool(), ScrapeWebsiteTool()]
writer.tools = [FileWriterTool()]
The researcher can search the web and scrape websites for data. The writer can save content to files. The editor doesn’t need external tools — their expertise is applied through reasoning.
Step 4: Define Tasks with Dependencies
Create tasks that chain through the crew:
from crewai import Task
research_task = Task(
description="Research emerging AI tools trends for 2026. Identify the top 5 trends with data points, source citations, and competitive analysis.",
expected_output="A structured research report with 5 trends, each containing: trend name, supporting data, source citations, and competitive implications.",
agent=researcher
)
writing_task = Task(
description="Using the research report, write a 1500-word SEO-optimized blog article about emerging AI tools trends for 2026. Include headers, keyword-rich paragraphs, and a compelling introduction.",
expected_output="A complete blog article in markdown format, ready for editorial review.",
agent=writer,
context=[research_task] # Writer receives researcher's output
)
editing_task = Task(
description="Review the blog article for factual accuracy, brand voice alignment, SEO compliance, and readability. Suggest improvements and produce the final publication-ready version.",
expected_output="A polished, publication-ready blog article with all corrections applied and quality verified.",
agent=editor,
context=[writing_task] # Editor receives writer's output
)
Step 5: Assemble and Run the Crew
Create the crew and execute the workflow:
from crewai import Crew, Process
content_crew = Crew(
agents=[researcher, writer, editor],
tasks=[research_task, writing_task, editing_task],
process=Process.sequential # Tasks run in order: research → write → edit
)
result = content_crew.kickoff()
print(result)
The crew runs sequentially — the researcher produces findings, the writer transforms them into an article, and the editor polishes it. Each agent receives the previous agent’s output through the context parameter.
Step 6: Add Human Input Gates
For business-critical workflows, insert human approval steps:
editing_task = Task(
description="Review the blog article...",
expected_output="...",
agent=editor,
context=[writing_task],
human_input=True # Pause for human review before proceeding
)
When human_input=True, CrewAI pauses execution and presents the agent’s output for your review. You can approve, modify, or redirect the agent before the workflow continues.
Step 7: Monitor Execution Logs
CrewAI provides detailed execution logs showing each agent’s reasoning process, tool calls, and inter-agent communication. Set verbose=True on agents and tasks to see these logs in your terminal. They reveal how agents decompose problems, which tools they invoke, and how they evaluate each other’s output — valuable for debugging and improving crew configurations.
