Convert Python functions and Runnables to LangChain tools.
Can be used as a decorator with or without arguments to create tools from functions.
Functions can have any signature - the tool will automatically infer input schemas unless disabled.
Runnable, a string name must be provided.tool(
name_or_callable: str | Callable | None = None,
runnable: Runnable | None = None,
*args: Any = (),
description: str | None = None,
return_direct: bool = False,
args_schema: ArgsSchema | None = None,
infer_schema: bool = True,
response_format: Literal['content', 'content_and_artifact'] = 'content',
parse_docstring: bool = False,
error_on_invalid_docstring: bool = True,
extras: dict[str, Any] | None = None
) -> BaseTool | Callable[[Callable | Runnable], BaseTool]| Name | Type | Description |
|---|---|---|
name_or_callable | str | Callable | None | Default: NoneOptional name of the tool or the Overrides the function's name. Must be provided as a positional argument. |
runnable | Runnable | None | Default: NoneOptional Must be provided as a positional argument. |
description | str | None | Default: NoneOptional description for the tool. Precedence for the tool description value is as follows:
|
*args | Any | Default: ()Extra positional arguments. Must be empty. |
return_direct | bool | Default: FalseWhether to return directly from the tool rather than continuing the agent loop. |
args_schema | ArgsSchema | None | Default: NoneOptional argument schema for user to specify. |
infer_schema | bool | Default: TrueWhether to infer the schema of the arguments from the function's signature. This also makes the resultant tool accept a dictionary input to its |
response_format | Literal['content', 'content_and_artifact'] | Default: 'content'The tool response format. If If |
parse_docstring | bool | Default: FalseIf |
error_on_invalid_docstring | bool | Default: TrueIf |
extras | dict[str, Any] | None | Default: NoneOptional provider-specific extra fields for the tool. Used to pass configuration that doesn't fit into standard tool fields. Chat models should process known extras when constructing model payloads. Example For example, Anthropic-specific fields like |