Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Improve error handling in LLM API calls by appending exception messages to LLMException. This change enhances the clarity of error logs in both utils.py and service.py, facilitating better debugging and traceability.
Magnus Müllerd998e95ac06c
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex bdbcaaf7f..ebadf50c7 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -1115,7 +1115,7 @@ class Agent(Generic[Context]):response = {'raw': output, 'parsed': None}except Exception as e:self.logger.error(f'Failed to invoke model: {str(e)}')- raise LLMException(401, 'LLM API call failed') from e+ raise LLMException(401, 'LLM API call failed' + str(e)) from e# TODO: currently invoke does not return reasoning_content, we should override invokeoutput.content = self._remove_think_tags(str(output.content))try:@@ -1901,7 +1901,7 @@ class Agent(Generic[Context]):response = await self.settings.planner_llm.ainvoke(planner_messages)except Exception as e:self.logger.error(f'Failed to invoke planner: {str(e)}')- raise LLMException(401, 'LLM API call failed') from e+ raise LLMException(401, 'LLM API call failed' + str(e)) from eplan = str(response.content)# if deepseek-reasoner, remove think tagsdiff --git a/browser_use/utils.py b/browser_use/utils.pyindex 92485484c..16e0abe48 100644--- a/browser_use/utils.py+++ b/browser_use/utils.py@@ -560,7 +560,7 @@ def handle_llm_error(e: Exception) -> tuple[dict[str, Any], Any | None]:# If it's not a recognized error type, log and raiselogger.error(f'Failed to invoke model: {str(e)}')- raise LLMException(401, 'LLM API call failed') from e+ raise LLMException(401, 'LLM API call failed' + str(e)) from e@cache