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 type safety and clarify task completion instructions
Magnus Müllerac07642b6cb7
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.pyindex 363e062d8..78aaf5e39 100644--- a/browser_use/agent/service.py+++ b/browser_use/agent/service.py@@ -914,15 +914,15 @@ class Agent(Generic[Context]):]if not self.settings.use_vision_for_planner and self.settings.use_vision:- last_state_message = planner_messages[-1]+ last_state_message: HumanMessage = planner_messages[-1]# remove image from last state messagenew_msg = ''if isinstance(last_state_message.content, list):for msg in last_state_message.content:- if msg['type'] == 'text':- new_msg += msg['text']- elif msg['type'] == 'image_url':- continue+ if msg['type'] == 'text': # type: ignore+ new_msg += msg['text'] # type: ignore+ elif msg['type'] == 'image_url': # type: ignore+ continue # type: ignoreelse:new_msg = last_state_message.contentdiff --git a/browser_use/agent/system_prompt.md b/browser_use/agent/system_prompt.mdindex cd6f37d68..e70ae4952 100644--- a/browser_use/agent/system_prompt.md+++ b/browser_use/agent/system_prompt.md@@ -49,10 +49,10 @@ Common action sequences:5. TASK COMPLETION:- Use the done action as the last action as soon as the ultimate task is complete- Dont use "done" before you are done with everything the user asked you, except you reach the last step of max_steps.-- If you reach the max_steps, use the done action even you are not finished and provide all the information you have gathered so far. If the ultimate task is not completed yet set success to false, only if fully completed set success to true.+- If you reach your last step, use the done action even if the task is not fully finished. Provide all the information you have gathered so far. If the ultimate task is completly finished set success to true. If not everything the user asked for is completed set success in done to false!- If you have to do something repeatedly for example the task says for "each", or "for all", or "x times", count always inside "memory" how many times you have done it and how many remain. Don't stop until you have completed like the task asked you. Only call done after the last step.- Don't hallucinate actions-- Make sure to include everything the user asked for in the done text parameter. This is what the user will see. Do not just say you are done, but include the requested information of the task.+- Make sure you include everything you found out for the ultimate task in the done text parameter. Do not just say you are done, but include the requested information of the task.6. VISUAL CONTEXT:- When an image is provided, use it to understand the page layoutdiff --git a/browser_use/controller/service.py b/browser_use/controller/service.pyindex 05bb50e27..a1ec1f131 100644--- a/browser_use/controller/service.py+++ b/browser_use/controller/service.py@@ -48,7 +48,7 @@ class Controller(Generic[Context]):success: bool = True@self.registry.action(- 'Complete task - with return text and if the ultimate task is reached (success=True) or not finished(success=False)',+ 'Complete task - with return text and if the task is finished (success=True) or not yet completly finished (success=False), because last step is reached',param_model=ExtendedOutputModel,)async def done(params: ExtendedOutputModel):@@ -58,7 +58,7 @@ class Controller(Generic[Context]):else:@self.registry.action(- 'Complete task - with return text and if the ultimate task is reached (success=True) or not finished (success=False)',+ 'Complete task - with return text and if the task is finished (success=True) or not yet completly finished (success=False), because last step is reached',param_model=DoneAction,)async def done(params: DoneAction):