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.9k stars 2.28k forks source link

Facing issues when using tools #841

Open githubdoramon opened 3 days ago

githubdoramon commented 3 days ago

Trying to run a super basic example, but whenever I add a tool (example, SerperDevTool), I got the dreadfull

Agent stopped due to iteration limit or time limit.

I've tried running againt ChatGPT but failed to get it working with the API key (most likely cause I tried to run it for free using GTP 3.5. Then I switch to LM Studio using Llama 3 v2

Sample code

import os

os.environ["SERPER_API_KEY"] = "xxxxx" - Hiding actual values
os.environ["BROWSERBASE_API_KEY"] = "xxxx"
os.environ["BROWSERBASE_PROJECT_ID"] = "xxxx"
os.environ["OPENAI_API_BASE"] = "http://localhost:1234/v1"
os.environ["OPENAI_API_KEY"] = "lm-studio"

from crewai import Crew, Process, Agent, Task
from crewai_tools import SerperDevTool, BrowserbaseLoadTool, EXASearchTool

search_tool = SerperDevTool()
browser_tool = BrowserbaseLoadTool()
exa_search_tool = EXASearchTool()

# Define your agents
researcher = Agent(
  role='Product Marketing Manager',
  goal='Bring insights and a hint of what the future entails for the rest of the company.',
  backstory='An experienced product marketing manager, with a big passion for gaming',
  verbose=True,
  memory=True,
  tools=[], # search_tool, browser_tool, exa_search_tool],
  max_iter=1,
)

# Define the tasks in sequence
research_task = Task(
    description='Conduct market and competitors research on the Playstation games market.',
    expected_output="A document with the latest trends in the gaming space for Playstation owners, and a list of competitors that are doing well in the space. The document should also contain a list of opportunities that we can leverage to surpass our competitors.",
    agent=researcher)

# Form the crew with a sequential process
report_crew = Crew(
  agents=[researcher],
  tasks=[research_task],
  process=Process.sequential
)

result = report_crew.kickoff()
print(result)

When I look at my Serper dashboard, no credit is being consumed.

I'm pretty sure I'm doing something dumb, but have no idea what.

brunooseliero commented 3 days ago

The error message "Agent stopped due to iteration limit or time limit" suggests that the agent reached its maximum number of allowed iterations or ran out of time. This often happens if the agent's tasks are too complex to complete within the provided limits.

Here's a plan to address the issue:

  1. Check Agent Configuration: Ensure the max_iter parameter is set appropriately. If it's set to 1, consider increasing it if the task requires more iterations to complete. Make sure there are no time constraints that are too strict for the tasks.

  2. Optimize Task Descriptions: Simplify the task description if it's too broad or complex. Breaking down the task into smaller sub-tasks might help. Use Tools Effectively: Uncomment and ensure that the tools provided are correctly integrated and configured to assist the agent in completing its tasks efficiently.

Here is a revised version of your code with some improvements:

import os

os.environ["SERPER_API_KEY"] = "xxxxx"  # Hiding actual values
os.environ["BROWSERBASE_API_KEY"] = "xxxx"
os.environ["BROWSERBASE_PROJECT_ID"] = "xxxx"
os.environ["OPENAI_API_BASE"] = "http://localhost:1234/v1"
os.environ["OPENAI_API_KEY"] = "lm-studio"

from crewai import Crew, Process, Agent, Task
from crewai_tools import SerperDevTool, BrowserbaseLoadTool, EXASearchTool

search_tool = SerperDevTool()
browser_tool = BrowserbaseLoadTool()
exa_search_tool = EXASearchTool()

##Define your agents
researcher = Agent(
    role='Product Marketing Manager',
    goal='Bring insights and a hint of what the future entails for the rest of the company.',
    backstory='An experienced product marketing manager, with a big passion for gaming',
    verbose=True,
    memory=True,
    tools=[search_tool, browser_tool, exa_search_tool],  # Ensure tools are provided
    max_iter=10,  # Increase the iteration limit
)

##Define the tasks in sequence
research_task = Task(
    description='Conduct market and competitors research on the Playstation games market.',
    expected_output=(
        "A document with the latest trends in the gaming space for Playstation owners, "
        "and a list of competitors that are doing well in the space. The document should "
        "also contain a list of opportunities that we can leverage to surpass our competitors."
    ),
    agent=researcher
)

##Form the crew with a sequential process
report_crew = Crew(
    agents=[researcher],
    tasks=[research_task],
    process=Process.sequential
)

result = report_crew.kickoff()
print(result)

Response using the crewai-assistant on openAI, see if it helps!

githubdoramon commented 2 days ago

This actually helped a lot. I thought that on each iteration the agent would try to do everything possible, but it needs more than an iteration to go through all his logic. Had to increase up to 60 to start getting him to consider the task finished. Will reduce the task's scope as well.

I still didn't manage to get a final "report" from it though, and am getting this errors on search

Action '** Search the internet**' don't exist, these are the only available Actions:
 Search the internet(**kwargs: Any) -> Any - Search the internet(search_query: 'string') - A tool that can be used to search the internet with a search_query.
Browserbase web load tool(url: str) - Browserbase web load tool(url: 'string') - Load webpages url in a headless browser using Browserbase and return the contents

Formatting errors incremented

But this doesn't happen all the time. Is it expected?