Files
langchain-python/langchain/agents/tools.py
T
Leonid Ganeline 17956ff08e docstrings agents (#7866)
Added/Updated docstrings for `agents`
@baskaryan
2023-07-18 02:23:24 -07:00

35 lines
993 B
Python

"""Interface for tools."""
from typing import Optional
from langchain.callbacks.manager import (
AsyncCallbackManagerForToolRun,
CallbackManagerForToolRun,
)
from langchain.tools.base import BaseTool, Tool, tool
class InvalidTool(BaseTool):
"""Tool that is run when invalid tool name is encountered by agent."""
name = "invalid_tool"
"""Name of the tool."""
description = "Called when tool name is invalid."
"""Description of the tool."""
def _run(
self, tool_name: str, run_manager: Optional[CallbackManagerForToolRun] = None
) -> str:
"""Use the tool."""
return f"{tool_name} is not a valid tool, try another one."
async def _arun(
self,
tool_name: str,
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
) -> str:
"""Use the tool asynchronously."""
return f"{tool_name} is not a valid tool, try another one."
__all__ = ["InvalidTool", "BaseTool", "tool", "Tool"]