diff --git a/libs/prebuilt/langgraph/prebuilt/tool_node.py b/libs/prebuilt/langgraph/prebuilt/tool_node.py index c4645800ee..025a5f666d 100644 --- a/libs/prebuilt/langgraph/prebuilt/tool_node.py +++ b/libs/prebuilt/langgraph/prebuilt/tool_node.py @@ -249,29 +249,6 @@ class ToolNode(RunnableCallable): Tool calls can also be passed directly as a list of `ToolCall` dicts. - Args: - tools: A sequence of tools that can be invoked by this node. Tools can be - BaseTool instances or plain functions that will be converted to tools. - name: The name identifier for this node in the graph. Used for debugging - and visualization. Defaults to "tools". - tags: Optional metadata tags to associate with the node for filtering - and organization. Defaults to None. - handle_tool_errors: Configuration for error handling during tool execution. - Defaults to True. Supports multiple strategies: - - - True: Catch all errors and return a ToolMessage with the default - error template containing the exception details. - - str: Catch all errors and return a ToolMessage with this custom - error message string. - - tuple[type[Exception], ...]: Only catch exceptions of the specified - types and return default error messages for them. - - Callable[..., str]: Catch exceptions matching the callable's signature - and return the string result of calling it with the exception. - - False: Disable error handling entirely, allowing exceptions to propagate. - - messages_key: The key in the state dictionary that contains the message list. - This same key will be used for the output ToolMessages. Defaults to "messages". - Example: Basic usage with simple tools: @@ -334,11 +311,26 @@ def __init__( """Initialize the ToolNode with the provided tools and configuration. Args: - tools: Sequence of tools to make available for execution. - name: Node name for graph identification. - tags: Optional metadata tags. - handle_tool_errors: Error handling configuration. - messages_key: State key containing messages. + tools: A sequence of tools that can be invoked by this node. Tools can be + BaseTool instances or plain functions that will be converted to tools. + name: The name identifier for this node in the graph. Used for debugging + and visualization. Defaults to "tools". + tags: Optional metadata tags to associate with the node for filtering + and organization. Defaults to None. + handle_tool_errors: Configuration for error handling during tool execution. + Defaults to True. Supports multiple strategies: + + - True: Catch all errors and return a ToolMessage with the default + error template containing the exception details. + - str: Catch all errors and return a ToolMessage with this custom + error message string. + - tuple[type[Exception], ...]: Only catch exceptions of the specified + types and return default error messages for them. + - Callable[..., str]: Catch exceptions matching the callable's signature + and return the string result of calling it with the exception. + - False: Disable error handling entirely, allowing exceptions to propagate. + messages_key: The key in the state dictionary that contains the message list. + This same key will be used for the output ToolMessages. Defaults to "messages". """ super().__init__(self._func, self._afunc, name=name, tags=tags, trace=False) self.tools_by_name: dict[str, BaseTool] = {} @@ -867,12 +859,6 @@ class InjectedState(InjectedToolArg): receive state data automatically during execution while remaining invisible to the model's tool-calling interface. - Args: - field: Optional key to extract from the state dictionary. If None, the entire - state is injected. If specified, only that field's value is injected. - This allows tools to request specific state components rather than - processing the full state structure. - Example: ```python from typing import List @@ -930,6 +916,14 @@ def foo_tool(x: int, foo: Annotated[str, InjectedState("foo")]) -> str: """ # noqa: E501 def __init__(self, field: Optional[str] = None) -> None: + """Initialize InjectedState annotation. + + Args: + field: Optional key to extract from the state dictionary. If None, the entire + state is injected. If specified, only that field's value is injected. + This allows tools to request specific state components rather than + processing the full state structure. + """ self.field = field diff --git a/libs/prebuilt/langgraph/prebuilt/tool_validator.py b/libs/prebuilt/langgraph/prebuilt/tool_validator.py index e5f0937273..0c4b9e7a5a 100644 --- a/libs/prebuilt/langgraph/prebuilt/tool_validator.py +++ b/libs/prebuilt/langgraph/prebuilt/tool_validator.py @@ -62,18 +62,6 @@ class ValidationNode(RunnableCallable): structured output that conforms to a complex schema without losing the original messages and tool IDs (for use in multi-turn conversations). - Args: - schemas: A list of schemas to validate the tool calls with. These can be - any of the following: - - A pydantic BaseModel class - - A BaseTool instance (the args_schema will be used) - - A function (a schema will be created from the function signature) - format_error: A function that takes an exception, a ToolCall, and a schema - and returns a formatted error string. By default, it returns the - exception repr and a message to respond after fixing validation errors. - name: The name of the node. - tags: A list of tags to add to the node. - Returns: (Union[Dict[str, List[ToolMessage]], Sequence[ToolMessage]]): A list of ToolMessages with the validated content or error messages. @@ -140,6 +128,20 @@ def __init__( name: str = "validation", tags: Optional[list[str]] = None, ) -> None: + """Initialize the ValidationNode. + + Args: + schemas: A list of schemas to validate the tool calls with. These can be + any of the following: + - A pydantic BaseModel class + - A BaseTool instance (the args_schema will be used) + - A function (a schema will be created from the function signature) + format_error: A function that takes an exception, a ToolCall, and a schema + and returns a formatted error string. By default, it returns the + exception repr and a message to respond after fixing validation errors. + name: The name of the node. + tags: A list of tags to add to the node. + """ super().__init__(self._func, None, name=name, tags=tags, trace=False) self._format_error = format_error or _default_format_error self.schemas_by_name: Dict[str, Type[BaseModel]] = {}