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
Refactor pause event handling in Agent class
Magnus Müllerf0ef506b9412
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 53d9ced60..a91d875fc 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -437,8 +437,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):self.logger.debug('📁 Initialized download tracking for agent')# Event-based pause control (kept out of AgentState for serialization)- self._pause_event = asyncio.Event()- self._pause_event.set()+ self._external_pause_event = asyncio.Event()+ self._external_pause_event.set()@propertydef logger(self) -> logging.Logger:@@ -1455,7 +1455,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):# Use the consolidated pause state managementif self.state.paused:self.logger.debug(f'⏸️ Step {step}: Agent paused, waiting to resume...')- await self._pause_event.wait()+ await self._external_pause_event.wait()signal_handler.reset()# Check if we should stop due to too many failures, if final_response_after_failure is True, we try one last time@@ -1917,7 +1917,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):'\n\n⏸️ Got [Ctrl+C], paused the agent and left the browser open.\n\tPress [Enter] to resume or [Ctrl+C] again to quit.')self.state.paused = True- self._pause_event.clear()+ self._external_pause_event.clear()# Task paused@@ -1929,7 +1929,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):print('----------------------------------------------------------------------')print('▶️ Got Enter, resuming agent execution where it left off...\n')self.state.paused = False- self._pause_event.set()+ self._external_pause_event.set()# Task resumed