█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/AI Agents/Code-First Agents/CrewAI: Multi-Agent Teams with Roles and Tasks
70 minIntermediate

CrewAI: Multi-Agent Teams with Roles and Tasks

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.

Prerequisites:LlamaIndex: RAG Pipelines and Data Agents

Install + setup

  1. 1

    1. `pip install crewai crewai-tools`

  2. 2

    2. Set ANTHROPIC_API_KEY (or OPENAI_API_KEY).

A 3-agent research crew

Researcher → Writer → Reviewer.

python
from crewai import Agent, Task, Crew, Process
from crewai.llm import LLM
from crewai_tools import SerperDevTool
llm = 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)

💡 Process.sequential vs Process.hierarchical

Sequential, agents run in order, each gets the previous task's output. Hierarchical, a manager LLM decides which agent runs next based on state. More flexible, more expensive. Start sequential; switch only if you need dynamic routing.

When CrewAI shines

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.

When NOT to use CrewAI

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.

Sign in to purchase
←LlamaIndex: RAG Pipelines and Data Agents
Back to Code-First Agents
Raw SDK: Anthropic and OpenAI APIs from Scratch→