| 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: None |
*args | Any | Default: () |
return_direct | bool | Default: False |
args_schema | ArgsSchema | None | Default: None |
infer_schema | bool | Default: True |
response_format | Literal['content', 'content_and_artifact'] | Default: 'content' |
parse_docstring | bool | Default: False |
error_on_invalid_docstring | bool | Default: True |
extras | dict[str, Any] | None | Default: None |
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.Optional description for the tool.
Precedence for the tool description value is as follows:
description argument (used even if docstring and/or args_schema
are provided)args_schema is provided)args_schema description (used only if description and docstring are
not provided)Extra positional arguments.
Must be empty.
Whether to return directly from the tool rather than continuing the agent loop.
Optional argument schema for user to specify.
Whether to infer the schema of the arguments from the function's signature.
This also makes the resultant tool accept a dictionary input to its run()
function.
The tool response format.
If 'content', then the output of the tool is interpreted as the contents
of a ToolMessage.
If 'content_and_artifact', then the output is expected to be a two-tuple
corresponding to the (content, artifact) of a ToolMessage.
If infer_schema and parse_docstring, will attempt to
parse parameter descriptions from Google Style function docstrings.
If parse_docstring is provided, configure
whether to raise ValueError on invalid Google Style docstrings.
Optional 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.
For example, Anthropic-specific fields like cache_control,
defer_loading, or input_examples.