mirror of
https://github.com/Mintplex-Labs/langchain-python.git
synced 2026-07-23 17:56:16 -04:00
17956ff08e
Added/Updated docstrings for `agents` @baskaryan
35 lines
993 B
Python
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"]
|