langchain.tools.base.tool¶
langchain.tools.base.tool(*args: Union[str, Callable, Runnable], return_direct: bool = False, args_schema: Optional[Type[BaseModel]] = None, infer_schema: bool = True) → Callable[source]¶
Make tools out of functions, can be used with or without arguments.
Parameters
*args – The arguments to the tool.
return_direct – Whether to return directly from the tool rather
than continuing the agent loop.
args_schema – optional argument schema for user to specify
infer_schema – 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.
Requires:
Function must be of type (str) -> str
Function must have a docstring
Examples
@tool
def search_api(query: str) -> str:
    # Searches the API for the query.
    return
@tool("search", return_direct=True)
def search_api(query: str) -> str:
    # Searches the API for the query.
    return
Examples using tool¶
Metaphor Search
LLMonitor
JSONFormer
Agent Trajectory
Agents
!pip install bs4
Defining Custom Tools
XML Agent