langchain
langchain copied to clipboard
Allowed tools (set()) different than provided tools error - all/most Agent examples broken?
Since upgrading to 0.0.155, the following code does not work:
tool_names = [tool.name for tool in tools]
agent = LLMSingleActionAgent(
llm_chain=llm_chain,
output_parser=output_parser,
stop=["\nObservation:"],
allowed_tools=tool_names
)
The following error is raised in what was previously working code so this appears to be a breaking change:
pydantic.error_wrappers.ValidationError: 1 validation error for AgentExecutor
__root__
Allowed tools (set()) different than provided tools (['Tenant Rights Assistant', 'Lease Question Answerer', 'Building Database Query']) (type=value_error)
This makes no sense. Printing tool_names yields {'Tenant Rights Assistant', 'Lease Question Answerer', 'Building Database Query'} which is exactly the same as the list of provided tools - presumably, since this was copied directly from the example code with my own tools (again, previously working fine), this means the examples are also now non-functional.
I've encountered the same problem.
Actually in my case the error above occurs when calling AgentExecutor, where I put the agent for its argument.
When called the constructor, the following validator will be run: https://github.com/hwchase17/langchain/blob/3bd5a99b835fa320d02aa733cb0c0bc4a87724fa/langchain/agents/agent.py#L627-L637
Since LLMSingleActionAgent ALWAYS returns set() for get_allowed_tools(),
https://github.com/hwchase17/langchain/blob/3bd5a99b835fa320d02aa733cb0c0bc4a87724fa/langchain/agents/agent.py#L51-L52
the error occurs.
For workaround, right now I have to create a child class inherited from LLMSingleActionAgent, add a field for tools and override get_allowed_tools() function, which is very tedious.
In my opinion, an agent class does not need to know what tools are available and allowed in the first place. It's the role of other classes, like AgentExecutor. The validation should be modified or removed.
I am also receiving this error on the new version, with no changes in code, and am reverting to 0.0.154 in order to fix it.
same error here
Same. Reverting to 0.0.154 resolves.
Same here. Thanks for the tip about reverting to 0.0.154
i ran into this as well, working through this tutorial.
came to the same conclusion as the comment above.
in case it's useful, here's my workaround:
class CustomLLMSingleActionAgent(LLMSingleActionAgent):
allowed_tools: Sequence[str]
def __init__(self, *args, **kwargs):
super(CustomLLMSingleActionAgent, self).__init__(*args, **kwargs)
self.allowed_tools = kwargs['allowed_tools']
def get_allowed_tools(self) -> Set[str]:
return set(self.allowed_tools)
This is resolved by https://github.com/hwchase17/langchain/pull/4014
How to update? I'm still version 0.0.156
How to update? I'm still version 0.0.156
!python -m pip install --upgrade langchain
How to update? I'm still version 0.0.156ε¦δ½ζ΄ζ°οΌζθΏζ―0.0.156ηζ¬
!python -m pip install --upgrade langchain
Thank you, I'm glad you solved this problem that was bugging me all afternoon