The input arguments’ schema.
The tool schema.
field coroutine: Optional[Callable[[...], Awaitable[Any]]] = None#
The asynchronous version of the function.
field description: str = ''#
Used to tell the model how/when/why to use the tool.
You can provide few-shot examples as a part of the description.
field func: Callable[[...], Any] [Required]#
The function to run when the tool is called.
classmethod from_function(func: Callable, name: Optional[str] = None, description: Optional[str] = None, return_direct: bool = False, args_schema: Optional[Type[pydantic.main.BaseModel]] = None, infer_schema: bool = True, **kwargs: Any) → langchain.tools.base.StructuredTool[source]#
Create tool from a given function.
A classmethod that helps to create a tool from a function.
Parameters
func – The function from which to create a tool
name – The name of the tool. Defaults to the function name
description – The description of the tool. Defaults to the function docstring
return_direct – Whether to return the result directly or as a callback
args_schema – The schema of the tool’s input arguments
infer_schema – Whether to infer the schema from the function’s signature
**kwargs – Additional arguments to pass to the tool
Returns
The tool
Examples
… code-block:: python
def add(a: int, b: int) -> int:“””Add two numbers”””
return a + b
tool = StructuredTool.from_function(add)
tool.run(1, 2) # 3
property args: dict#
The tool’s input arguments.
pydantic model langchain.tools.Tool[source]#
Tool that takes in function or coroutine directly.
rtdocs_stable/api.python.langchain.com/en/stable/reference/modules/tools.html