Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Refactor message manager example generation and update system prompt tag

Cursor Agent411af73f2033
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.py
index ec3830e40..a9f225f6e 100644
--- a/browser_use/agent/message_manager/service.py
+++ b/browser_use/agent/message_manager/service.py
@@ -139,74 +139,42 @@ class MessageManager:
# placeholder_message = HumanMessage(content='Example output:')
self._add_message_with_type(placeholder_message, message_type='init')
+ # Create base example content
+ example_content = {
+ 'evaluation_previous_goal': 'Navigated to GitHub explore page. Verdict: Success',
+ 'memory': 'Found initial repositories such as bytedance/UI-TARS-desktop and ray-project/kuberay.',
+ 'next_goal': 'Create todo.md checklist to track progress, initialize github.md for collecting information, and click on bytedance/UI-TARS-desktop.',
+ 'action': [
+ {
+ 'write_file': {
+ 'path': 'todo.md',
+ 'content': '# Interesting Github Repositories in Explore Section\n\n## Tasks\n- [ ] Initialize a tracking file for GitHub repositories called github.md\n- [ ] Visit each Github repository and find their description\n- [ ] Visit bytedance/UI-TARS-desktop\n- [ ] Visit ray-project/kuberay\n- [ ] Check for additional Github repositories by scrolling down\n- [ ] Compile all results in the requested format\n- [ ] Validate that I have not missed anything in the page\n- [ ] Report final results to user',
+ }
+ },
+ {
+ 'write_file': {
+ 'path': 'github.md',
+ 'content': '# Github Repositories:\n',
+ }
+ },
+ {
+ 'click_element_by_index': {
+ 'index': 4,
+ }
+ },
+ ],
+ }
+
+ # Add thinking field only if use_thinking is True
if self.use_thinking:
- # Example with thinking field
- example_tool_call_1 = AssistantMessage(
- content=json.dumps(
- {
- 'thinking': """I have successfully navigated to https://github.com/explore and can see the page has loaded with a list of featured repositories. The page contains interactive elements and I can identify specific repositories like bytedance/UI-TARS-desktop (index [4]) and ray-project/kuberay (index [5]). The user's request is to explore GitHub repositories and collect information about them such as descriptions, stars, or other metadata. So far, I haven't collected any information.
+ example_content['thinking'] = """I have successfully navigated to https://github.com/explore and can see the page has loaded with a list of featured repositories. The page contains interactive elements and I can identify specific repositories like bytedance/UI-TARS-desktop (index [4]) and ray-project/kuberay (index [5]). The user's request is to explore GitHub repositories and collect information about them such as descriptions, stars, or other metadata. So far, I haven't collected any information.
My navigation to the GitHub explore page was successful. The page loaded correctly and I can see the expected content.
I need to capture the key repositories I've identified so far into my memory and into a file.
Since this appears to be a multi-step task involving visiting multiple repositories and collecting their information, I need to create a structured plan in todo.md.
After writing todo.md, I can also initialize a github.md file to accumulate the information I've collected.
-The file system actions do not change the browser state, so I can also click on the bytedance/UI-TARS-desktop (index [4]) to start collecting information.
-""",
- 'evaluation_previous_goal': 'Navigated to GitHub explore page. Verdict: Success',
- 'memory': 'Found initial repositories such as bytedance/UI-TARS-desktop and ray-project/kuberay.',
- 'next_goal': 'Create todo.md checklist to track progress, initialize github.md for collecting information, and click on bytedance/UI-TARS-desktop.',
- 'action': [
- {
- 'write_file': {
- 'path': 'todo.md',
- 'content': '# Interesting Github Repositories in Explore Section\n\n## Tasks\n- [ ] Initialize a tracking file for GitHub repositories called github.md\n- [ ] Visit each Github repository and find their description\n- [ ] Visit bytedance/UI-TARS-desktop\n- [ ] Visit ray-project/kuberay\n- [ ] Check for additional Github repositories by scrolling down\n- [ ] Compile all results in the requested format\n- [ ] Validate that I have not missed anything in the page\n- [ ] Report final results to user',
- }
- },
- {
- 'write_file': {
- 'path': 'github.md',
- 'content': '# Github Repositories:\n',
- }
- },
- {
- 'click_element_by_index': {
- 'index': 4,
- }
- },
- ],
- }
- )
- )
- else:
- # Example without thinking field
- example_tool_call_1 = AssistantMessage(
- content=json.dumps(
- {
- 'evaluation_previous_goal': 'Navigated to GitHub explore page. Verdict: Success',
- 'memory': 'Found initial repositories such as bytedance/UI-TARS-desktop and ray-project/kuberay.',
- 'next_goal': 'Create todo.md checklist to track progress, initialize github.md for collecting information, and click on bytedance/UI-TARS-desktop.',
- 'action': [
- {
- 'write_file': {
- 'path': 'todo.md',
- 'content': '# Interesting Github Repositories in Explore Section\n\n## Tasks\n- [ ] Initialize a tracking file for GitHub repositories called github.md\n- [ ] Visit each Github repository and find their description\n- [ ] Visit bytedance/UI-TARS-desktop\n- [ ] Visit ray-project/kuberay\n- [ ] Check for additional Github repositories by scrolling down\n- [ ] Compile all results in the requested format\n- [ ] Validate that I have not missed anything in the page\n- [ ] Report final results to user',
- }
- },
- {
- 'write_file': {
- 'path': 'github.md',
- 'content': '# Github Repositories:\n',
- }
- },
- {
- 'click_element_by_index': {
- 'index': 4,
- }
- },
- ],
- }
- )
- )
+The file system actions do not change the browser state, so I can also click on the bytedance/UI-TARS-desktop (index [4]) to start collecting information."""
+ example_tool_call_1 = AssistantMessage(content=json.dumps(example_content))
self._add_message_with_type(example_tool_call_1, message_type='init')
self._add_message_with_type(
UserMessage(
diff --git a/browser_use/agent/system_prompt.md b/browser_use/agent/system_prompt.md
index a1eeeb191..ee9350cc9 100644
--- a/browser_use/agent/system_prompt.md
+++ b/browser_use/agent/system_prompt.md
@@ -34,7 +34,7 @@ Next Goal: Your goal for this step
Action Results: Your actions and their results
</step_{{step_number}}>
-and system messages wrapped in <system> tag.
+and system messages wrapped in <s> tag.
</agent_history>
<user_request>