Create tool from a given function.
A classmethod that helps to create a tool from a function.
from_function(
cls,
func: Callable | None = None,
coroutine: Callable[..., Awaitable[Any]] | None = None,
name: str | None = None,
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 = False,
**kwargs: Any = {}
) -> StructuredTool| Name | Type | Description |
|---|---|---|
func | Callable | None | Default: NoneThe function from which to create a tool. |
coroutine | Callable[..., Awaitable[Any]] | None | Default: NoneThe async function from which to create a tool. |
name | str | None | Default: NoneThe name of the tool. Defaults to the function name. |
description | str | None | Default: NoneThe description of the tool. Defaults to the function docstring. |
return_direct | bool | Default: FalseWhether to return the result directly or as a callback. |
args_schema | ArgsSchema | None | Default: NoneThe schema of the tool's input arguments. |
infer_schema | bool | Default: TrueWhether to infer the schema from the function's signature. |
response_format | Literal['content', 'content_and_artifact'] | Default: 'content'The tool response format. If |
parse_docstring | bool | Default: FalseIf |
error_on_invalid_docstring | bool | Default: Falseif |
**kwargs | Any | Default: {}Additional arguments to pass to the tool |