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
17k stars 2.3k forks source link

encountered an error while trying to use the tool. This was the error: 'NoneType' object has no attribute 'startswith' #668

Open felixgao opened 1 month ago

felixgao commented 1 month ago

The crew is chugging along then it failed

> Entering new CrewAgentExecutor chain...
Action: Ask question to co-worker
Action Input: {
 "question": "Can you provide me with the key facts about the new iPad Air from Apple?",
 "context": "The new iPad Air is available in new blue and purple finishes, along with starlight and space gray. Customers can order the new iPad Air today, with availability beginning Wednesday, May 15."
 }
Action: Delegate work to co-worker
Action Input: {
 "task": "Verify the accuracy of the AI Information Researcher report for Apple Inc.(Stock code :AAPL).",
 "context": "The new iPad Air is available in new blue and purple finishes, along with starlight and space gray. Customers can order the new iPad Air today, with availability beginning Wednesday, May 15."
 }
Thought: After getting the key facts from the co-worker, I will cross-check them against authoritative references to confirm factual correctness.Thought: To begin, let's ask the Information Researcher for the key facts about the new iPad Air from Apple.
Action: Ask question to co-worker
Action Input: {
 "question": "Can you provide me with the key facts about the new iPad Air from Apple?",
 "context": "The new iPad Air is available in new blue and purple finishes, along with starlight and space gray. Customers can order the new iPad Air today, with availability beginning Wednesday, May 15."
 }
Thought: Once we have the key facts, I'll delegate a task to the co-worker to verify their accuracy.Thought: Let's correct the input and proceed with the actions.

Action: Ask question to co-worker
Action Input: {
 "question": "Can you provide me with the key facts about the new iPad Air from Apple?",
 "context": "The new iPad Air is available in new blue and purple finishes, along with starlight and space gray. Customers can order the new iPad Air today, with availability beginning Wednesday, May 15."
 }

I encountered an error while trying to use the tool. This was the error: 'NoneType' object has no attribute 'startswith'.
 Tool Ask question to co-worker accepts these inputs: Ask question to co-worker(question: str, context: str, coworker: Optional[str] = None, **kwargs) - Ask a specific question to one of the following co-workers: [Information Researcher]
The input to this tool should be the co-worker, the question you have for them, and ALL necessary context to ask the question properly, they know nothing about the question, so share absolute everything you know, don't reference things but instead explain them.

Code

from crewai import Agent, Task, Crew, Process
from langchain_community.tools import DuckDuckGoSearchRun
from crewai.tasks.task_output import TaskOutput
from langchain.agents import Tool
from langchain_community.llms import Ollama

mistral_client = Ollama(model="openhermes")

research_topic = "Apple Inc.(Stock code :AAPL)"

#Solve the spelling mistake in "search\_tool" on mistral ai**
search = DuckDuckGoSearchRun()
search_tool = Tool(
    name="search\_tool",
    description="A search tool used to query DuckDuckGo for search results when trying to find information from the internet.",
    func=search.run
)

def search_result_callback(output: TaskOutput):
    if output.result is not None:
        print("Search task completed successfully!")
        print("Search Results:\n", output.result)
    else:
        print("Search task failed to produce output.")

# Define agents with specific roles and tools
researcher = Agent(
    role='Information Researcher',
    goal=f'Search the internet for the latest news , announcement about {research_topic} with accurate sourcing.',
    backstory="""As a Researcher, passionate and knowledgable about technology industry's forefront, you meticulously gather and verify the latest business trend and products developments. Your quest for truth requires verifying the authenticity of information, ensuring a credible knowledge base for informed decision-making.""",
    verbose=True,
    llm=mistral_client
)

fact_checker = Agent(
    role='Information Fact Checker',
    goal="Provide judgement to AI Information Researcher findings on the credibility of the information by 'True' or 'False' or 'unknown'.",
    backstory="""As the guardian of truth, you critically assess the AI Information Researcher's data for accuracy by cross check from internet. Your expertise ensures the integrity and credibility of information shared, maintaining a standard of trustworthiness in a data-saturated world.""",
    verbose=True,
    llm=mistral_client
)

