Error with ZeroShotAgent using multi-input tool 'Calculator' in LangChain #25910
Replies: 1 comment 2 replies
-
Hello, @berkbirkan! I'm here to help you with your Langchain issue. Let's work together to get this sorted out. I found a similar closed issue that addresses the "ZeroShotAgent does not support multi-input tool Calculator" error. The suggested solution is to use a version of LangChain that does not have this restriction. Specifically, installing version pip install --force-reinstall -v langchain==v0.0.147 However, since you are using a more recent version, you might want to consider using a different agent that supports multi-input tools or modifying your tool to accept a single input in a structured format. Updated Example CodeHere is an updated version of your code using the from langchain_openai.chat_models import ChatOpenAI
from langchain_core.tools import StructuredTool
from langchain_core.pydantic_v1 import BaseModel, Field
from langchain.agents import create_tool_calling_agent, AgentExecutor
# Define the Calculator tool
class CalculatorInput(BaseModel):
a: int = Field(description="first number")
b: int = Field(description="second number")
def multiply(a: int, b: int) -> int:
"""Multiply two numbers."""
return a * b
calculator = StructuredTool.from_function(
func=multiply,
name="Calculator",
description="multiply numbers",
args_schema=CalculatorInput,
return_direct=True,
)
# Create the agent
llm = ChatOpenAI(temperature=0)
tools = [calculator]
# Create the tool calling agent
agent = create_tool_calling_agent(llm, tools)
# Create an agent executor
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
# Use the agent
result = agent_executor.invoke({"input": "Multiply 2 and 3"})
print(result) This code uses the For more information on creating and using multi-input tools with different agents, you can refer to the LangChain documentation [1]. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Checked other resources
Commit to Help
Example Code
Description
Hello. I am new to Langchain and AI agents in general. I wanted to run the examples (for custom tools and ai agents) in the Langchain documentation on my own computer in order to improve myself. But I am getting the error below. I could not fix it. I would be very happy if you could help me, thank you.
Script :
Error :
System Info
System Information
Package Information
Optional packages not installed
Other Dependencies
Beta Was this translation helpful? Give feedback.
All reactions