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
21.38k stars 2.97k forks source link

Agent execution stuck in a forever loop while using gpt-4o #737

Closed akshatjain99 closed 3 months ago

akshatjain99 commented 5 months ago

Hey folks,

I have a simple crew that takes in an instruction from the user and makes an API call (using a tool) to fetch some data. Even though the agent correctly identifies that it wants to make an API call, while calling the tool, it is stuck in a forever loop.

It keeps calling the tool with the same input again and again, the tool however never gets executed and ultimately, I get a timeout exception.

console.txt

For context, I'm using gpt-4o.

Any help will be appreciated, Thanks.

mangalprada commented 5 months ago

Can you be more specific and share code and other details like you would on Stack Overflow so that we can help?

akshatjain99 commented 5 months ago

Hey @mangalprada,

My crew looks like this:

`from crewai import Agent, Crew, Task

from agents.tools.extractData import ExtractData
from agents.tools.makeApiCall import MakeAPICall

class CrewExperiment:

  def __init__(self, llm):
    self.llm = llm

  def run(self):
      recipe_agent = Agent(
          role='Code Expert',
          goal='From the relevant information about the APIs, write an algorithm of list of steps that can be used to get the fields specified by the user.',
          backstory="""
            Background:
                You are a code expert agent that understands APIs, JSON and how to link multiple steps together. 
                Your main aim is to write an algorithm with a list of steps to fulfill an objective.

                `Based on the action you want to perform, select the desired tool and get the definition from there.
                For example, to make an API call, use the 'makeApiCall' tool.

            ##############################################################################################################    
            Task:
                The user has come to you with two sets of information: a list of selected APIs and a list of fields that it wants to fetch. 
                Write a strcutured step by step algorithm that starts from scratch and adds all the fields asked by the user to the user's model.                 
                You must use the tools and get their definition and use those in the recipe. 

            ##############################################################################################################
            """,
          llm=self.llm,
          allow_delegation=True,
          verbose=True,
          tools=[MakeAPICall(), ExtractData()],
        )

      prepare_recipe = Task(
          description=("""
            Write an algorithm that contains a list of steps and their definitions to add the required fields to my model. 

            The information about the selected APIs is as follows:

    The API that is needed to get the field is:
        - "method": "GET",
        - "url": "https://xyz.com/api/",
        - "response": "{{firstname: "", lastname: "", email: ""}}",         

            The fields that need to be extracted are : first name, last name, email

            ##############################################################################################################

            """),
          expected_output='Algorithm that contains a list of steps to extract the fields mentioned.',
          agent = recipe_agent
        )

      crew = Crew(
          agents=[recipe_agent],
          tasks=[prepare_recipe],
          verbose=True
        )

      result = crew.kickoff(inputs={})

      return result`

and I have two tools:

Both tools take in an argument and return the json response.

akshatjain99 commented 5 months ago

My hunch is that is not able to capture the tool output correctly, maybe? Because the agent keeps going in a loop calling the tools again and again - so maybe it is not recognizing that the tool has already been called and it has the output for that?

akshatjain99 commented 5 months ago

@mangalprada, any thoughts on this?

jabbasj commented 4 months ago

I've had a similar experience unfortunately and it's super frustrating: it correctly identifies the tool or agent to delegate to but then in the response it's as if the data/answer never makes it back to whoever requested the tool/agent and it keeps looping.

github-actions[bot] commented 3 months ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 3 months ago

This issue was closed because it has been stalled for 5 days with no activity.