# Create tasks for the agents
research_task = Task(
    description=f'Search 3 topic for the latest news {research_topic} within May of 2024, ensuring all data is backed by credible sources. Compile a report detailing each finding and its source for verification.', 
    expected_output=f'Summary of 3 latest news on {research_topic} from May 2024 with credible sources.',
    tools=[search_tool], 
    agent=researcher,
    callback=search_result_callback
)
fact_checker_task = Task(
    description=f'Verify the accuracy of the AI Information Researcher report for {research_topic}. Cross-check all cited sources against authoritative references to confirm factual correctness, highlighting any inaccuracies or areas needing further verification.', 
    expected_output=f'Verification report on {research_topic} with accuracy assessment and source validation.',
    tools=[search_tool], 
    agent=fact_checker
)

# Assemble the crew with a sequential process
my_crew = Crew(
    agents=[researcher, fact_checker],
    tasks=[research_task, fact_checker_task],
    process=Process.sequential,
    verbose=2,
)
# Start the crew's task execution
result = my_crew.kickoff()
print(result)

I also tired llama3 or gemma using Ollama also failed.

> Entering new CrewAgentExecutor chain...
Thought: I need to search for the latest news about Apple Inc. (Stock code: AAPL) within May 2024. To ensure accuracy and credibility, I will rely on reputable sources.

Action: search_tool

