forked from Archives/langchain
parent
d9fcc45d05
commit
8ef7274ee6
@ -160,3 +160,9 @@ Below is a list of all supported tools and relevant information:
|
||||
- Notes: A connection to the OpenWeatherMap API (https://api.openweathermap.org), specifically the `/data/2.5/weather` endpoint.
|
||||
- Requires LLM: No
|
||||
- Extra Parameters: `openweathermap_api_key` (your API key to access this endpoint)
|
||||
|
||||
**sleep**
|
||||
|
||||
- Tool Name: Sleep
|
||||
- Tool Description: Make agent sleep for some time.
|
||||
- Requires LLM: No
|
||||
|
@ -34,6 +34,7 @@ from langchain.tools.requests.tool import (
|
||||
from langchain.tools.scenexplain.tool import SceneXplainTool
|
||||
from langchain.tools.searx_search.tool import SearxSearchResults, SearxSearchRun
|
||||
from langchain.tools.shell.tool import ShellTool
|
||||
from langchain.tools.sleep.tool import SleepTool
|
||||
from langchain.tools.wikipedia.tool import WikipediaQueryRun
|
||||
from langchain.tools.wolfram_alpha.tool import WolframAlphaQueryRun
|
||||
from langchain.tools.openweathermap.tool import OpenWeatherMapQueryRun
|
||||
@ -82,6 +83,10 @@ def _get_terminal() -> BaseTool:
|
||||
return ShellTool()
|
||||
|
||||
|
||||
def _get_sleep() -> BaseTool:
|
||||
return SleepTool()
|
||||
|
||||
|
||||
_BASE_TOOLS: Dict[str, Callable[[], BaseTool]] = {
|
||||
"python_repl": _get_python_repl,
|
||||
"requests": _get_tools_requests_get, # preserved for backwards compatability
|
||||
@ -91,6 +96,7 @@ _BASE_TOOLS: Dict[str, Callable[[], BaseTool]] = {
|
||||
"requests_put": _get_tools_requests_put,
|
||||
"requests_delete": _get_tools_requests_delete,
|
||||
"terminal": _get_terminal,
|
||||
"sleep": _get_sleep,
|
||||
}
|
||||
|
||||
|
||||
|
1
langchain/tools/sleep/__init__.py
Normal file
1
langchain/tools/sleep/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
"""Sleep tool."""
|
44
langchain/tools/sleep/tool.py
Normal file
44
langchain/tools/sleep/tool.py
Normal file
@ -0,0 +1,44 @@
|
||||
"""Tool for agent to sleep."""
|
||||
from asyncio import sleep as asleep
|
||||
from time import sleep
|
||||
from typing import Optional, Type
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from langchain.callbacks.manager import (
|
||||
AsyncCallbackManagerForToolRun,
|
||||
CallbackManagerForToolRun,
|
||||
)
|
||||
from langchain.tools.base import BaseTool
|
||||
|
||||
|
||||
class SleepInput(BaseModel):
|
||||
"""Input for CopyFileTool."""
|
||||
|
||||
sleep_time: int = Field(..., description="Time to sleep in seconds")
|
||||
|
||||
|
||||
class SleepTool(BaseTool):
|
||||
"""Tool that adds the capability to sleep."""
|
||||
|
||||
name = "sleep"
|
||||
args_schema: Type[BaseModel] = SleepInput
|
||||
description = "Make agent sleep for a specified number of seconds."
|
||||
|
||||
def _run(
|
||||
self,
|
||||
sleep_time: int,
|
||||
run_manager: Optional[CallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the Sleep tool."""
|
||||
sleep(sleep_time)
|
||||
return f"Agent slept for {sleep_time} seconds."
|
||||
|
||||
async def _arun(
|
||||
self,
|
||||
sleep_time: int,
|
||||
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
||||
) -> str:
|
||||
"""Use the sleep tool asynchronously."""
|
||||
await asleep(sleep_time)
|
||||
return f"Agent slept for {sleep_time} seconds."
|
Loading…
Reference in New Issue
Block a user