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
Merge remote-tracking branch 'origin/HEAD' into fix/issue-1716-event-driven-pause-resume
Magnus Müller0e44eb1d3d49
diff --cc browser_use/agent/service.pyindex 23ef82d84,e2d3b1b52..53d9ced60--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@@ -474,11 -434,10 +434,11 @@@ class Agent(Generic[Context, AgentStrucself.has_downloads_path = self.browser_session.browser_profile.downloads_path is not Noneif self.has_downloads_path:self._last_known_downloads: list[str] = []- self.logger.info('📁 Initialized download tracking for agent')+ self.logger.debug('📁 Initialized download tracking for agent')- self._external_pause_event = asyncio.Event()- self._external_pause_event.set()+ # Event-based pause control (kept out of AgentState for serialization)+ self._pause_event = asyncio.Event()+ self._pause_event.set()@propertydef logger(self) -> logging.Logger:@@@ -1244,14 -1447,16 +1452,16 @@@self.logger.debug(f'🔄 Starting main execution loop with max {max_steps} steps...')for step in range(max_steps):- # Replace the polling with clean pause-wait+ # Use the consolidated pause state managementif self.state.paused:self.logger.debug(f'⏸️ Step {step}: Agent paused, waiting to resume...')- await self.wait_until_resumed()+ await self._pause_event.wait()signal_handler.reset()- # Check if we should stop due to too many failures- if self.state.consecutive_failures >= self.settings.max_failures:+ # Check if we should stop due to too many failures, if final_response_after_failure is True, we try one last time+ if (self.state.consecutive_failures) >= self.settings.max_failures + int(+ self.settings.final_response_after_failure+ ):self.logger.error(f'❌ Stopping due to {self.settings.max_failures} consecutive failures')agent_run_error = f'Stopped due to {self.settings.max_failures} consecutive failures'breakdiff --cc browser_use/agent/views.pyindex 933b0aed7,8de986114..89d89cb2d--- a/browser_use/agent/views.py+++ b/browser_use/agent/views.py@@@ -78,10 -61,10 +63,12 @@@ class AgentState(BaseModel)last_result: list[ActionResult] | None = Nonelast_plan: str | None = Nonelast_model_output: AgentOutput | None = None++ # Pause/resume state (kept serialisable for checkpointing)paused: bool = Falsestopped: bool = False+ session_initialized: bool = False # Track if session events have been dispatched+ follow_up_task: bool = False # Track if the agent is a follow-up taskmessage_manager_state: MessageManagerState = Field(default_factory=MessageManagerState)file_system_state: FileSystemState | None = None