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
improve force done message
Magnus Müllere06f87c1ad98
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 3ab83df9e..52d24d5a4 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -882,9 +882,8 @@ class Agent(Generic[Context, AgentStructuredOutput]):"""Handle special processing for the last step"""if step_info and step_info.is_last_step():# Add last step warning if needed- msg = 'Now comes your last step. Use only the "done" action now. No other actions - so here your action sequence must have length 1.'+ msg = 'You reached max_steps - this is your last step. Your only tool available is the "done" tool. No other tool is available. All other tools which you see in history or examples are not available.'msg += '\nIf the task is not yet fully finished as requested by the user, set success in "done" to false! E.g. if not all steps are fully completed.'- msg += '\nIf the task is fully finished, set success in "done" to true.'msg += '\nInclude everything you found out for the ultimate task in the done text.'self.logger.debug('Last step finishing up')self._message_manager._add_context_message(UserMessage(content=msg))@@ -894,10 +893,10 @@ class Agent(Generic[Context, AgentStructuredOutput]):"""Force done after failure"""# Create recovery messageif self.state.consecutive_failures >= self.settings.max_failures and self.settings.final_response_after_failure:- msg = f'You have failed {self.settings.max_failures} consecutive times. This is your final step to complete the task or provide what you found. '- msg += 'Use only the "done" action now. No other actions - so here your action sequence must have length 1.'- msg += '\nIf the task could not be completed due to the failures, set success in "done" to false!'- msg += '\nInclude everything you found out for the task in the done text.'+ msg = f'You failed {self.settings.max_failures} times. Therefore we terminate the agent.'+ msg += 'Your only tool available is the "done" tool. No other tool is available. All other tools which you see in history or examples are not available.'+ msg += '\nIf the task is not yet fully finished as requested by the user, set success in "done" to false! E.g. if not all steps are fully completed.'+ msg += '\nInclude everything you found out for the ultimate task in the done text.'self.logger.debug('Force done action, because we reached max_failures.')self._message_manager._add_context_message(UserMessage(content=msg))