CrewAI Fundamentals
From the course CrewAI: Multi-Agent Frameworks
What Is CrewAI?
CrewAI is a Python framework for orchestrating multiple AI agents that work together on complex tasks, each with specialized roles, goals, and tools.
Core Concepts
- Agent: An autonomous unit with a role, goal, backstory, and tools
- Task: A specific piece of work assigned to an agent
- Crew: A team of agents working together on related tasks
- Tool: Functions that agents can use (web search, file I/O, APIs)
- Process: How tasks are executed (sequential or hierarchical)
Installation
pip install crewai crewai-tools
Your First Crew
from crewai import Agent, Task, Crew
researcher = Agent(
role="Senior Research Analyst",
goal="Find comprehensive information about AI trends in 2026",
backstory="You are an expert analyst who excels at finding and synthesizing information.",
verbose=True,
)
writer = Agent(
role="Content Writer",
goal="Write engaging articles based on research findings",
backstory="You are a skilled writer who transforms complex topics into accessible content.",
verbose=True,
)
research_task = Task(
description="Research the top 5 AI trends for 2026 with supporting data.",
expected_output="A detailed report with statistics and sources.",
agent=researcher,
)
writing_task = Task(
description="Write a blog post based on the research findings.",
expected_output="A 1000-word blog post with headers and examples.",
agent=writer,
)
crew = Crew(
agents=[researcher, writer],
tasks=[research_task, writing_task],
verbose=True,
)
result = crew.kickoff()
Common Pitfall: Verbose Backstories That Confuse Agent Behavior
An agent's backstory influences behavior but should not contain contradictory instructions. Avoid combining "you are an expert researcher" with "you sometimes make mistakes to test the team" in the same backstory — this confuses the underlying LLM. Keep backstories focused on expertise and communication style, and put behavioral constraints in the task description instead.
Best Practice: Set Expected Output Format in Tasks
The expected_output field in a Task is read by the agent as a constraint on its response format. Be specific about the format required:
research_task = Task(
description="Research the top 5 AI trends for 2026.",
expected_output="""A markdown-formatted report with:
- An executive summary (50 words)
- 5 numbered trends, each with: name, 2-sentence description, supporting statistic
- A list of 3 credible sources with URLs""",
agent=researcher,
)
Specific expected output descriptions reduce hallucination rates and improve the consistency of outputs across runs.
Named Product Reference: SerperDev for Web Search in CrewAI
The SerperDevTool from crewai-tools uses the Serper.dev API to give agents access to Google Search results. Serper offers 2,500 free searches per month — sufficient for prototyping. For production, the paid tier supports custom search parameters like date ranges, country filtering, and news-specific queries that make research agents significantly more targeted and useful.
Key Takeaways
- •CrewAI orchestrates multiple specialized AI agents
- •Agents have roles, goals, and backstories that guide behavior
- •Tasks define specific work with expected outputs
- •Crews coordinate agents and tasks into collaborative workflows
Progress is kept in this browser only.