langchain icon indicating copy to clipboard operation
langchain copied to clipboard

How to pass multiple arguments to tool?

Open mzhadigerov opened this issue 1 year ago • 3 comments

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

mzhadigerov avatar May 05 '23 21:05 mzhadigerov

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 avatar May 05 '23 22:05 abhinav-rafa

@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 avatar May 05 '23 22:05 mzhadigerov

@mzhadigerov Thank you for the pointer!

abhinav-rafa avatar May 05 '23 22:05 abhinav-rafa

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}) ?

shuvracse03 avatar Jun 11 '23 15:06 shuvracse03

where you able to get this to work ?

rdhillbb avatar Sep 04 '23 14:09 rdhillbb

what about passing as single array of inputs ?

rambabusure avatar Sep 10 '23 09:09 rambabusure

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

rdhillbb avatar Sep 10 '23 13:09 rdhillbb

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!

dosubot[bot] avatar Dec 10 '23 16:12 dosubot[bot]

description = 'Use this tool with arguments like "{{"start_date": "yyyy-mm-dd", "max_results": int}}" when you need to retrieve events"

ozkit avatar Mar 25 '24 15:03 ozkit

@ozkit Thanks your comment helped me. I am getting inputs and string and now i can change it to dict and read keys.

shubhamofbce avatar Apr 07 '24 13:04 shubhamofbce

Such a saver! Thank you @ozkit

Ortega-Dan avatar Apr 10 '24 18:04 Ortega-Dan