crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
18.45k stars 2.54k forks source link

Unexpected Exception: Manager agent should not have tools #909

Open leungmanhin opened 1 month ago

leungmanhin commented 1 month ago

I'm using the latest version of crewai and crewai-tools in a Colab notebook, and my manager agent do not have tools, in fact none of my agents have. The exact same code can run successfully without this exception and then fail with it in the next run, and I'll have to re-create my crew in order to successfully run the same code again. It feels like sometimes somehow a tool got equipped to my manager agent during kickoff()?

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
[<ipython-input-13-1d2bf6638f8c>](https://localhost:8080/#) in <cell line: 3>()
      2 
----> 3 discuss_result = discuss_crew.kickoff(
      4     inputs = {
      5         "test_case": test_case

[/usr/local/lib/python3.10/dist-packages/crewai/crew.py](https://localhost:8080/#) in _run_hierarchical_process(self)
    471             manager = self.manager_agent
    472             if manager.tools is not None and len(manager.tools) > 0:
--> 473                 raise Exception("Manager agent should not have tools")
    474             manager.tools = self.manager_agent.get_delegation_tools(self.agents)
    475         else:

Exception: Manager agent should not have tools
santana-ai commented 1 month ago

Hey, I had the same issue when running kickoff() method for the same crew in a loop. I fixed locally by removing the validation of the tools equipped to the manager agent. In the lib, file crewai/crew.py I commented out the two lines that appears in your error message.

    472         # if manager.tools is not None and len(manager.tools) > 0:
    473         #       raise Exception("Manager agent should not have tools")

The other way I prevented this was recreating crew inside the loop instead of reusing same object, as you said. But I think the problem is here:

    474         manager.tools = self.manager_agent.get_delegation_tools(self.agents)

I don't know why it equips the tools to the manager if it will validate later on.

jakeazcona commented 3 weeks ago

Hi, I ran into this same issue. However, in my case I was trying to equip my manager agent with tools. Is that not allowed? and why would it not be okay for a manager agent to use tools just like other agents?

The other problem I have is following what @santana-ai mentioned:

The other way I prevented this was recreating crew inside the loop instead of reusing same object, as you said. But I think the problem is here: 474 manager.tools = self.manager_agent.get_delegation_tools(self.agents) I don't know why it equips the tools to the manager if it will validate later on.

What is the point of the manager agent who in theory delegates tasks to other agents, to get the tools of the agents it's delegating the tasks to... shouldn't it work they other way around (if anything)? In other words, the delegating agents should inherit the tools from the manager agent, rather than the opposite way around.

As far as I have seen, most people either attach tools to specific tasks, or to specific agents. In the case where tools are assigned to tasks, this logic is fine since the manager agent gives tasks to agents. But in the case where tools are attached to agents, does the manager delegate the tasks according to which tools are equipped to each agent? This is a bit confusing and is not really explained in the docs.