langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Allowed tools (set()) different than provided tools error - all/most Agent examples broken?

Open francisjervis opened this issue 2 years ago β€’ 6 comments

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.

francisjervis avatar May 02 '23 07:05 francisjervis

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.

whiteking64 avatar May 02 '23 14:05 whiteking64

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.

exiao avatar May 02 '23 20:05 exiao

same error here

MichaelMDowling avatar May 02 '23 21:05 MichaelMDowling

Same. Reverting to 0.0.154 resolves.

givingbacksmiles avatar May 02 '23 21:05 givingbacksmiles

Same here. Thanks for the tip about reverting to 0.0.154

rishni-firstthing-ai avatar May 03 '23 01:05 rishni-firstthing-ai

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)

trironkk avatar May 03 '23 05:05 trironkk

This is resolved by https://github.com/hwchase17/langchain/pull/4014

francisjervis avatar May 03 '23 20:05 francisjervis

How to update? I'm still version 0.0.156

14790897 avatar May 05 '23 09:05 14790897

How to update? I'm still version 0.0.156

!python -m pip install --upgrade langchain

MichaelMDowling avatar May 05 '23 09:05 MichaelMDowling

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

14790897 avatar May 05 '23 09:05 14790897