After this lesson, you will be able to: Define specialised agent roles, assign tasks, and orchestrate a CrewAI crew that collaborates to complete a research workflow.
CrewAI is the Python answer to multi-agent teams. You define agents (with roles, goals, backstories), tasks (with descriptions and expected outputs), and a crew that runs them. This lesson builds a 3-agent research crew that researches, drafts, and reviews, fully in code.
1. `pip install crewai crewai-tools`
2. Set ANTHROPIC_API_KEY (or OPENAI_API_KEY).
Researcher → Writer → Reviewer.
from crewai import Agent, Task, Crew, Processfrom crewai.llm import LLMfrom crewai_tools import SerperDevToolllm = LLM(model='anthropic/claude-sonnet-4-6')search_tool = SerperDevTool() # needs SERPER_API_KEY (free at serper.dev)researcher = Agent(role='Senior Research Analyst',goal='Find accurate, current facts about a topic',backstory='You are obsessive about citations and primary sources.',tools=[search_tool], llm=llm, verbose=True,)writer = Agent(role='Tech Writer',goal='Turn research into a clear 400-word piece',backstory='You write for smart non-experts.',llm=llm, verbose=True,)reviewer = Agent(role='Editor',goal='Catch factual errors, vague claims, and tone issues',backstory='Brutal but fair.',llm=llm, verbose=True,)research_task = Task(description='Research: {topic}', expected_output='5 cited bullet points', agent=researcher)write_task = Task(description='Draft a 400-word post.', expected_output='Markdown post', agent=writer, context=[research_task])review_task = Task(description='Review the draft, return the final.', expected_output='Polished markdown', agent=reviewer, context=[write_task])crew = Crew(agents=[researcher, writer, reviewer], tasks=[research_task, write_task, review_task], process=Process.sequential, verbose=True)result = crew.kickoff(inputs={'topic': 'state of AI agent frameworks in 2026'})print(result)
When the workflow is naturally team-shaped (research-write-review, plan-build-test, scout-analyze-decide). When prompts get unwieldy in a single agent. When you want auditability per role.
Single-step tasks. Latency-sensitive flows (each agent = 1+ LLM calls = compounding latency). Strict cost budgets. Use a single tightly-prompted agent with tools instead.
Sign in and purchase access to unlock this lesson.