FromZero2AI
CoursesPlaygroundBlog
Support on Ko-fi
AI Agent Frameworks • Module B: Multi-Agent SystemsLesson 4: Multi-Agent Workflows with CrewAI
PreviousNext

Lesson 4: Multi-Agent Workflows with CrewAI

Define specialized Agent personas, assign Tasks, and wire them into a Crew. Build a researcher-writer-reviewer pipeline where agents hand off work and check each other's outputs.

Built with AI for beginners. Free forever.

Support on Ko-fi•About•Blog•Privacy Policy•Terms of Service

CrewAI structures multi-agent collaboration the way startups structure teams: each agent has a role, a specialization, and a defined responsibility. Agents delegate, share context, and produce outputs that downstream agents consume.

The CrewAI Mental Model

Three primitives:

  • Agent — an LLM with a role, tools, and a goal
  • Task — a unit of work assigned to an agent, with expected output
  • Crew — a team of agents executing tasks, sequentially or hierarchically
from crewai import Agent
from langchain_anthropic import ChatAnthropic

# Each agent has a role, goal, and backstory — these shape the system prompt
researcher = Agent(
    role="Senior Research Analyst",
    goal="Uncover cutting-edge developments in AI and technology",
    backstory="""You are a veteran tech researcher with 15 years of experience.
You excel at finding primary sources, verifying claims, and synthesizing complex information.""",
    llm=ChatAnthropic(model="claude-sonnet-4-6"),
    verbose=True,
    memory=True,        # Agent remembers past interactions
    max_iter=5,         # Max reasoning iterations before forced stop
)

writer = Agent(
    role="Tech Content Strategist",
    goal="Create compelling technical content for software engineers",
    backstory="""You turn dry technical research into engaging articles.
You write at a senior engineer level — precise, code-heavy, and no fluff.""",
    llm=ChatAnthropic(model="claude-haiku-4-5-20251001"),  # Cheaper for writing
    allow_delegation=False,   # This agent does not reassign tasks
)

reviewer = Agent(
    role="Senior Tech Editor",
    goal="Ensure accuracy and clarity of technical content",
    backstory="You are meticulous about technical accuracy and catch errors others miss.",
    llm=ChatAnthropic(model="claude-haiku-4-5-20251001"),
)

Sequential vs. Hierarchical Process

AspectSequentialHierarchical
Flow controlPredefined task orderManager LLM decides dynamically
PredictabilityHigh — same path every timeLower — manager may reorder or skip
CostLowerHigher (extra manager LLM calls)
Best forKnown, structured pipelinesOpen-ended research, unknown sub-tasks

Next, we look at the communication patterns between agents: how they hand off work, how errors propagate, and how to build agents that give up gracefully instead of looping forever.