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.55k stars 2.55k forks source link

SerperDevTool._run() missing 1 required positional argument: 'search_query'. #430

Closed BracerJack closed 22 hours ago

BracerJack commented 4 months ago

A.I says: I encountered an error while trying to use the tool. This was the error: SerperDevTool._run() missing 1 required positional argument: 'search_query'. Tool Search the internet accepts these inputs: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.

I am just running from the example, copy and paste. `` import os from crewai import Agent, Task, Crew, Process from crewai_tools import SerperDevTool

os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY"

os.environ["SERPER_API_KEY"] = "I have filled this in with a valid key" # serper.dev API key

os.environ["OPENAI_API_BASE"] ='http://localhost:11434/v1' os.environ["OPENAI_MODEL_NAME"] ='mistral' # Adjust based on available model os.environ["OPENAI_API_KEY"] ='null' #switching between null and ollama makes no difference, the error as mentioned remains.

search_tool = SerperDevTool() ``

The rest is exactly copy and paste from the front page example.

joaomdmoura commented 4 months ago

Could be a model limitation but will give it a try as well! Em 5 de abr. de 2024, 19:32 -0300, Bracer Jack @.***> escreveu:

A.I says: I encountered an error while trying to use the tool. This was the error: SerperDevTool._run() missing 1 required positional argument: 'search_query'. Tool Search the internet accepts these inputs: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content. I am just running from the example, copy and paste. import os from crewai import Agent, Task, Crew, Process from crewai_tools import SerperDevTool

os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY"

os.environ["SERPER_API_KEY"] = "I have filled this in with a valid key" # serper.dev API key You can choose to use a local model through Ollama for example. See https://docs.crewai.com/how-to/LLM-Connections/ for more information. os.environ["OPENAI_API_BASE"] ='http://localhost:11434/v1' os.environ["OPENAI_MODEL_NAME"] ='mistral' # Adjust based on available model os.environ["OPENAI_API_KEY"] ='null' #switching between null and ollama makes no difference, the error as mentioned remains. search_tool = SerperDevTool() The rest is exactly copy and paste from the front page example. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>

BracerJack commented 4 months ago

Could be a model limitation

Ok let me try again now: import os from crewai import Agent, Task, Crew, Process from crewai_tools import SerperDevTool

os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY"

os.environ["SERPER_API_KEY"] = "valid API Key enetered" # serper.dev API key

os.environ["OPENAI_API_BASE"] ='http://localhost:11434/v1' os.environ["OPENAI_MODEL_NAME"] ='llava' #I swtitched from 'mistral' to llava. os.environ["OPENAI_API_KEY"] ='null' bla bla bla

Result: Action 'search_query' don't exist, these are the only available Actions: Search the internet: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.

Switching from 'mistral' to 'llava' makes no difference, the search still fails. the serper API key is valid. It should also be noted that I install via: pip install "crewai[tools]" so the tools exist.

joaomdmoura commented 4 months ago

I'll also try the same models locally just in case to make sure we make it better for them, but just in case, gpt4 works like a cham I guess?

-- João Moura @joaomdmoura http://twitter.com/joaomdmoura

Em sex., 5 de abr. de 2024 às 19:38, Bracer Jack @.***> escreveu:

Could be a model limitation

Ok let me try again now: import os from crewai import Agent, Task, Crew, Process from crewai_tools import SerperDevTool

os.environ["OPENAI_API_KEY"] = "YOUR_API_KEY"

os.environ["SERPER_API_KEY"] = "a0b7dc06666b68bac203ea16276b9e58c21e19dd"

serper.dev API key

You can choose to use a local model through Ollama for example. See https://docs.crewai.com/how-to/LLM-Connections/ for more information.

os.environ["OPENAI_API_BASE"] ='http://localhost:11434/v1' os.environ["OPENAI_MODEL_NAME"] ='llava' #I swtitch from 'mistral' to llava. os.environ["OPENAI_API_KEY"] ='null' bla bla bla

Result: Action 'search_query' don't exist, these are the only available Actions: Search the internet: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.

— Reply to this email directly, view it on GitHub https://github.com/joaomdmoura/crewAI/issues/430#issuecomment-2040720430, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAFC3N4UM3DU37IDAJB4M5LY34RWJAVCNFSM6AAAAABFZ34LFGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANBQG4ZDANBTGA . You are receiving this because you commented.Message ID: @.***>

BracerJack commented 4 months ago

No idea, I only use local models. CrewA.I. worked before, but I deleted the archived venv isolated folder to update because it has been a long time and that venv backup was old, should have kept the backup! ha ha ha Good luck solving this :D

More reports: Action 'search_query('AI advancements 2023')' don't exist, these are the only available Actions: Search the internet: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.

BracerJack commented 4 months ago

Switched from Ollama to LM Studio to see if anything changes, nope same issue, it should also be noted that yet another different model was used, this issue seems to be model independent: Action '[Search the internet] 'artificial intelligence trends 2024' - A tool that can be used to semantic search a query from a txt's content.' don't exist, these are the only available Actions: Search the internet: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.

BracerJack commented 4 months ago

I have updated crewA.I. to the latest v0.28.1 7 April 2024 and it is still giving this error: "I encountered an error while trying to use the tool. This was the error: SerperDevTool._run() missing 1 required positional argument: 'search_query'. Tool Search the internet accepts these inputs: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content."

NSMyself commented 4 months ago

I've ran into the same issue but weirdly enough it only appears to fail sporadically; i first saw the error 5m ago and I ended up re-running just for the sake of it but it appears to be working now.

Edit: it actually just failed in the middle of my task. It made two successfully Serper search requests, failed twice and then worked again:

_I encountered an error while trying to use the tool. This was the error: SerperDevTool._run() missing 1 required positional argument: 'search_query'. Tool Search the internet accepts these inputs: Search the internet(searchquery: 'string') - A tool that can be used to semantic search a query from a txt's content.

joaomdmoura commented 4 months ago

I mean I'm doing some digging but it seems to be a model limitation (smaller models sometime struggle more than bigger ones), the good thing is that crewAI will try to skew the model to try again with the right format, but I'll still do some more digging on this

NSMyself commented 4 months ago

@joaomdmoura thanks for the quick reply. I've edited my comment above btw, it now appears to fail sporadically instead of permanently.

For the record, I'm using Mistral 7B on a MacBook Air M1 (16GB RAM). I'm aware it is a bit heavy, as there is some delay when chatting with the LLM locally. I will give it a shot on a smaller LLM later today hopefully.

joaomdmoura commented 4 months ago

Yup, smaller model will probably fail even more often

NSMyself commented 4 months ago

Oh, i see. Well, I'll try a larger one then 😅

BracerJack commented 4 months ago

Looks like the solution might be to have a list of "compatible models" along with the minimum quantization needed.

0xC0FFEE71 commented 4 months ago

