From fe84a9af76d0d2dfb9a2cbce1022a4f725802bfc Mon Sep 17 00:00:00 2001 From: Erick Friis Date: Thu, 19 Dec 2024 11:17:51 -0500 Subject: [PATCH] core: dont mutate tool_kwargs during tool run --- libs/core/langchain_core/tools/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/core/langchain_core/tools/base.py b/libs/core/langchain_core/tools/base.py index ff264edac3284..802240665033d 100644 --- a/libs/core/langchain_core/tools/base.py +++ b/libs/core/langchain_core/tools/base.py @@ -684,9 +684,9 @@ def run( context.run(_set_config_context, child_config) tool_args, tool_kwargs = self._to_args_and_kwargs(tool_input, tool_call_id) if signature(self._run).parameters.get("run_manager"): - tool_kwargs["run_manager"] = run_manager + tool_kwargs = tool_kwargs | {"run_manager": run_manager} if config_param := _get_runnable_config_param(self._run): - tool_kwargs[config_param] = config + tool_kwargs = tool_kwargs | {config_param: config} response = context.run(self._run, *tool_args, **tool_kwargs) if self.response_format == "content_and_artifact": if not isinstance(response, tuple) or len(response) != 2: