From d411013b6f9d4d436698672f105162f3fe5f0138 Mon Sep 17 00:00:00 2001 From: "open-swe[bot]" Date: Fri, 22 Aug 2025 12:37:24 +0000 Subject: [PATCH] Apply patch [skip ci] --- libs/prebuilt/langgraph/prebuilt/tool_node.py | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libs/prebuilt/langgraph/prebuilt/tool_node.py b/libs/prebuilt/langgraph/prebuilt/tool_node.py index 6592a2f27..d967c4604 100644 --- a/libs/prebuilt/langgraph/prebuilt/tool_node.py +++ b/libs/prebuilt/langgraph/prebuilt/tool_node.py @@ -664,6 +664,44 @@ class ToolNode(RunnableCallable): } return tool_call + def _inject_runtime( + self, + tool_call: ToolCall, + store: Optional[BaseStore], + config: RunnableConfig, + ) -> ToolCall: + """Inject runtime object into tool call arguments. + + This method creates and injects a Runtime object containing store and + context into tools that have a 'runtime' reserved keyword parameter. + + Args: + tool_call: The tool call dictionary to augment with runtime. + store: The persistent store instance to include in runtime. + config: The runnable configuration containing context. + + Returns: + The tool call with runtime injected if needed. + """ + runtime_arg = self.tool_to_runtime_arg[tool_call["name"]] + if not runtime_arg: + return tool_call + + # Create a Runtime object with store and context from config + # The context will be available from the config if set + runtime = Runtime( + context=config.get("configurable", {}).get("context"), + store=store, + stream_writer=lambda _: None, # Default no-op stream writer + previous=None, + ) + + tool_call["args"] = { + **tool_call["args"], + runtime_arg: runtime, + } + return tool_call + def inject_tool_args( self, tool_call: ToolCall, @@ -1179,3 +1217,4 @@ def _get_runtime_arg(tool: BaseTool) -> Optional[str]: +