From c0df2feb110f0de483ef0ea7b8108ed5dfc3dcd4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Magnus=20M=C3=BCller?=
<67061560+MagMueller@users.noreply.github.com>
Date: Tue, 10 Jun 2025 07:51:12 +0200
Subject: [PATCH] Enhance system prompt and message formatting in service.py
Updated the system prompt documentation to clarify user request handling and added specific instructions for open-ended tasks. Modified message formatting in service.py to include XML-like tags for context, sensitive data, and user requests, improving structure and readability of messages. This change aims to enhance the clarity of communication between the agent and users.
---
browser_use/agent/message_manager/service.py | 28 +++++++++++---------
browser_use/agent/system_prompt.md | 4 ++-
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.py
index 322630075..f15ee8cb2 100644
--- a/browser_use/agent/message_manager/service.py
+++ b/browser_use/agent/message_manager/service.py
@@ -220,24 +220,24 @@ class MessageManager:
self._add_message_with_tokens(self.system_prompt, message_type='init')
if self.settings.message_context:
- context_message = HumanMessage(content='Context for the task' + self.settings.message_context)
+ context_message = HumanMessage(content='' + self.settings.message_context + '')
self._add_message_with_tokens(context_message, message_type='init')
if self.settings.sensitive_data:
- info = f'Here are placeholders for sensitive data: {list(self.settings.sensitive_data.keys())}'
- info += '\nTo use them, write the placeholder name'
+ info = f'Here are placeholders for sensitive data: {list(self.settings.sensitive_data.keys())}'
+ info += '\nTo use them, write the placeholder name '
info_message = HumanMessage(content=info)
self._add_message_with_tokens(info_message, message_type='init')
- placeholder_message = HumanMessage(
- content='Here is an example thinking and tool call. You can use it as a reference but do not copy it exactly.'
- )
task_message = HumanMessage(
- content=f'Your ultimate task is: """{self.task}""". If you achieved your ultimate task, stop everything and use the done action in the next step to complete the task. If not, continue as usual.'
+ content=f'Your ultimate goal is: """{self.task}""" \nIf you achieved your ultimate task, stop everything and use the done action in the next step to complete the task. If not, continue as usual.'
)
self._add_message_with_tokens(task_message, message_type='init')
- placeholder_message = HumanMessage(content='Example output:')
+ placeholder_message = HumanMessage(
+ content='Here is an example output of thinking and tool call. You can use it as a reference but do not copy it exactly.'
+ )
+ # placeholder_message = HumanMessage(content='Example output:')
self._add_message_with_tokens(placeholder_message, message_type='init')
example_tool_call_1 = AIMessage(
@@ -307,9 +307,9 @@ class MessageManager:
],
)
self._add_message_with_tokens(example_tool_call_1, message_type='init')
- self.add_tool_message(content='Data written to todo.md successfully.', message_type='init')
+ self.add_tool_message(content='Data written to todo.md successfully. ', message_type='init')
- placeholder_message = HumanMessage(content='Example thinking and tool call 2:')
+ placeholder_message = HumanMessage(content='Example thinking and tool call 2:')
# self._add_message_with_tokens(placeholder_message, message_type='init')
example_tool_call_2 = AIMessage(
@@ -350,14 +350,16 @@ My next action is to click on the iPhone link at index [4] to navigate to Apple'
],
)
# self._add_message_with_tokens(example_tool_call_2, message_type='init')
- # self.add_tool_message(content='Clicked on index [4].', message_type='init')
+ # self.add_tool_message(content='Clicked on index [4]. ', message_type='init')
if self.settings.available_file_paths:
- filepaths_msg = HumanMessage(content=f'Here are file paths you can use: {self.settings.available_file_paths}')
+ filepaths_msg = HumanMessage(
+ content=f'Here are file paths you can use: {self.settings.available_file_paths}'
+ )
self._add_message_with_tokens(filepaths_msg, message_type='init')
def add_new_task(self, new_task: str) -> None:
- content = f'Your new ultimate task is: """{new_task}""". Take the previous context into account and finish your new ultimate task. '
+ content = f'Your new ultimate task is: """{new_task}""". Take the previous context into account and finish your new ultimate task. '
msg = HumanMessage(content=content)
self._add_message_with_tokens(msg)
self.task = new_task
diff --git a/browser_use/agent/system_prompt.md b/browser_use/agent/system_prompt.md
index 6a8f06129..10ee33817 100644
--- a/browser_use/agent/system_prompt.md
+++ b/browser_use/agent/system_prompt.md
@@ -36,7 +36,9 @@ Action Results: System generated result of those actions
USER REQUEST: This is your ultimate objective and always remains visible.
-This has the highest priority. Make the user happy.
+- This has the highest priority. Make the user happy.
+- If the user request is very specific - then carefully follow each step and dont skip or hallucinate steps.
+- If the task is open ended you can plan more yourself how to get it done.