I have the same issue here, SerperDevTool is not working, returning forementioned error message. Also here, I just copied and pasted the trip planner example, which worked well with gpt4. Now I am using Ollama on Windows and tried the following models: llama2:7b (as far as I can see, the agent doesnt even try to use SerperDevTool, stops after max iterations) llama2:13b (the agent tries to search, but SerperDevTool does not work) llama2:70b (freezes, I can actually run models that large on my machine, but for this example, it doesn't work) openhermes (SerperDevTool works sporadically, but then WebsiteSearchTool fails) mistral:7b (works, SerperDevTool fails its very first attempt but then "adjusts" and runs well)

hope this helps

Do I still have to configure all model files to introduce "Result" as stop word?

BracerJack commented 4 months ago

I just ran it on dolphin-2.8-mistral-7b-v02, a recent model and it failed, but seeing from the comments that the failure/success rate is also "random", I cannot longer say it definitely doesn't work.

The issue here is...it is not that the search is returning nothing...it is not that too little or too much information came from the search, the situation seem to be that the connection itself is not even established, you have:

1: "A tool that can be used to semantic search a query from a txt's content.' don't exist" 2: SerperDevTool._run() missing 1 required positional argument: 'search_query'. 3: Action 'search_query' don't exist, these are the only available~

The first one stats the tool didn't exist even though pip install "crewai[tools]" is used. The second is a code error itself where 1 argument is missing, this seems to indicate code issue, not A.I. issue? The third one, the function call doesn't exist...code issue again? Nothing to do with the A.I. ?

Any idea what is the version where this work? Or we have a case where even if we go back in versions it wouldn't help because the tools that are installed via pip install "crewai[tools]" wasn't archived so the old version of crew_ai would still be using the newer damaged tools?

I am speculating here, I have no idea.

ThinksFast commented 4 months ago

I'm also getting this error, but using the JSONSearchTool. I have not tried this with other tools, but I've tried using both local LLMs and gpt-4-0125-preview.

Full CrewAI error text is:

Action: Search a JSON's content

Action Input: {"query": "datadog"}

I encountered an error while trying to use the tool. This was the error: JSONSearchTool._run() missing 1 required positional argument: 'search_query'.
 Tool Search a JSON's content accepts these inputs: A tool that can be used to semantic search a query the data/knowledge_base.json JSON's content.

Environment:

python==3.11.8
crewai==0.28.6
crewai-tools==0.1.6
thiagosrib commented 4 months ago

Hi guys,

I have the same issue here using codellama local model with ollama.

Action Input: {'string': 'current trends and breakthroughs in AI research'} 

I encountered an error while trying to use the tool. This was the error: SerperDevTool._run() missing 1 required positional argument: 'search_query'.
 Tool Search the internet accepts these inputs: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.

I'm trying to run the example on Readme file on the creawAI github.

BracerJack commented 4 months ago

Updated to the latest v0.28.5 as of 11 April 2024, same issue: I encountered an error while trying to use the tool. This was the error: SerperDevTool._run() missing 1 required positional argument: 'search_query'. Tool Search the internet accepts these inputs: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.

joaomdmoura commented 4 months ago

Do I still have to configure all model files to introduce "Result" as stop word?

@0xC0FFEE71 last time I check this was not necessary anymore

@BracerJack @thiagosrib @ThinksFast

Updated to the latest v0.28.5 as of 11 April 2024, same issue: I encountered an error while trying to use the tool. This was the error: SerperDevTool._run() missing 1 required positional argument: 'search_query'. Tool Search the internet accepts these inputs: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.

This one could be a bug we shipped a couple thins in the tools that I think impacted, this will get the team looking into it first thing in the morning

BracerJack commented 4 months ago

Thank you for taking the time to reply, it is nice to know our issues are heard.

gcaith2 commented 4 months ago

Traceback (most recent call last): File "c:/Users/AVITA/Desktop/Learn Django/aiagent/newsletter.py", line 3, in
from crewai_tools import SerperDevTool ModuleNotFoundError: No module named 'crewai_tools'

christianazinn commented 4 months ago

Going to throw my hat into the ring and say it's affected me too - serving via LM Studio v0.2.19 beta, tested with Zephyr Beta 7B and Mistral Instruct 7B, failed both times. It doesn't even work with Command-R locally.

sahilkamath0108 commented 4 months ago

I seem to have solved the problem. When you define the task that involves serper search tool, in the task description add this particular line: 'Set the input parameter as : search_query'. By default it sets the parameter as 'query' which is not allowed by serper, so.... try this

theCyberTech commented 4 months ago

Could you post a snippet example for reference?

sahilkamath0108 commented 4 months ago

research_agent = Agent( role='Researcher', goal='Find and summarize the latest AI news', backstory="""You're a researcher at a large company. You're responsible for analyzing data and providing insights to the business.""", verbose=True, llm=llm, tools=[search_tool] )

task = Task( description='Find and summarize the latest AI news. Set the input parameter as : search_query', expected_output='A bullet list summary of the top 5 most important AI news', agent=research_agent )

NSMyself commented 4 months ago

Adding Set the input parameter as : search_query' didn't really help in my case, even when using your agent and task:

[DEBUG]: == Working Agent: Researcher
 [INFO]: == Starting Task: Find and summarize the latest AI news. Set the input parameter as : search_query

> Entering new CrewAgentExecutor chain...
 Action: Search the internet(search_query="latest AI news")
Action Input: {'search_query': 'latest AI news'}

Action 'Search the internet(search_query="latest AI news")' don't exist, these are the only available Actions: Search the internet: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.
carmineapice commented 4 months ago

I seem to have solved the problem. When you define the task that involves serper search tool, in the task description add this particular line: 'Set the input parameter as : search_query'. By default it sets the parameter as 'query' which is not allowed by serper, so.... try this

It worked apparently

ananthpn commented 4 months ago

research_agent = Agent( role='Researcher', goal='Find and summarize the latest AI news', backstory="""You're a researcher at a large company. You're responsible for analyzing data and providing insights to the business.""", verbose=True, llm=llm, tools=[search_tool] )

task = Task( description='Find and summarize the latest AI news. Set the input parameter as : search_query', expected_output='A bullet list summary of the top 5 most important AI news', agent=research_agent )

Your solution worked for me, thanks much!

BracerJack commented 4 months ago

16 April 2024: Adding "Set the input parameter as : search_query." doesn't work.

Now you get: Action 'search_query' don't exist, these are the only available Actions: Search the internet: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.

theCyberTech commented 4 months ago

Quick question where are you setting the tool? On the agent or on the task?

BracerJack commented 4 months ago

I placed it in task following ananthpn's example :-)

theCyberTech commented 4 months ago

Ok, could you do me a favor and set it on the both the agent and task, it's the same attribute on the agent

BracerJack commented 4 months ago

I removed all traces of crewAI from my system, maybe at a later time :-)

