A manager for the crew
In a hierarchical crew, tasks have no assigned agent. CrewAI creates a manager agent from manager_llm, and the manager delegates each task to the crew's agents.
Lesson 18 made one agent a delegator. Process.hierarchical adds a separate manager on top of the crew instead, so no worker has to be one.
from crewai import Agent, Crew, Task
from shop_llm import ShopLLM
from tools import lookup_order
clerk = Agent(role="Order clerk", goal="Find the status of customers' orders",
backstory="You can look up any order in the shop's system.",
llm=ShopLLM(model="shop"), tools=[lookup_order])
writer = Agent(role="Reply writer", goal="Write replies to customers",
backstory="You write short, friendly emails.",
llm=ShopLLM(model="shop"))from crewai import Process, Task
from desk_manager import ManagerLLM
task = Task(description="Answer the customer: {question}", expected_output="One sentence.")
crew = Crew(agents=[clerk, writer], tasks=[task], process=Process.hierarchical,
manager_llm=ManagerLLM(model="shop"))
print(crew.kickoff(inputs={"question": "Where is my order A17?"}).raw)The task names no agent. CrewAI built a manager called Crew Manager, gave it lesson 18's ManagerLLM and the two coworker tools, and the manager sent the job to the clerk. The workers need no allow_delegation.
from crewai import Process, Task
task = Task(description="Answer the customer: {question}", expected_output="One sentence.")
Crew(agents=[clerk, writer], tasks=[task], process=Process.hierarchical)Without manager_llm or manager_agent the crew is refused when it is built. manager_agent takes an Agent you configure yourself, with its own role and backstory.
The manager decides who does what, so every task costs at least two models' work. When the order of work is known, as it is for this desk, a sequential crew does the same job without the manager's calls.
- Add a second task and see whether the manager delegates it too.
- Print the manager's role from
result.tasks_output[0].agent. - Pass a
manager_agentwithllm=ManagerLLM(model="shop")instead ofmanager_llm.
This is what real progress feels like.