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.
By Bishwambhar Sen • Last updated • 80 min
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
| Aspect | Sequential | Hierarchical |
|---|---|---|
| Flow control | Predefined task order | Manager LLM decides dynamically |
| Predictability | High — same path every time | Lower — manager may reorder or skip |
| Cost | Lower | Higher (extra manager LLM calls) |
| Best for | Known, structured pipelines | Open-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.