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.
Three primitives:
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"),
)| 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.