Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

increase default consecutive failure to 5

Saurav Panda33831f2b1216
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index 12ee404c2..46056195c 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -167,7 +167,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
use_vision: bool | Literal['auto'] = True,
save_conversation_path: str | Path | None = None,
save_conversation_path_encoding: str | None = 'utf-8',
- max_failures: int = 3,
+ max_failures: int = 5,
override_system_message: str | None = None,
extend_system_message: str | None = None,
generate_gif: bool | str = False,
@@ -1185,8 +1185,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# Record executed actions for loop detection
self._update_loop_detector_actions()
- # check for action errors - increment on any step where the last result has an error
- if self.state.last_result and self.state.last_result[-1].error:
+ # check for action errors - count the whole step as 1 failure if any action in the step errored
+ if self.state.last_result and any(r.error for r in self.state.last_result):
self.state.consecutive_failures += 1
self.logger.debug(f'🔄 Step {self.state.n_steps}: Consecutive failures: {self.state.consecutive_failures}')
return
diff --git a/browser_use/agent/views.py b/browser_use/agent/views.py
index bb8726fe6..b73afc5e1 100644
--- a/browser_use/agent/views.py
+++ b/browser_use/agent/views.py
@@ -62,7 +62,7 @@ class AgentSettings(BaseModel):
vision_detail_level: Literal['auto', 'low', 'high'] = 'auto'
save_conversation_path: str | Path | None = None
save_conversation_path_encoding: str | None = 'utf-8'
- max_failures: int = 3
+ max_failures: int = 5
generate_gif: bool | str = False
override_system_message: str | None = None
extend_system_message: str | None = None