BracerJack commented 4 months ago

Ok, could you do me a favor and set it on the both the agent and task, it's the same attribute on the agent

It works. It works. It works!!! I went full insane and paste: Set the input parameter as : search_query.

Everywhere, in agents and tasks. Now it works. Alright that's it, I am making a local backup of ALL these (the current version) as it is working right now: 16 April 2024.

Thank you theCyberTech for your suggestion.

It works it works it works ! To anyone reading this, this is on 16 April 2024. The version that works for this test: v0.28.5 I cannot garentee if the crewai[tools], the "tools" part are archived in the same version as crewA.I. itself, if you are reading this and it is still on 0.28.5, make a backup copy now because everything is working right now ! he he he

And once again, thanks for being awesome theCyberTech!

theCyberTech commented 4 months ago

No worries, FYI this also works for the rag tools, setting on the agent and the task

theCyberTech commented 4 months ago

FYI I'm a mod from the discord server so catch me on there if any other issues

BracerJack commented 4 months ago

FYI I'm a mod from the discord server so catch me on there if any other issues

I will if I ever get back to discord again, I was thinking of making a server for my YouTube subscribers but discord also take time and attention resources ;p

Again, thank you for resolving this issue ;p

vishalvihaapps commented 4 months ago

It is not working still. I am using LLAMA2 7B via Ollama.

Error below:

Action 'Search the internet("Latest AI News")' don't exist, these are the only available Actions: Search the internet: Search the internet(search_query: 'string') - A tool that can be used to semantic search a query from a txt's content.

Request help on this issue.

Code is very simple:

`from crewai import Agent, Task, Crew, Process from langchain_community.llms import Ollama from langchain_community.tools import DuckDuckGoSearchRun from langchain.tools import Tool from crewai_tools import tool from crewai_tools import SerperDevTool from langchain_openai import ChatOpenAI

import os

os.environ["SERPER_API_KEY"] = "XXX" os.environ["OPENAI_API_BASE"] = 'http://localhost:11434/v1' os.environ["OPENAI_MODEL_NAME"] ='llama2' os.environ["OPENAI_API_KEY"] ='null'

search_tool = SerperDevTool()

research_agent = Agent( role='Researcher', goal='Find and summarize the latest AI news. Example: {"search_query": "Latest AI News"}', backstory="""You're a researcher at a large company. You're responsible for analyzing data and providing insights to the business.""", verbose=True, tools=[search_tool] )

task = Task( description='Find and summarize the latest AI news. Example: {"search_query": "Latest AI News"}', expected_output='A bullet list summary of the top 5 most important AI news', agent=research_agent )

crew = Crew( agents=[research_agent], tasks=[task], verbose=2 )

result = crew.kickoff() print(result)`

jimccadm commented 4 months ago

Hi there. This is 100% to do with Ollama/local LLMs. I have confirmed this by testing llama3, llama2 (via Ollama) and the same search_query error persists. On switching to OpenAI API key, 100% works fine, Serper does the search magic and zero errors.

jimccadm commented 4 months ago

UPDATE: After some further Ollama testing (mixtral, alfred, solar) I appear to be having success with dolphin2.1-mistral (4.1gb) with no need to add search_query addition(s). May be worth trying. Further update: starling-lm too but you'll need to go harder on your prompts (the results from my serper searches were weak, so I needed to emphasise the need for more detail, which it seems to be behaving well with). I've also asked the Write agent in my code to use llama3 for better enrichment to the final product which may also be assisting things, rather than solely employing starling-lm throughout.

elhakimz commented 3 months ago

It sucessfully using phi3 (without changing temperature), but if I set temperature to .8 it failed to use SerperDevTool image

but the result is hilarious : the topic is

result = crew.kickoff(inputs={'topic': 'AI in industrial manufacture'})

but the MD file result is about :

_> Finished chain. Executive Summary of Smartphone Sales Growth Trend Analysis by Age Demographics (2018-2023):

The past five years have seen varying growth rates in smartphone sales among different age groups. The following key insights provide a snapshot of the trends within each demographic:

Children & Teenagers (ages 0-14): This youngest segment has demonstrated minimal impact on overall smartphone sales, as children's primary ownership of smart devices is usually through family members or guardians. However, the rising adoption rates in education and child safety monitoring could represent future market potential.

