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
Move self.state.last_model_output = model_output up otherwise we dont safe it in the case of an error
Magnus Müller475e757d6a05
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex fdb30769a..31bf8264d 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -721,7 +721,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):retry_messages = input_messages + [clarification_message]model_output = await self.get_next_action(retry_messages)-+ self.state.last_model_output = model_outputif not model_output.action or all(action.model_dump() == {} for action in model_output.action):self.logger.warning('Model still returned empty after retry. Inserting safe noop action.')action_instance = self.ActionModel()@@ -785,7 +785,6 @@ class Agent(Generic[Context, AgentStructuredOutput]):self.logger.debug(f'✅ Step {self.state.n_steps}: Actions completed')self.state.last_result = result- self.state.last_model_output = model_output# Check for new downloads after executing actionsif self.has_downloads_path:@@ -1328,7 +1327,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):check_for_new_elements: bool = True,) -> list[ActionResult]:"""Execute multiple actions"""- results = []+ results: list[ActionResult] = []assert self.browser_session is not None, 'BrowserSession is not set up'cached_selector_map = await self.browser_session.get_selector_map()