Course Content
CrewAI Multi-Agents
9 sections · 53 lessons
How do you implement manager-worker patterns using CrewAI?
What you need to know
Option A: hierarchical crew
1manager = Agent(2 role="Research Director",3 goal="Get a correct, sourced answer by assigning the right specialist",4 backstory="You delegate every piece of work and reject answers without sources.",5 llm="openai/gpt-4o",6)7pricing = Agent(role="Pricing Analyst", goal="...", backstory="...",8 tools=[price_search], allow_delegation=False, max_iter=6)9regulation = Agent(role="Regulation Analyst", goal="...", backstory="...",10 tools=[law_search], allow_delegation=False, max_iter=6)1112crew = Crew(agents=[pricing, regulation],13 tasks=[Task(description="{question}",14 expected_output="An answer with sources")],15 process=Process.hierarchical,16 manager_agent=manager)The task has no agent, so the manager chooses. The manager has no tools; CrewAI adds the delegation tools itself.
Option B: explicit plan and dispatch
1from typing import Literal2from pydantic import BaseModel, Field3from crewai.flow.flow import Flow, start, listen45class Step(BaseModel):6 worker: Literal["pricing", "regulation"]7 question: str89class Plan(BaseModel):10 steps: list[Step] = Field(max_length=4)1112class ResearchFlow(Flow[ResearchState]):13 @start()14 def plan(self):15 out = PlannerCrew().crew().kickoff(inputs={"question": self.state.question})16 self.state.plan = out.pydantic # a Plan1718 @listen(plan)19 def run_steps(self):20 crews = {"pricing": PricingCrew, "regulation": RegulationCrew}21 for step in self.state.plan.steps:22 out = crews[step.worker]().crew().kickoff(inputs={"q": step.question})23 self.state.answers.append(out.raw)The planner still uses an LLM, but its output is a typed list with at most 4 steps, and Python does the dispatching. Each step can be retried, logged and costed on its own. (ResearchState is a Pydantic model with question, plan and answers fields; the crews are your own.)
Hierarchical crew
- Manager adapts during the run
- Fast to build
- Cost varies with the manager's choices
- Harder to test and replay
Plan plus Flow
- Plan is fixed once written
- More code to write
- Cost bounded by the plan length
- Each step testable and retryable
A real-life example
A consumer-goods company's strategy team asks open questions like "should we launch our energy drink in Kerala?". They use a hierarchical crew: a Research Director manager and four specialists (market size, pricing, regulation, distribution). Question shapes vary a lot, so run-time routing is worth the cost. A run costs between Rs 30 and Rs 110 and takes 2 to 6 minutes, which the team accepts.
The same company's weekly retailer price report had also started as a hierarchical crew. Its steps never change, and the variable cost annoyed finance. It became plan-plus-Flow with a fixed three-step plan — effectively sequential — costing a steady Rs 20 per report. Same framework, two patterns, chosen by how predictable the work is.
Follow-up questions to expect
- "Why must workers have delegation off?" — Otherwise workers can delegate back to each other or to the manager's other workers, creating loops and duplicated work.
- "Can the manager use tools?" — No; CrewAI raises an error if a custom manager has tools. Give tools to workers.
- "How do you cap cost in hierarchical mode?" — Low
max_iteron manager and workers,max_rpmon the crew,max_execution_time, and monitoringtoken_usageper run.