Closed Punisheroot closed 1 year ago
Ran into similar problem.
The issue seems to be that BaseTool
class subclasses pydantic BaseModel
:
@root_validator()
in AgentExecutor
, e.g., validate_tools
, hence the KeyError
. See here for more details on root validation.@root_validator()
decorators, you'll probably get a more informative message as to why pydantic validation is failing.Config
of BaseTool
. @Punisheroot
Issue resolved for me. Try running your custom tool with the following env:
langchain==0.0.162
openapi-schema-pydantic==1.2.4
pydantic==1.10.7
@Punisheroot
Issue resolved for me. Try running your custom tool with the following env:
langchain==0.0.162 openapi-schema-pydantic==1.2.4 pydantic==1.10.7
Hi @jeromeku i tried but still the same error π’ The only one tool that have a root_validator is this:
class QueryCheckerTool(BaseMongoDBDatabaseTool, BaseTool):
"""Use an LLM to check if a MongoDB query is correct."""
template: str = QUERY_CHECKER
llm: BaseLLM
llm_chain: LLMChain = Field(init=False)
name = "query_checker_mongodb_db"
description = """
Use this tool to double check if your MongoDB query is correct before executing it.
Always use this tool before executing a query with query_mongodb_db!
"""
@root_validator(pre=True)
def initialize_llm_chain(cls, values: Dict[str, Any]) -> Dict[str, Any]:
if "llm_chain" not in values:
values["llm_chain"] = LLMChain(
llm=values.get("llm"),
prompt=PromptTemplate(
template=QUERY_CHECKER, input_variables=["query"]
),
)
if values["llm_chain"].prompt.input_variables != ["query"]:
raise ValueError(
"LLM chain for QueryCheckerTool must have input variables ['query']"
)
return values
def _run(self, query: str) -> str:
"""Use the LLM to check the MongoDB query."""
return self.llm_chain.predict(query=query)
async def _arun(self, query: str) -> str:
return await self.llm_chain.apredict(query=query)
commenting root validator I get this error
Traceback (most recent call last):
File "...\test.py", line 92, in <module>
agent = create_mongodb_agent(llm=llm, toolkit=toolkit, verbose=True)
File "...\mongodb\agent.py", line 32, in create_mongodb_agent
tools = toolkit.get_tools()
File "...\mongodb\toolkit.py", line 36, in get_tools
QueryCheckerTool(db=self.db, llm=self.llm),
File "pydantic\main.py", line 341, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for QueryCheckerTool
llm_chain
field required (type=value_error.missing)
Hi, @Punisheroot! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.
Based on my understanding of the current state of the issue, the problem is that the AgentExecutor
validator is throwing a KeyError
for the 'tools' key. You verified that the tools are being passed correctly to the AgentExecutor.from_agent_and_tools
function. User jeromeku
suggested that the issue may be related to the BaseTool
class subclassing pydantic BaseModel
and provided some suggestions for resolving the issue. However, you tried the suggested solution but still encountered the same error. You also provided additional details about the specific tool that has a root_validator
and the error you received when commenting out the root_validator
.
Now, we would like to know if this issue is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or the issue will be automatically closed in 7 days.
Thank you for your understanding and cooperation!
@Punisheroot How well did your custom chain work?
Hi, I am in the process of developing an agent and a toolkit to query mongodb databases, and to do this I simulated SQL Database Agent code with implementations for mongodb, I created this function to create the agent:
and this is my ToolKit:
but I get the error from the AgentExecutor validator:
I did some debugging and verified that the tools are passed correctly to the AgentExecutor.from_agent_and_tools function. Can anyone help me with this?