Skip to content

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

Merge branch 'main' into fix/issue-1716-event-driven-pause-resume

Yash Solankid7a7d555e65d
diff --cc browser_use/agent/service.py
index 821ba7498,3633d464e..0a6ad2c0f
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@@ -1610,8 -1634,11 +1631,8 @@@ class Agent(Generic[Context, AgentStruc
"""Save the history to a file"""
if not file_path:
file_path = 'AgentHistory.json'
- self.state.history.save_to_file(file_path)
+ self.history.save_to_file(file_path)
- async def wait_until_resumed(self):
- await self._external_pause_event.wait()
-
def pause(self) -> None:
"""Pause the agent before the next step"""
print(
diff --cc browser_use/agent/views.py
index c67e4c427,0ee4eeb6d..6af10cac0
--- a/browser_use/agent/views.py
+++ b/browser_use/agent/views.py
@@@ -79,14 -75,9 +78,13 @@@ class AgentState(BaseModel)
n_steps: int = 1
consecutive_failures: int = 0
last_result: list[ActionResult] | None = None
- history: AgentHistoryList = Field(default_factory=lambda: AgentHistoryList(history=[], usage=None))
last_plan: str | None = None
last_model_output: AgentOutput | None = None
- paused: bool = False
+
+ # Consolidated pause/resume state management
+ # The pause_event serves as the single source of truth for pause state
+ # When set: agent is running, when cleared: agent is paused
+ pause_event: asyncio.Event = Field(default_factory=lambda: asyncio.Event(), exclude=True, repr=False)
stopped: bool = False
message_manager_state: MessageManagerState = Field(default_factory=MessageManagerState)