core: dont mutate tool_kwargs during tool run (#28824)

fixes https://github.com/langchain-ai/langchain/issues/24621
This commit is contained in:
Erick Friis
2024-12-19 10:11:56 -08:00
committed by GitHub
parent 033ac41760
commit 6a37899b39
2 changed files with 19 additions and 2 deletions

View File

@@ -2268,3 +2268,20 @@ def test_tool_return_output_mixin() -> None:
assert foo.invoke(
{"type": "tool_call", "args": {"x": 0}, "name": "foo", "id": "bar"}
) == Bar(x=0)
def test_tool_mutate_input() -> None:
class MyTool(BaseTool):
name: str = "MyTool"
description: str = "a tool"
def _run(
self,
x: str,
run_manager: Optional[CallbackManagerForToolRun] = None,
) -> str:
return "hi"
my_input = {"x": "hi"}
MyTool().invoke(my_input)
assert my_input == {"x": "hi"}