langchain
langchain copied to clipboard
ValueError: ZeroShotAgent does not support multi-input tool Calculator.
There is an error when i tried to use this code.
tools = load_tools(['llm-math', 'python_repl'], llm)
agent = initialize_agent(tools, agent="zero-shot-react-description", llm=llm)
Looks like because of #3684 checking if len(self.args) == 1: in self.is_single_input. But, self.args of llm-math is
{'args': {'title': 'Args', 'type': 'array', 'items': {}},
'kwargs': {'title': 'Kwargs', 'type': 'object'}}
So, self.is_single_input return False
Is there a way to get single input llm-math?
I've had the same problem with all agent types. The _validate_tools method is the problem. Commenting out this line, the agent resumes work: https://github.com/hwchase17/langchain/blob/v0.0.152/langchain/agents/agent.py#L478
I still can't figure out why. Does anyone know why the agent shouldn't support a multiple input tool?
I tried with ConversationalAgent with a RetrivalQA tool that needs {context} and {quary} inputs.
Hi @BankNatchapol
I think its related to the recent releases.
Installing v0.0.147 would resolve the issue. Do the following
pip install --force-reinstall -v langchain==v0.0.147
In the meantime someone needs to fix this bug.
I also have this issue after updating module to latest version for code that yesterday was running perfectly but today doesn't
I created a PR here that removes the restrictive checking of multi-input in the Agent base class. Will need reviewers to +1 and merge.
The bug where Tool(func=some_func)
was inferred to be a multi-input function was fixed in 0.0.153
Some tools recently landed (such as the playwright tools, some file management tools) are not compatible with older agent definitions.
Fixed in 0.0.153
I get the same error with ConversationalChatAgent. Is this by design or has it only been fixed in ZeroShotAgent?
ValueError: ConversationalChatAgent does not support multi-input tool query_webpage.
getting similar error. Here is a minimal example following their playwright example:
Error:
Traceback (most recent call last):
File "c:\Users\ryans\Documents\JobsGPT\test.py", line 38, in <module>
agent = initialize_agent(
^^^^^^^^^^^^^^^^^
File "C:\Users\ryans\.conda\envs\jobsgpt\Lib\site-packages\langchain\agents\initialize.py", line 52, in initialize_agent
agent_obj = agent_cls.from_llm_and_tools(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\ryans\.conda\envs\jobsgpt\Lib\site-packages\langchain\agents\mrkl\base.py", line 101, in from_llm_and_tools
cls._validate_tools(tools)
File "C:\Users\ryans\.conda\envs\jobsgpt\Lib\site-packages\langchain\agents\mrkl\base.py", line 125, in _validate_tools
super()._validate_tools(tools)
File "C:\Users\ryans\.conda\envs\jobsgpt\Lib\site-packages\langchain\agents\agent.py", line 502, in _validate_tools
raise ValueError(
ValueError: ZeroShotAgent does not support multi-input tool previous_webpage.
CODE:
from langchain.agents.agent_toolkits import PlayWrightBrowserToolkit
from langchain.chains.conversation.memory import ConversationBufferWindowMemory
from langchain.tools.playwright.utils import (
create_async_playwright_browser,
create_sync_playwright_browser,# A synchronous browser is available, though it isn't compatible with jupyter.
)
from langchain.chat_models import ChatOpenAI
import os
OPENAI_API_KEY=""
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
async_browser = create_async_playwright_browser()
toolkit = PlayWrightBrowserToolkit.from_browser(async_browser=async_browser)
tools = toolkit.get_tools()
tools_by_name = {tool.name: tool for tool in tools}
navigate_tool = tools_by_name["navigate_browser"]
get_elements_tool = tools_by_name["get_elements"]
print(tools)
# conversational agent memory
memory = ConversationBufferWindowMemory(
memory_key='chat_history',
k=3,
return_messages=True
)
from langchain.agents import initialize_agent
# Set up the turbo LLM
turbo_llm = ChatOpenAI(
temperature=0,
model_name='gpt-3.5-turbo'
)
from langchain.agents import AgentType
# create our agent
agent = initialize_agent(
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
tools=tools,
llm=turbo_llm,
verbose=True,
)
out = agent.run("Is there an article about Clubhouse on https://techcrunch.com/? today")
print(out)
Yes the playwright and other structured tools will be compatible with a new agent. Previous agents' format instructions and parsers don't work well with more complex signatures
Yes the playwright and other structured tools will be compatible with a new agent. Previous agents' format instructions and parsers don't work well with more complex signatures
Ok so which agent should I use then? Any examples?
Seeing the same error as @jasgeo75 for ValueError: ConversationalChatAgent does not support multi-input tool
Any workaround other than downgrading langchain?
@tirthb for the llm-math
/ python-repl
tool or something else? This particular issue was resolved for these tools.
For newer tools (playwright, write file, etc.), they are only compatible with newer agents.
Thanks, I was writing a custom tool that takes multiple arguments and calls an API. I am using the agent: 'chat-conversational-react-description'
What am I doing wrong?
class OrgSearchTool(BaseTool):
name = "Get Organization Details"
description = "Useful when searching for information about an organization or company for a give name and website."
def _run(self, name: str, website: str):
from api import search_org
r = search_org(name, website)
if len(r) > 4000:
r = r[:4000]
return r
def _arun(self, webpage: str):
raise NotImplementedError("This tool does not support async")
org_search = OrgSearchTool()
tools = [search, org_search]
That should be correct, it's just not compatible with the ZeroShotAgent. You could try the AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION
or the autogpt agent or write your own agent though.
Multi-argument / structured tools are a recent feature, so the older agents wouldn't know how to use them
Thanks for your help. It is not working as expected with AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION
As it does not use my API even when I prompt it otherwise by modifying the template.
I have downgraded langchain to v0.0.147 for now.
I am still getting an error when I try to use agents.
The code I run is from the langchain Quickstart Guide (Agents)
from langchain.agents import load_tools
from langchain.agents import initialize_agent
from langchain.agents import AgentType
from langchain.llms import OpenAI
llm = OpenAI(temperature=0)
tools = load_tools(["serpapi", "llm-math"], llm=llm)
agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
agent.run("What was the high temperature in SF yesterday in Fahrenheit? What is that number raised to the .023 power?")
And then I get the following error:
ValueError Traceback (most recent call last)
Cell In[48], line 11
7 tools = load_tools(["serpapi", "llm-math"], llm=llm)
10 # Finally, let's initialize an agent with the tools, the language model, and the type of agent we want to use.
---> 11 agent = initialize_agent(tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
13 # print(tools)
14
15 # Now let's test it out!
16 # agent.run("What was the lowest temperature in Mississauga yesterday in Celsius? What is that number squared")
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/langchain/agents/initialize.py:52, in initialize_agent(tools, llm, agent, callback_manager, agent_path, agent_kwargs, **kwargs)
50 agent_cls = AGENT_TO_CLASS[agent]
51 agent_kwargs = agent_kwargs or {}
---> 52 agent_obj = agent_cls.from_llm_and_tools(
53 llm, tools, callback_manager=callback_manager, **agent_kwargs
54 )
55 elif agent_path is not None:
56 agent_obj = load_agent(
57 agent_path, llm=llm, tools=tools, callback_manager=callback_manager
58 )
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/langchain/agents/mrkl/base.py:101, in ZeroShotAgent.from_llm_and_tools(cls, llm, tools, callback_manager, output_parser, prefix, suffix, format_instructions, input_variables, **kwargs)
87 @classmethod
88 def from_llm_and_tools(
89 cls,
(...)
98 **kwargs: Any,
99 ) -> Agent:
100 """Construct an agent from an LLM and tools."""
--> 101 cls._validate_tools(tools)
102 prompt = cls.create_prompt(
103 tools,
104 prefix=prefix,
(...)
107 input_variables=input_variables,
108 )
109 llm_chain = LLMChain(
110 llm=llm,
111 prompt=prompt,
112 callback_manager=callback_manager,
113 )
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/langchain/agents/mrkl/base.py:125, in ZeroShotAgent._validate_tools(cls, tools)
123 @classmethod
124 def _validate_tools(cls, tools: Sequence[BaseTool]) -> None:
--> 125 super()._validate_tools(tools)
126 for tool in tools:
127 if tool.description is None:
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/langchain/agents/agent.py:459, in Agent._validate_tools(cls, tools)
457 for tool in tools:
458 if not tool.is_single_input:
--> 459 raise ValueError(
460 f"{cls.__name__} does not support multi-input tool {tool.name}."
461 )
ValueError: ZeroShotAgent does not support multi-input tool Calculator.
I tried downgrading to the older version @Pouyanpi mentioned; it still didn't work.
I checked the history release of the repo, and I did not see any release that fixed this specific issue (#3700)
Did anyone figure this out yet?
Just so I'm clear, there's no way to use an agent right now that can use both multiinput and single-input tools right? It has to be all one or the other?
Having the same issue, any solution without downgrading?
Same issue as @tirthb described for me, 0.0.147 downgrade seems to work.
Just so I'm clear, there's no way to use an agent right now that can use both multiinput and single-input tools right? It has to be all one or the other?
All agents can use single input tools. Only newer agents can use multi-input tools right now
@okonma01 could you share your version info for this package? I can't reproduce that error on the getting started doc you've shared with any of the recent versions of langchain
Looking at the new StructuredTool docs helped me, if anyone hasn't seen those yet. I am moving my tools to use that class, which has worked well so far.
I don't quite understand why the multi-input tools are supposed to not work with the older agents. They were working before, and are still working fine with this quick hack that just turns the validation into a no-op:
from langchain.agents.conversational_chat.base import ConversationalChatAgent
ConversationalChatAgent._validate_tools = lambda *_, **__: ...
Out of curiosity @vowelparrot, why do you say that they don't work? The new structured tools look cool, but afaict I can't use them yet, since my use case requires a chat agent with a conversation history, and the only new structured tool STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION
doesn't support chat history.
Same question here, how do you use the structured tool to wrap the ConversationalChatAgent so that it can also be passed with the chat_history
?
I am seeing this issue in the latest version (langchain==0.0.216). Why was this issue closed?
>>> agent = initialize_agent(tools, chat_llm, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/rb013z/venvs/hackathon39/lib/python3.9/site-packages/langchain/agents/initialize.py", line 57, in initialize_agent
agent_obj = agent_cls.from_llm_and_tools(
File "/Users/rb013z/venvs/hackathon39/lib/python3.9/site-packages/langchain/agents/chat/base.py", line 112, in from_llm_and_tools
cls._validate_tools(tools)
File "/Users/rb013z/venvs/hackathon39/lib/python3.9/site-packages/langchain/agents/chat/base.py", line 62, in _validate_tools
validate_tools_single_input(class_name=cls.__name__, tools=tools)
File "/Users/rb013z/venvs/hackathon39/lib/python3.9/site-packages/langchain/agents/utils.py", line 10, in validate_tools_single_input
raise ValueError(
ValueError: ChatAgent does not support multi-input tool calculate_discount.
EDIT: It looks like using a different AgentType works.
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION
Yes - we're recommending the use of newer agents that are compatible over making changes to older agents
Got it. As a new user, it was not immediately clear which agents were the right ones to use. Maybe the old ones should print a deprecation warning if they are used?
Good point. Thanks for raising! I think we'll work on some doc chart and/or model cards to communicate this better. I'm not sure we want to act like we're deprecating the old agents since they work fine depending on the use case
As a LangChain newcomer, I just got hit by this one as well.
The tools documentation shows examples of multi-input tools without mentioning agent types (e.g. here).
I am seeing this issue in the latest version (langchain==0.0.216). Why was this issue closed?
>>> agent = initialize_agent(tools, chat_llm, agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION, verbose=True) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/rb013z/venvs/hackathon39/lib/python3.9/site-packages/langchain/agents/initialize.py", line 57, in initialize_agent agent_obj = agent_cls.from_llm_and_tools( File "/Users/rb013z/venvs/hackathon39/lib/python3.9/site-packages/langchain/agents/chat/base.py", line 112, in from_llm_and_tools cls._validate_tools(tools) File "/Users/rb013z/venvs/hackathon39/lib/python3.9/site-packages/langchain/agents/chat/base.py", line 62, in _validate_tools validate_tools_single_input(class_name=cls.__name__, tools=tools) File "/Users/rb013z/venvs/hackathon39/lib/python3.9/site-packages/langchain/agents/utils.py", line 10, in validate_tools_single_input raise ValueError( ValueError: ChatAgent does not support multi-input tool calculate_discount.
EDIT: It looks like using a different AgentType works.
agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION
As @tirthb mentioned, zero shot has no memory. "chat-conversational-react-description" and those alike need to have support for multi input tools.