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
Enhance agent state representation and update system prompt documentation
Magnus Müller18a97acf7627
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.pyindex 260c1b247..27f43d7bb 100644--- a/browser_use/agent/message_manager/service.py+++ b/browser_use/agent/message_manager/service.py@@ -310,7 +310,7 @@ class MessageManager:)self._add_message_with_tokens(example_tool_call_1, message_type='init')self.add_tool_message(- content='Data written to todo.md. \nData written to github.md. \n Clicked element with index 4. </example_1>',+ content='Data written to todo.md. \nData written to github.md.\nClicked element with index 4. </example_1>',message_type='init',)diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.pyindex d477f7dbc..3b8e6573c 100644--- a/browser_use/agent/prompts.py+++ b/browser_use/agent/prompts.py@@ -134,22 +134,26 @@ Interactive elements from top layer of the current page inside the viewport{truntodo_contents = '[Current todo.md is empty, fill it with your plan when applicable]'agent_state = f"""# Agent State\n-## USER REQUEST:+<user_request>+ ## USER REQUEST:{self.task}\n+</user_request>+<file_system>## File System:{self.file_system.describe()}\n## Contents of todo.md:{todo_contents}\n+</file_system>## Step Info:{step_info_description}"""return agent_statedef get_user_message(self, use_vision: bool = True) -> HumanMessage:- state_description = self.agent_history_description + '\n'- state_description += self._get_agent_state_description() + '\n'- state_description += self._get_browser_state_description() + '\n'- state_description += self.read_state_description + '\n'+ state_description = '<agent_history>' + self.agent_history_description + '</agent_history>\n'+ state_description += '<agent_state>' + self._get_agent_state_description() + '</agent_state>\n'+ state_description += '<browser_state>' + self._get_browser_state_description() + '</browser_state>\n'+ state_description += '<read_state>' + self.read_state_description + '</read_state>\n'if self.page_filtered_actions:state_description += 'For this page, these additional actions are available:\n'state_description += self.page_filtered_actions + '\n'diff --git a/browser_use/agent/system_prompt.md b/browser_use/agent/system_prompt.mdindex 10ee33817..6b701b445 100644--- a/browser_use/agent/system_prompt.md+++ b/browser_use/agent/system_prompt.md@@ -163,7 +163,7 @@ Exhibit the following reasoning patterns:- `evaluation_previous_goal`, `memory`, and `next_goal` fields are how you leave traceable progress for the next step.- Each should be short, informative, concrete and specific. This is the information that will be visible to the user and you later.- Reason carefully about the most relevant next action.-- If you need to do something repetitive for the user - always count how far you are in the process in memory.+- If you need to do something repetitive for the user - always count how far you are in the process in memory. (Not the step number, but e.g. 32/74 pages visited)6. **Before Calling `done`**- Verify completeness—e.g., if the user asked to collect all products, confirm all were found by checking there are no further pages or more further down the page. Verify that you found the right number of items.@@ -177,7 +177,7 @@ You must ALWAYS respond with a valid JSON in this exact format:"current_state": {{"thinking": "A long and structured <think>-style reasoning block that applies the <reasoning_rules> provided above.""evaluation_previous_goal": "One-sentence analysis of your last action. Clearly state success, failure, or uncertain.",- "memory": "1-3 sentences of specific memory of this step. You should put here everything that will help you track progress in future steps. Like counting.",+ "memory": "1-3 sentences of specific memory of this step. You should put here everything that will help you track progress in future steps. Like counting pages visited, items found, etc.","next_goal": "State the next immediate goal and the action to achieve it, in one clear sentence."}}"action":[{{"one_action_name": {{// action-specific parameter}}}}, // ... more actions in sequence]