Source code for tools.wait_tool

"""Wait for a specified number of seconds before continuing."""

import asyncio
import json
import logging

logger = logging.getLogger(__name__)

MAX_WAIT_SECONDS = 60

TOOL_NO_BACKGROUND = True
TOOL_ALLOW_REPEAT = True
TOOL_NAME = "wait"
TOOL_DESCRIPTION = (
    "Pause execution for a specified duration (0.1 to 60 seconds). "
    "Useful for rate limiting, waiting for external processes, or "
    "adding delays between operations."
)
TOOL_PARAMETERS = {
    "type": "object",
    "properties": {
        "seconds": {
            "type": "number",
            "description": "Number of seconds to wait (0.1 to 60).",
        },
    },
    "required": ["seconds"],
}


[docs] async def run(seconds: float = 1.0, **_kwargs) -> str: """Execute this tool and return the result. Args: seconds (float): The seconds value. Returns: str: Result string. """ if seconds is None: return json.dumps({"error": "seconds parameter is required"}) try: seconds = float(seconds) except (TypeError, ValueError): return json.dumps({"error": "seconds must be a number"}) if seconds < 0: return json.dumps({"error": "seconds cannot be negative"}) if seconds > MAX_WAIT_SECONDS: logger.warning("Wait time %ss exceeds maximum, clamping to %ss", seconds, MAX_WAIT_SECONDS) seconds = MAX_WAIT_SECONDS if seconds < 0.1: seconds = 0.1 logger.info("Waiting for %s seconds...", seconds) await asyncio.sleep(seconds) return json.dumps({"success": True, "waited_seconds": seconds})