joaomdmoura / 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
16.84k stars 2.27k forks source link

Bug in 0.22.5 with co-worker delegation #351

Open olafgeibig opened 3 months ago

olafgeibig commented 3 months ago

The agent wants to delegate a task to a co-worker. Although the name is correct, the co-worker is not found. crewAI 0.22.5, MacOS, Python 3.11.7, Ollama running adrienbrault/nous-hermes2pro:Q5_K_M

Output:

Example input:
{
  "tool_name": "delegate work to co-worker",
  "arguments": {
    "coworker": "Senior Research Analyst",
    "task": "Summarize the top 10 AI trends for 2024",
    "context": "Here are the top 10 AI and machine learning trends to prepare for in 2024:\n\n1. Multimodal AI\n2. Small (er) language models and open source advancements\n3. GPU shortages and cloud costs\n4. Customized local models and data pipelines\n5. More powerful virtual agents\n6. Seamless integration of AI into everyday products\n7. Emphasis on ethics, safety, and regulatory compliance\n8. Advancements in explainable AI (XAI)\n9. Quantum computing and AI convergence\n10. Continued growth of generative AI"
  }
}<|im_end|> 

Error executing tool. Co-worker mentioned not found, it must to be one of the following options:
- Senior Research Analyst

The Agent definition:

researcher = Agent(
  role='Senior Research Analyst',
  goal='Uncover cutting-edge developments in AI and data science in',
  backstory="""You are a Senior Research Analyst at a leading tech think tank.
  Your expertise lies in identifying emerging trends and technologies in AI and
  data science. You have a knack for dissecting complex data and presenting
  actionable insights. You ask the human for feedback if the result of a research is relevant for the report.""",
  verbose=True,
  allow_delegation=False,
  tools=[search_tool],
  llm=llm,
  function_calling_llm=llm_func
)
ryanmac commented 3 months ago

I see a lot of this too. From the verbose logs it looks like the Action Input is incorrectly structuring the task, using to co-worker instead of coworker.

For example, this fails:

Action: Ask question to co-worker
Action Input: {
    "co-worker": "Analyzer",
    "question": "Can you provide me a summary?",
    "context": ""
}

But this works:

Action: Ask question to co-worker
Action Input: {
    "coworker": "Analyzer",
    "question": "Can you provide me a summary?",
    "context": ""
}
olafgeibig commented 3 months ago

Interesting. Probably co-worker was a bad choice because there are two correct spellings for it.

WindSmileValley commented 1 month ago

in which .py to fix it?

madmag77 commented 1 month ago

I've had the same problem when LLM (Mistral 0.3 in my case) return action input key as co-worker instead of required coworker and this caused the same misleading error about absent agent. I fixed it in this PR. Already tested in my fork - it works fine.

imars commented 1 month ago

I'm using your fork (@madmag77) with Ollama and llama 3 and it's still failing with:

"Thought: I need to break down this complex task into manageable blah blah.. Action Input: {.. "coworker": "architect <-- Thought output truncates here?
Error executing tool. coworker mentioned not found, it must to be one of the following options:

madmag77 commented 1 month ago

@imars

I'm using your fork (@madmag77) with Ollama and llama 3 and it's still failing with:

"Thought: I need to break down this complex task into manageable blah blah.. Action Input: {.. "coworker": "architect <-- Thought output truncates here? Error executing tool. coworker mentioned not found, it must to be one of the following options:

  • architect

Interesting, I'm using it with LM Studio + Phi3 medium or Mistral Instruct 0.3 and it works fine, especially with Mistral (Phi sometimes fails on other steps in my flow, but delegation works perfect). When I tried LM Studio + Llama 3 7B it doesn't work at all - Llama just tries to do everything in one response: delegate work, add observations, add imaginary answer from delegate and finish the work :)

I'll try to install Ollama and try LLama3 again later on though - curios how it would work...

madmag77 commented 1 month ago

I'm using your fork (@madmag77) with Ollama and llama 3 and it's still failing with:

"Thought: I need to break down this complex task into manageable blah blah.. Action Input: {.. "coworker": "architect <-- Thought output truncates here? Error executing tool. coworker mentioned not found, it must to be one of the following options:

  • architect

@imars I finally tested on Llama 3 with Ollama and LM Studio and made another fix in my fork after that it started working. You may want to try it as well to check