|
15 | 15 | from app.tool.base import BaseTool, ToolResult |
16 | 16 | from app.tool.web_search import WebSearch |
17 | 17 |
|
18 | | - |
19 | 18 | _BROWSER_DESCRIPTION = """\ |
20 | 19 | A powerful browser automation tool that allows interaction with web pages through various actions. |
21 | 20 | * This tool provides commands for controlling a browser session, navigating web pages, and extracting information |
@@ -151,15 +150,20 @@ def _classify_error(self, error: Exception) -> tuple[str, str]: |
151 | 150 | error_str = str(error) |
152 | 151 |
|
153 | 152 | # Check for Playwright initialization errors |
154 | | - if any(phrase in error_str for phrase in [ |
155 | | - "BrowserType.launch", |
156 | | - "Executable doesn't exist", |
157 | | - "playwright install", |
158 | | - "Browser binary not found", |
159 | | - ]): |
160 | | - return ("INIT_FAILED", |
161 | | - "Browser initialization failed. Browser engine not available. " |
162 | | - "Try using 'web_search' tool instead to search for information.") |
| 153 | + if any( |
| 154 | + phrase in error_str |
| 155 | + for phrase in [ |
| 156 | + "BrowserType.launch", |
| 157 | + "Executable doesn't exist", |
| 158 | + "playwright install", |
| 159 | + "Browser binary not found", |
| 160 | + ] |
| 161 | + ): |
| 162 | + return ( |
| 163 | + "INIT_FAILED", |
| 164 | + "Browser initialization failed. Browser engine not available. " |
| 165 | + "Try using 'web_search' tool instead to search for information.", |
| 166 | + ) |
163 | 167 |
|
164 | 168 | # Check for operation errors |
165 | 169 | return ("OPERATION_FAILED", f"Browser action failed: {error_str}") |
@@ -258,7 +262,9 @@ async def execute( |
258 | 262 | return ToolResult(error=error_msg) |
259 | 263 | else: |
260 | 264 | # Other initialization errors |
261 | | - return ToolResult(error=f"Browser initialization failed: {str(init_error)}") |
| 265 | + return ToolResult( |
| 266 | + error=f"Browser initialization failed: {str(init_error)}" |
| 267 | + ) |
262 | 268 |
|
263 | 269 | # Get max content length from config |
264 | 270 | max_content_length = getattr( |
@@ -514,7 +520,9 @@ async def execute( |
514 | 520 | if error_type == "INIT_FAILED": |
515 | 521 | return ToolResult(error=error_msg) |
516 | 522 | else: |
517 | | - return ToolResult(error=f"Browser action '{action}' failed: {error_msg}") |
| 523 | + return ToolResult( |
| 524 | + error=f"Browser action '{action}' failed: {error_msg}" |
| 525 | + ) |
518 | 526 |
|
519 | 527 | async def get_current_state( |
520 | 528 | self, context: Optional[BrowserContext] = None |
|
0 commit comments