From 7c2bed2c73b147de2d700e145c7099c4035ad821 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 16 Nov 2025 14:16:23 -0500 Subject: [PATCH] fix: UserValves contamination between multiple tools Co-Authored-By: Daniel Pots <3932988+podden@users.noreply.github.com> --- backend/open_webui/utils/tools.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/open_webui/utils/tools.py b/backend/open_webui/utils/tools.py index f493f5bf65..fb623ed332 100644 --- a/backend/open_webui/utils/tools.py +++ b/backend/open_webui/utils/tools.py @@ -237,14 +237,16 @@ async def get_tools( module, _ = load_tool_module_by_id(tool_id) request.app.state.TOOLS[tool_id] = module - extra_params["__id__"] = tool_id + __user__ = { + **extra_params["__user__"], + } # Set valves for the tool if hasattr(module, "valves") and hasattr(module, "Valves"): valves = Tools.get_tool_valves_by_id(tool_id) or {} module.valves = module.Valves(**valves) if hasattr(module, "UserValves"): - extra_params["__user__"]["valves"] = module.UserValves( # type: ignore + __user__["valves"] = module.UserValves( # type: ignore **Tools.get_user_valves_by_id_and_user_id(tool_id, user.id) ) @@ -266,7 +268,12 @@ async def get_tools( function_name = spec["name"] tool_function = getattr(module, function_name) callable = get_async_tool_function_and_apply_extra_params( - tool_function, extra_params + tool_function, + { + **extra_params, + "__id__": tool_id, + "__user__": __user__, + }, ) # TODO: Support Pydantic models as parameters