langchain
langchain copied to clipboard
How to pass multiple arguments to tool?
Issue you'd like to raise.
Hi I want to pass multiple arguments to a tool, that was created using @tool
decorator. E.g.:
@tool
def test(query: str, smth: str) -> str:
"""description"""
return "test"
tools = [
lambda query, smth: test(query, smth)
]
initialize_agent(tools...)
I'm getting an error. In the example in the docs , it is shown that agent decides what to pass, but I don't want such a behavior, I want ability to pass arguments myself along with a query.
Suggestion:
No response
We have a similar need to be able to be able to load a document from a vector store based on your user input in one of the tools. Unable to find any docs on if an agent can be configured to have Tools that have multiple input PromptTemplates.
@abhinav-rafa Hi! For anyone who is interested, I was able to pass a custom arguments using Tool
class, like this:
tools = [
Tool(
name="Internet search",
func=lambda query, custom=custom: str(search_from_internet(query, custom)),
description="useful when user's query was not answered by database and performing Internet search is necessary"
)
]
@mzhadigerov Thank you for the pointer!
Still there is an issue. For example, Let say my custom tool takes 3 input parameters: [input1, input2,input3] :-> bool, str, int
How to feed these inputs to the agent who is using thes tool? Usually we run agent like agent.run('string'). But is there any way to do like agent.run({'input1: input1, 'input2': input2, 'input3': input3}) ?
where you able to get this to work ?
what about passing as single array of inputs ?
I used StructuredTool.from_function for single and multi parameters. You will need to use agent = initialize_agent( tools, llm2, agent=AgentType.STRUCTURED_CHAT_ZERO_SHOT_REACT_DESCRIPTION, memory=memory, verbose=True, ) Reference Documentation: https://python.langchain.com/docs/modules/agents/tools/multi_input_tool
Hi, @mzhadigerov,
I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, the issue you raised involved passing multiple arguments to a tool created using the @tool
decorator, and you encountered an error when attempting to pass arguments along with a query. You responded with a solution using the Tool
class to pass custom arguments, and other users also discussed potential solutions, including using StructuredTool.from_function
for single and multi parameters.
Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!
description = 'Use this tool with arguments like "{{"start_date": "yyyy-mm-dd", "max_results": int}}" when you need to retrieve events"
@ozkit Thanks your comment helped me. I am getting inputs and string and now i can change it to dict and read keys.
Such a saver! Thank you @ozkit