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
fix ruff errors in other files
Nick Sweeting8b165d59975a
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.pyindex 085adc6c3..fcd5125ad 100644--- a/browser_use/agent/message_manager/service.py+++ b/browser_use/agent/message_manager/service.py@@ -72,34 +72,36 @@ class MessageManager:example_tool_call = AIMessage(content='',- tool_calls=[{- 'name': 'AgentOutput',- 'args': {- 'current_state': {- 'evaluation_previous_goal': """+ tool_calls=[+ {+ 'name': 'AgentOutput',+ 'args': {+ 'current_state': {+ 'evaluation_previous_goal': """Success - I successfully clicked on the 'Apple' link from the Google Search results page,which directed me to the 'Apple' company homepage. This is a good start toward findingthe best place to buy a new iPhone as the Apple website often list iPhones for sale.""".strip(),- 'memory': """+ 'memory': """I searched for 'iPhone retailers' on Google. From the Google Search results page,I used the 'click_element' tool to click on a element labelled 'Best Buy' but callingthe tool did not direct me to a new page. I then used the 'click_element' tool to clickon a element labelled 'Apple' which redirected me to the 'Apple' company homepage.Currently at step 3/15.""".strip(),- 'next_goal': """+ 'next_goal': """Looking at reported structure of the current page, I can see the item '[127]<h3 iPhone/>'in the content. I think this button will lead to more information and potentially pricesfor iPhones. I'll click on the link to 'iPhone' at index [127] using the 'click_element'tool and hope to see prices on the next page.""".strip(),+ },+ 'action': [{'click_element': {'index': 127}}],},- 'action': [{'click_element': {'index': 127}}],+ 'id': str(self.state.tool_id),+ 'type': 'tool_call',},- 'id': str(self.state.tool_id),- 'type': 'tool_call',- },]+ ],)self._add_message_with_tokens(example_tool_call, message_type='init')self.add_tool_message(content='Browser started', message_type='init')diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 7d8ad34ed..f84d5d2ee 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -160,7 +160,6 @@ class Agent(Generic[Context]):self.llm = llmself.controller = controllerself.sensitive_data = sensitive_data-self.settings = AgentSettings(use_vision=use_vision,@@ -265,7 +264,7 @@ class Agent(Generic[Context]):)except ImportError:logger.warning(- "Memory functionality was enabled but required packages are not installed. "+ 'Memory functionality was enabled but required packages are not installed. '"Install with 'pip install browser-use[memory]' to use memory features.")self.memory = None@@ -846,25 +845,24 @@ class Agent(Generic[Context]):breakelse:error_message = 'Failed to complete task in maximum steps'-+self.state.history.history.append(AgentHistory(model_output=None,result=[ActionResult(error=error_message, include_in_memory=True)],state=BrowserStateHistory(- url="",- title="",+ url='',+ title='',tabs=[],interacted_element=[],screenshot=None,),- metadata=None+ metadata=None,))logger.info(f'❌ {error_message}')-return self.state.historyexcept KeyboardInterrupt:diff --git a/browser_use/agent/views.py b/browser_use/agent/views.pyindex 1e191c6ab..94bd6a307 100644--- a/browser_use/agent/views.py+++ b/browser_use/agent/views.py@@ -70,6 +70,7 @@ class AgentSettings(BaseModel):planner_interval: int = 1 # Run planner every N stepsis_planner_reasoning: bool = False # type: ignore+class AgentState(BaseModel):"""Holds all state information for an Agent"""diff --git a/examples/models/deepseek.py b/examples/models/deepseek.pyindex 072c0a192..eef76c131 100644--- a/examples/models/deepseek.py+++ b/examples/models/deepseek.py@@ -35,4 +35,4 @@ async def run_search():if __name__ == '__main__':- asyncio.run(run_search())\ No newline at end of file+ asyncio.run(run_search())diff --git a/examples/use-cases/web_voyager_agent.py b/examples/use-cases/web_voyager_agent.pyindex f57638211..ad06a4b66 100644--- a/examples/use-cases/web_voyager_agent.py+++ b/examples/use-cases/web_voyager_agent.py@@ -58,6 +58,7 @@ TASK = """Find and book a hotel in Paris with suitable accommodations for a family of four (two adults and two children) offering free cancellation for the dates of February 14-21, 2025. on https://www.booking.com/"""+async def main():agent = Agent(task=TASK,