Young Adults (ages 15-24): The young adult segment has shown robust growth in smartphone sales due to increased usage of these devices for social interaction, e-learning, and job opportunities during the pandemic era. Factors contributing to this trend include affordability of high-spec devices as well as a greater preference for owning over renting smartphones. -- bla bla_

joaomdmoura commented 3 months ago

Hey folks, good new this should be fixed on the new version we are now testing, 0.30.0rc3, if you want ot give it a try you can do to with pip install 'crewai[tools]'==0.30.0rc3 lmk how it goes!

joaomdmoura commented 3 months ago

It's non deterministic but we tried to make way easier for smaller models to use tools and this one in particular

biraescudero commented 3 months ago

João, thanks for your open source code and dedication. I'm struggling with this problem. Using Groq and local models. I get an error installing this rc vesrion: (.venv) C:\Users\ubira\PycharmProjects\teste_groq>pip install 'crewai[tools]'==0.30.0rc3 ERROR: Invalid requirement: "'crewai[tools]'==0.30.0rc3"

biraescudero commented 3 months ago

I used a slightly differente comand:

pip install crewai==0.30.0rc3 which result was ==>Successfully uninstalled crewai-0.28.8 and Successfully installed crewai-0.30.0rc3

After this, I run (just in case): pip install crewai[tools]
which result was ==> Successfully uninstalled crewai-tools-0.1.7 and Successfully installed crewai-tools-0.2.2

Still testing, but it looks work great on Groq llama3-8b-8192. I believe this issue is solved, but we need more tests and opinions from community.

I will keep testing.

Thanks a lot and congratulations.

joaomdmoura commented 3 months ago

You can know also give the prompt templates that works the better for the model:

Agent = Agent(
    role="{topic} specialist",
    goal="Figure {goal} out",
    backstory="I am the master of {role}",
    system_template="""<|start_header_id|>system<|end_header_id|>

{{ .System }}<|eot_id|>""",
    prompt_template="""<|start_header_id|>user<|end_header_id|>

{{ .Prompt }}<|eot_id|>""",
    response_template="""<|start_header_id|>assistant<|end_header_id|>

{{ .Response }}<|eot_id|>""",
)
BracerJack commented 3 months ago

3 May 2024 Testing 0.30.0rc3 as suggested. Since error is supposedly fixed, I will now remove "Set the input parameter as : search_query." from the backstory parameter.

Error: Action: Search the internet Action Input: {'search_query': 'AI advancements 2024

{'message': 'Missing query parameter', 'statusCode': 400}

Error Handling

Since the Search the internet tool returned an error, I need to handle it before proceeding. Let me try rephrasing the search query:

Action: Search the internet Action Input: {search_query: "latest advancements in AI 2024"}

Thought: Hopefully this revised query will yield better results Let's handle these errors and proceed with caution!

Error Handling

It seems that the Action Input is not being recognized as a valid key-value dictionary. Let me reformat it to match the expected input:

Action: Search the internet
Action Input: {'search_query': 'latest advancements in AI 2024'}

With this revised format, let's retry the search: ``Let me rephrase the Action Input one more time to ensure it matches the expected input:

Action: Search the internet
Action Input: {'search_query': 'latest advancements in AI 2024'}

I'll retry the search with this revised format... I have stopped with the test, it doesn't work for me.

Fortunately I have made a venv backup as suggested further up the post of the version that does work with "Set the input parameter as : search_query." implemented so no loss there.

This is just the result of my own test, maybe others have better luck, I am giving this version a miss since I retained the version that works on the first try :-)

biraescudero commented 3 months ago

@BracerJack, try not pass query arguments and let the agent manage this.

My code: search_tool = SerperDevTool( url = "https://google.serper.dev/search", country="br", location="location", locale="pt-br" )

I hope it works fr you.

BracerJack commented 3 months ago

Thank you @biraescudero, the version I am using that works does not require me to fill in all these data in the SerperDevTool, I left it as search_tool = SerperDevTool() as the example shown for a yet an even older version that works when that example was created for.

For now I will stick to the old working version, only for now :D

joaomdmoura commented 3 months ago

@BracerJack this is super useful, what model are you using, I'd love to replicate it locally, but I think I found what the bug might be

BracerJack commented 3 months ago

Glad I could be of help @joaomdmoura.

llama3 on Ollama.

It should be noted that I doubled check the API from https://serper.dev/api-key to make sure it is not an external issue, it is functional.