From b0b6e3d91f277f43cf4637727df16634496ef57e Mon Sep 17 00:00:00 2001 From: "open-swe[bot]" Date: Fri, 22 Aug 2025 12:34:26 +0000 Subject: [PATCH] Apply patch [skip ci] --- libs/prebuilt/langgraph/prebuilt/tool_node.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/libs/prebuilt/langgraph/prebuilt/tool_node.py b/libs/prebuilt/langgraph/prebuilt/tool_node.py index d4940045c..70bbb16a2 100644 --- a/libs/prebuilt/langgraph/prebuilt/tool_node.py +++ b/libs/prebuilt/langgraph/prebuilt/tool_node.py @@ -1028,6 +1028,46 @@ def _is_injection( return False +def _get_reserved_keyword_args(tool: BaseTool) -> dict[str, str]: + """Extract reserved keyword arguments from tool function signature. + + This function inspects the tool's underlying function signature to identify + parameters with reserved names ('state' and 'runtime') that should be injected + automatically without requiring annotations. + + Args: + tool: The tool to analyze for reserved keyword parameters. + + Returns: + A dictionary mapping reserved parameter names to their injection type. + Keys are parameter names, values are either 'state' or 'runtime'. + """ + reserved_args = {} + + # Get the underlying function from the tool + if hasattr(tool, 'func'): + func = tool.func + elif hasattr(tool, '_run'): + func = tool._run + else: + return reserved_args + + # Inspect the function signature + try: + sig = inspect.signature(func) + for param_name, param in sig.parameters.items(): + # Check for reserved keywords + if param_name == 'state': + reserved_args['state'] = 'state' + elif param_name == 'runtime': + reserved_args['runtime'] = 'runtime' + except (ValueError, TypeError): + # If we can't inspect the signature, return empty + pass + + return reserved_args + + def _get_state_args(tool: BaseTool) -> dict[str, Optional[str]]: """Extract state injection mappings from tool annotations. @@ -1103,3 +1143,4 @@ def _get_store_arg(tool: BaseTool) -> Optional[str]: return None +