Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BaseTool.run does not pass kwargs to the actual function call #28114

Open
5 tasks done
kapicic opened this issue Nov 14, 2024 · 1 comment
Open
5 tasks done

BaseTool.run does not pass kwargs to the actual function call #28114

kapicic opened this issue Nov 14, 2024 · 1 comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core investigate

Comments

@kapicic
Copy link

kapicic commented Nov 14, 2024

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

from langchain_core.tools import StructuredTool


def print_input_and_kwargs(input: str, **kwargs) -> None:
    print(f"Input: {input}")
    print(f"Kwargs: {kwargs}")


tool = StructuredTool.from_function(
    func=print_input_and_kwargs,
    name="print_input_and_kwargs",
    description="Print the input and kwargs.",
)

tool.run(
    "Hello, world!", kwarg1="First keyword argument.", kwarg2="Second keyword argument."
)

Actual

# Input: Hello, world!
# Kwargs: {}

Expected

# Input: Hello, world!
# Kwargs: {"kwarg1": "First keyword argument.", "kwarg2": "Second keyword argument."}

Error Message and Stack Trace (if applicable)

No response

Description

I am using langchain to create custom tools.
The tools are using kwargs to pass some data.
BaseTool.run accepts **kwargs as an argument and the docs clearly state:
kwargs: Additional arguments to pass to the tool

I expect that if I pass any kwargs to tool.run they will be available for me to use inside the function, which they are NOT.

System Info

System Information

OS: Darwin
OS Version: Darwin Kernel Version 23.5.0: Wed May 1 20:12:58 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6000
Python Version: 3.12.3 (main, Apr 9 2024, 08:09:14) [Clang 15.0.0 (clang-1500.3.9.4)]

Package Information

langchain_core: 0.2.23
langchain: 0.2.7
langchain_community: 0.2.7
langsmith: 0.1.85
langchain_anthropic: 0.1.19
langchain_google_community: 1.0.6
langchain_google_genai: 1.0.7
langchain_groq: 0.1.6
langchain_mistralai: 0.1.10
langchain_openai: 0.1.17
langchain_text_splitters: 0.2.2
langchainhub: 0.1.20

Packages not installed (Not Necessarily a Problem)

The following packages were not found:

langgraph
langserve

@langcarl langcarl bot added the investigate label Nov 14, 2024
@dosubot dosubot bot added Ɑ: core Related to langchain-core 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Nov 14, 2024
@keenborder786
Copy link
Contributor

keenborder786 commented Nov 16, 2024

I guess the Docstring for BaseTool need a little bit clarification but you can achieve your behaviour using the following code:

def print_input_and_kwargs(input: str, additional_kwargs:dict) -> None:
    print(f"Input: {input}")
    print(f"Kwargs: {additional_kwargs}")


tool = StructuredTool.from_function(
    func=print_input_and_kwargs,
    name="print_input_and_kwargs",
    description="Print the input and kwargs.",
)

tool.run(
    tool_input = {"input":"Hello, world!", "additional_kwargs": {"kwarg1":"First keyword argument.", "kwarg2":"Second keyword argument."}}
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: core Related to langchain-core investigate
Projects
None yet
Development

No branches or pull requests

2 participants