Call a tool by name with optional timeout Args: name: Tool name input: Input for the tool timeout: Timeout in seconds for this specific call (overrides default_timeout if provided) Returns: ToolResponse: Tool resul
(self,
name: str,
input: Dict[str, Any],
timeout: Optional[float] = None,
ctx: SessionContext = None,
**kwargs
)
| 1247 | ) |
| 1248 | |
| 1249 | async def __call__(self, |
| 1250 | name: str, |
| 1251 | input: Dict[str, Any], |
| 1252 | timeout: Optional[float] = None, |
| 1253 | ctx: SessionContext = None, |
| 1254 | **kwargs |
| 1255 | ) -> ToolResponse: |
| 1256 | """Call a tool by name with optional timeout |
| 1257 | |
| 1258 | Args: |
| 1259 | name: Tool name |
| 1260 | input: Input for the tool |
| 1261 | timeout: Timeout in seconds for this specific call (overrides default_timeout if provided) |
| 1262 | |
| 1263 | Returns: |
| 1264 | ToolResponse: Tool result |
| 1265 | """ |
| 1266 | |
| 1267 | if ctx is None: |
| 1268 | ctx = SessionContext() |
| 1269 | |
| 1270 | tool_info = await self.get_info(name) |
| 1271 | |
| 1272 | version = tool_info.version |
| 1273 | tool_instance = tool_info.instance |
| 1274 | logger.info(f"| ✅ Using tool {name}@{version}") |
| 1275 | |
| 1276 | # Use provided timeout, or fall back to default_timeout |
| 1277 | effective_timeout = timeout if timeout is not None else self.default_timeout |
| 1278 | |
| 1279 | # Other tool args |
| 1280 | tool_kwargs = dict(ctx=ctx) |
| 1281 | |
| 1282 | # If timeout is None (no timeout), call tool directly |
| 1283 | if effective_timeout is None: |
| 1284 | return await tool_instance(**input, **tool_kwargs) |
| 1285 | |
| 1286 | # Otherwise, use asyncio.wait_for to enforce timeout |
| 1287 | try: |
| 1288 | return await asyncio.wait_for(tool_instance(**input, **tool_kwargs), timeout=effective_timeout) |
| 1289 | except asyncio.TimeoutError: |
| 1290 | error_msg = f"Tool '{name}' execution timed out after {effective_timeout} seconds" |
| 1291 | logger.error(f"| ⏱️ {error_msg}") |
| 1292 | return ToolResponse( |
| 1293 | success=False, |
| 1294 | message=error_msg, |
| 1295 | extra=None |
| 1296 | ) |
nothing calls this directly
no test coverage detected