(self, msg: str)
| 1407 | |
| 1408 | @extension.extensible |
| 1409 | async def process_tools(self, msg: str): |
| 1410 | # search for tool usage requests in agent message |
| 1411 | tool_request = extract_tools.json_parse_dirty(msg) |
| 1412 | |
| 1413 | raw_tool_name = "" |
| 1414 | tool_args = {} |
| 1415 | |
| 1416 | # Only validate when extraction produced an object; None means no JSON tool |
| 1417 | # block was found - the misformat warning path below handles that. |
| 1418 | if tool_request is not None: |
| 1419 | try: |
| 1420 | raw_tool_name, tool_args = extract_tools.normalize_tool_request( |
| 1421 | tool_request |
| 1422 | ) |
| 1423 | except ValueError: |
| 1424 | tool_request = None # treat structural validation errors as misformat |
| 1425 | |
| 1426 | if tool_request is not None: |
| 1427 | tool_name = raw_tool_name # Initialize tool_name with raw_tool_name |
| 1428 | tool_method = None # Initialize tool_method |
| 1429 | |
| 1430 | tool = None # Initialize tool to None |
| 1431 | |
| 1432 | # Try getting tool from MCP first |
| 1433 | try: |
| 1434 | import helpers.mcp_handler as mcp_helper |
| 1435 | |
| 1436 | mcp_tool_candidate = mcp_helper.MCPConfig.get_instance().get_tool( |
| 1437 | self, tool_name |
| 1438 | ) |
| 1439 | if mcp_tool_candidate: |
| 1440 | tool = mcp_tool_candidate |
| 1441 | except ImportError: |
| 1442 | PrintStyle( |
| 1443 | background_color="black", font_color="yellow", padding=True |
| 1444 | ).print("MCP helper module not found. Skipping MCP tool lookup.") |
| 1445 | except Exception as e: |
| 1446 | PrintStyle( |
| 1447 | background_color="black", font_color="red", padding=True |
| 1448 | ).print(f"Failed to get MCP tool '{tool_name}': {e}") |
| 1449 | |
| 1450 | # Fallback to local get_tool if MCP tool was not found or MCP lookup failed |
| 1451 | if not tool: |
| 1452 | tool = self.get_tool( |
| 1453 | name=tool_name, |
| 1454 | method=tool_method, |
| 1455 | args=tool_args, |
| 1456 | message=msg, |
| 1457 | loop_data=self.loop_data, |
| 1458 | ) |
| 1459 | |
| 1460 | if tool: |
| 1461 | self.loop_data.current_tool = tool # type: ignore |
| 1462 | try: |
| 1463 | await self.handle_intervention() |
| 1464 | |
| 1465 | # Call tool hooks for compatibility |
| 1466 | await tool.before_execution(**tool_args) |
no test coverage detected