From 6952d3a1e00cb7ff4e5c4143c2af16dcfc878b85 Mon Sep 17 00:00:00 2001 From: "open-swe[bot]" Date: Fri, 22 Aug 2025 12:39:17 +0000 Subject: [PATCH] Apply patch [skip ci] --- libs/prebuilt/langgraph/prebuilt/tool_node.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/libs/prebuilt/langgraph/prebuilt/tool_node.py b/libs/prebuilt/langgraph/prebuilt/tool_node.py index d967c4604..a65bbf8ee 100644 --- a/libs/prebuilt/langgraph/prebuilt/tool_node.py +++ b/libs/prebuilt/langgraph/prebuilt/tool_node.py @@ -711,13 +711,15 @@ class ToolNode(RunnableCallable): BaseModel, ], store: Optional[BaseStore], + config: Optional[RunnableConfig] = None, ) -> ToolCall: - """Inject graph state and store into tool call arguments. + """Inject graph state, store, and runtime into tool call arguments. This method enables tools to access graph context that should not be controlled - by the model. Tools can declare dependencies on graph state or persistent storage - using InjectedState and InjectedStore annotations. This method automatically - identifies these dependencies and injects the appropriate values. + by the model. Tools can declare dependencies using either reserved keywords + ('state' and 'runtime') or annotations (InjectedState and InjectedStore for + backward compatibility). This method automatically identifies these dependencies + and injects the appropriate values. The injection process preserves the original tool call structure while adding the necessary context arguments. This allows tools to be both model-callable @@ -730,10 +732,11 @@ class ToolNode(RunnableCallable): Can be a message list, state dictionary, or BaseModel instance. store: The persistent store instance to inject into tools requiring storage. Will be None if no store is configured for the graph. + config: The runnable configuration containing context for runtime injection. Returns: A new ToolCall dictionary with the same structure as the input but with - additional arguments injected based on the tool's annotation requirements. + additional arguments injected based on the tool's requirements. Raises: ValueError: If a tool requires store injection but no store is provided, @@ -751,6 +754,9 @@ class ToolNode(RunnableCallable): tool_call_copy: ToolCall = copy(tool_call) tool_call_with_state = self._inject_state(tool_call_copy, input) tool_call_with_store = self._inject_store(tool_call_with_state, store) + if config: + tool_call_with_runtime = self._inject_runtime(tool_call_with_store, store, config) + return tool_call_with_runtime return tool_call_with_store def _validate_tool_command( @@ -1218,3 +1224,4 @@ def _get_runtime_arg(tool: BaseTool) -> Optional[str]: +