Action Input: {"q": "latest news apple inc aapl may 2024", "source": "reputationNo good DuckDuckGo Search Result was found

No good DuckDuckGo Search Result was found

Thought:
It seems that the initial search did not yield any satisfactory results. Since I need to rely on reputable sources for accurate information, I will delegate the task of searching for credible news articles about Apple Inc. (Stock code: AAPL) within May 2024 to my co-worker.

Action: Delegate work to co-worker

Action Input: {"task": "search latest news apple inc aapl may 2024", "context": "Apple Inc.'s stock code is AAPL, and I'm looking for credible sources from reputable news outlets. The timeframe is within May 2024.", "coworker": "Information Fact Checker

Error executing tool. Co-worker mentioned not found, it must to be one of the following options:
- information fact checker

It seems that I made a mistake by trying to delegate a task to an incorrect co-worker. Let me try again.

Thought:
I will ask my Information Fact Checker co-worker for help in searching for credible news articles about Apple Inc. (Stock code: AAPL) within May 2024.

Action: Ask question to co-worker

Action Input: {"question": "Can you please find the latest news articles about Apple Inc. (Stock code: AAPL) from reputable sources, focusing on the timeframe of May 2024?", "context": "Apple's stock code is AAPL, and I'm looking for credible sources from reliable news outlets."

I encountered an error while trying to use the tool. This was the error: 'NoneType' object has no attribute 'startswith'.
 Tool Ask question to co-worker accepts these inputs: Ask question to co-worker(question: str, context: str, coworker: Optional[str] = None, **kwargs) - Ask a specific question to one of the following co-workers: [Information Fact Checker]
The input to this tool should be the co-worker, the question you have for them, and ALL necessary context to ask the question properly, they know nothing about the question, so share absolute everything you know, don't reference things but instead explain them.
WindSmileValley commented 1 month ago

me too. the arch seems many bug, and it is diffcult to work along with mind.

JayGhiya commented 1 month ago

same here. any luck?

gaborkukucska commented 1 month ago

Same here

akshatjain546 commented 1 month ago

bump. facing the same issue

sorydi3 commented 1 month ago

I had the same issue as well, my guess is that it might be related to the interpolacion of the input variable. try renaming your input variable research_topic to another name in a way that it does not resemble to any word within your task description or agent itself.

akram commented 1 month ago

Hi there, I am hitting the same issue. I am trying to run the instagram_post example. After some modification, it now starts to run but fail at some point:

-----------------
Title: Amazon.com: Original Sensory Chew Toys for Autistic Children ...
Link: https://www.amazon.com/Original-Autistic-Children-Silicone-Stimulation/dp/B0C712V32L
Snippet: Original Sensory Chew Toys for Autistic Children, Silicone Chewing Sticks for Autistic Chewers, ADHD, SPD, Oral Motor Stimulation or Special Needs (2Packs) (A).

-----------------

Thought: Now that we know a bit more about Gabbo and its features, let's ask the Senior Photographer to review the photos from the photoshoot.
Action: Ask question to co-worker
Action Input: {
  "question": "Can you please review the photos from the photoshoot of Gabbo?",
  "context": "The product is Gabbo, a robot toy designed to help children disconnect from the digital world and connect with the real world. The photographs should be aligned with the product's goals of promoting human interaction and helping children with autism develop social skills."
}

I encountered an error while trying to use the tool. This was the error: 'NoneType' object has no attribute 'startswith'.
 Tool Ask question to co-worker accepts these inputs: Ask a specific question to one of the following co-workers: [Senior Photographer]
The input to this tool should be the co-worker, the question you have for them, and ALL necessary context to ask the question properly, they know nothing about the question, so share absolute everything you know, don't reference things but instead explain them.

Thought: It seems like you're facing an issue with using the Ask question to co-worker tool. Can you please clarify what exactly is not working? I can help troubleshoot the issue and provide a solution if needed.
Action: Ask question to co-worker
Action Input: {
  "question": "Can you please review the photos from the photoshoot of Gabbo?",
  "context": "The product is Gabbo, a robot toy designed to help children disconnect from the digital world and connect with the real world. The photographs should be aligned with the product's goals of promoting human interaction and helping children with autism develop social skills."
}

I encountered an error while trying to use the tool. This was the error: 'NoneType' object has no attribute 'startswith'.
 Tool Ask question to co-worker accepts these inputs: Ask a specific question to one of the following co-workers: [Senior Photographer]
The input to this tool should be the co-worker, the question you have for them, and ALL necessary context to ask the question properly, they know nothing about the question, so share absolute everything you know, don't reference things but instead explain them.
greg80303 commented 1 month ago

I'm seeing this issue as well. Looking at the code, it appears to be because the agent doing the delegation is not including the names (Roles) of the co-worker agents in the tool call. You can see in your debug statements that the agent is passing the question and the context which are required for this call, but it is not passing the name of the co-worker that it wishes to ask.

The bug is happening here in crewai/tools/agent_tools.py:

    def ask_question(self, question: str, context: str, coworker: Union[str, None] = None, **kwargs):
        """Useful to ask a question, opinion or take from a co-worker passing all necessary context and names."""
        coworker = coworker or kwargs.get("co_worker") or kwargs.get("co-worker")
        is_list = coworker.startswith("[") and coworker.endswith("]")
        if is_list:
            coworker = coworker[1:-1].split(",")[0]
        return self._execute(coworker, question, context)

Note that the coworker parameter is optional. Seems like this was done so that the agent could call the function, passing the coworker as any of coworker, co_worker, or co-worker named parameters (the latter two options being handled via kwargs). But there's nothing in the definition of this function that forces one of the 3 forms to be passed, so the agent LLM likely sees this as truly optional and is ignoring it.

greg80303 commented 1 month ago

I just ran a quick test in which I modified the ask_question tool to require the coworker parameter, and that did not seem to fix the issue. For some reason, the documentation provided to the LLM regarding the tool signature is not working. The LLM is still not passing all the correct params.

maximinus commented 1 month ago

I have a similar issue with the same _askquestion function. The argument "coworker" is passed as a dict, even though the type signature is Union[str, None] and so fails in coworker.startswith("[") and coworker.endswith("]"). This would appear to backup what @greg80303 is saying, in my case the LLM is passing a the wrong parameter. This was with mistral 0.3 running under Ollama.

levidehaan commented 1 month ago

so what i did that works is i camelCased the agent names.

so instead of Strategy Agent its strategyAgent

this Was working great :D however, suddenly its not. digging more.

endcycles commented 1 month ago

so what i did that works is i camelCased the agent names.

so instead of Strategy Agent its strategyAgent

this Was working great :D however, suddenly its not. digging more.

This solution is temporarily working for me, thanks.

eav-solution commented 1 month ago

I think we should return missing parameters error for LLM instead raise an error: May be: coworker = coworker or kwargs.get("co_worker") or kwargs.get("co-worker") if not coworker: return "You must generate 'co-worker' parameter".

Is it ok ?

MelvinRook commented 3 weeks ago

I solved it by adding the following to the start of task2:

Using the insights provided from task1

I have seen other examples having the 2nd task starting with:

Take the input from task 1 and do something with it.

Yiyan0407 commented 3 weeks ago

I tried to add a prompt in my tasks: "If you use the ask_question tool, ensure to contain question, coworker, and context in the tool input." This solves the problem perfectly.

MrSimonC commented 1 week ago

For anyone else reading this, the recent PR #712 above, released in crewai==0.32.2 has made a big improvement for me after facing this problem. I recommend upgrading if you're still having issues.

akram commented 1 week ago

I solved it by adding the following to the start of task2:

Using the insights provided from task1

I have seen other examples having the 2nd task starting with:

Take the input from task 1 and do something with it.

Using this suggestion worked also for me. But, I had to do that for every task:

task1 <- task2 <- task3 <- task4

That would make it difficult to reuse tasks in different agents then as the task input may change from a situation to another. wdyt ?