Hey Antonio! Yeah, the hierarchical process and delegation in CrewAI definitely seem a bit tricky, judging by how often it pops up here in the forum. So, I’ll take your question as a chance to throw in my two cents (okay, maybe more like twenty cents!) about some details on how the hierarchical process works in CrewAI. Bear with me, and I promise I’ll get to your specific question.
Right, so that tool does exist, but you aren’t the one who creates it. Let’s walk through how a hierarchical process gets set up:
Crew(process=Process.hierarchical)
: This is the magic switch that turns on the hierarchical logic.- Then, choose your Manager: You’ve got two options here. Either CrewAI gives you a default manager agent, or you provide your own custom one. You can only pick one of these:
manager_llm=<YOUR_LLM_INSTANCE>
: CrewAI whips up a default manager agent for you (using the role/goal/backstory found increwai/translations/en.json
), then calls the internal_create_manager_agent
method to get it ready. It’s like the classic “If you cannot afford a lawyer, one will be appointed for you.” Great.manager_agent=<YOUR_CUSTOM_MANAGER_AGENT>
: Here, you define your own managerAgent
instance with its specific role, goal, backstory, and crucially,allow_delegation=True
. Basically, “I can afford my own lawyer!”
agents=[agent_1, agent_2, ...]
: This list should only contain the agents who will actually do the work delegated by the manager. Please, do not include your manager agent in this list.tasks=[task_1, task_2, ...]
: These are the high-level goals your Crew needs to tackle. In the hierarchical process, the manager figures out which worker agent gets which task (or a sub-task derived from the main one). Things are starting to click, right? Please tell me they are!- Then CrewAI does a crucial step behind the scenes when setting up task execution (check out the
_prepare_tools
and_update_manager_tools
methods):- It automatically creates instances of
DelegateWorkTool
andAskQuestionTool
. (Hey Antonio, see where that tool from your error message comes from now?) - The descriptions for these tools are generated on the fly (again, take a look at
crewai/translations/en.json
) to list the available worker agents (e.g., “Delegate a specific task to one of the following coworkers: Researcher, Writer, etc.”). - It injects these two tools into the list of tools available exclusively to the manager agent for that specific task execution cycle. This is why you don’t define these tools yourself – they’re built into the hierarchical mechanism.
- It automatically creates instances of
- When the manager agent decides it’s time to delegate (because its LLM generates an action to use the
Delegate work to coworker
tool), a temporaryTask
gets created, and the system looks for the specified agent (coworker
) to handle it. - The manager agent gets the result back and continues its thought process – maybe delegating more tasks, asking questions (remember that other secret tool it gets?), or eventually putting together the final answer for the original Crew task.
See how it’s a process where lots of gears need to mesh perfectly, and the whole coordination needs to run smoothly? This level of complexity should be something the project demonstrates is worth the risk. As I mentioned in another reply, this behavior is truly agentic and has stochastic characteristics – meaning it’s much more probabilistic than deterministic, you know? Often, that’s the opposite of what you need to solve the problem at hand. Many times, a clear, well-defined process yields a much more predictable (deterministic) result, and it’s up to you to weigh what’s best for your actual use case.
In terms of implementation, I invite you to check out this other thread where I tackled the same topic but provided two functional code examples: a traditional version (using Process.hierarchical
) and an approach using Flow
that gives you more control over the process.
Hope I’ve been clear enough to make things less confusing. Good luck!