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
Update service.py
Matic Zavadlal41e7be6865ae
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex e5a2e873c..f7918a126 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -8,7 +8,6 @@ from pathlib import Pathfrom typing import Any, Awaitable, Callable, Dict, Generic, List, Optional, Type, TypeVarfrom dotenv import load_dotenv-from google.api_core.exceptions import ResourceExhaustedfrom langchain_core.language_models.chat_models import BaseChatModelfrom langchain_core.messages import (BaseMessage,@@ -17,7 +16,6 @@ from langchain_core.messages import ()# from lmnr.sdk.decorators import observe-from openai import RateLimitErrorfrom pydantic import BaseModel, ValidationErrorfrom browser_use.agent.gif import create_history_gif@@ -384,14 +382,18 @@ class Agent(Generic[Context]):# give model a hint how output should look likeerror_msg += '\n\nReturn a valid JSON object with the required fields.'- self.state.consecutive_failures += 1- elif isinstance(error, RateLimitError) or isinstance(error, ResourceExhausted):- logger.warning(f'{prefix}{error_msg}')- await asyncio.sleep(self.settings.retry_delay)self.state.consecutive_failures += 1else:- logger.error(f'{prefix}{error_msg}')- self.state.consecutive_failures += 1+ from google.api_core.exceptions import ResourceExhausted+ from openai import RateLimitError++ if isinstance(error, RateLimitError) or isinstance(error, ResourceExhausted):+ logger.warning(f'{prefix}{error_msg}')+ await asyncio.sleep(self.settings.retry_delay)+ self.state.consecutive_failures += 1+ else:+ logger.error(f'{prefix}{error_msg}')+ self.state.consecutive_failures += 1return [ActionResult(error=error_msg, include_in_memory=True)]@@ -498,7 +500,7 @@ class Agent(Generic[Context]):return False, False- @observe(name='agent.run', ignore_output=True)+ # @observe(name='agent.run', ignore_output=True)async def run(self, max_steps: int = 100) -> AgentHistoryList:"""Execute the task with maximum number of steps"""try: