Skip to content

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

update system prompts

mertunsall110b96dc8dc4
diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.py
index f201a58a1..882f2fac6 100644
--- a/browser_use/agent/prompts.py
+++ b/browser_use/agent/prompts.py
@@ -22,11 +22,13 @@ class SystemPrompt:
use_thinking: bool = True,
flash_mode: bool = False,
is_anthropic: bool = False,
+ is_browser_use_model: bool = False,
):
self.max_actions_per_step = max_actions_per_step
self.use_thinking = use_thinking
self.flash_mode = flash_mode
self.is_anthropic = is_anthropic
+ self.is_browser_use_model = is_browser_use_model
prompt = ''
if override_system_message is not None:
prompt = override_system_message
@@ -42,8 +44,16 @@ class SystemPrompt:
def _load_prompt_template(self) -> None:
"""Load the prompt template from the markdown file."""
try:
- # Choose the appropriate template based on flash_mode, use_thinking, and is_anthropic
- if self.flash_mode and self.is_anthropic:
+ # Choose the appropriate template based on model type and mode
+ # Browser-use models use simplified prompts optimized for fine-tuned models
+ if self.is_browser_use_model:
+ if self.flash_mode:
+ template_filename = 'system_prompt_browser_use_flash.md'
+ elif self.use_thinking:
+ template_filename = 'system_prompt_browser_use.md'
+ else:
+ template_filename = 'system_prompt_browser_use_no_thinking.md'
+ elif self.flash_mode and self.is_anthropic:
template_filename = 'system_prompt_flash_anthropic.md'
elif self.flash_mode:
template_filename = 'system_prompt_flash.md'
@@ -53,7 +63,11 @@ class SystemPrompt:
template_filename = 'system_prompt_no_thinking.md'
# This works both in development and when installed as a package
- with importlib.resources.files('browser_use.agent').joinpath(template_filename).open('r', encoding='utf-8') as f:
+ with (
+ importlib.resources.files('browser_use.agent.system_prompts')
+ .joinpath(template_filename)
+ .open('r', encoding='utf-8') as f
+ ):
self.prompt_template = f.read()
except Exception as e:
raise RuntimeError(f'Failed to load system prompt template: {e}')
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index eb0ea3ca6..db20f9e7e 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -438,6 +438,9 @@ class Agent(Generic[Context, AgentStructuredOutput]):
is_anthropic = isinstance(self.llm, ChatAnthropic)
+ # Check if model is a browser-use fine-tuned model (uses simplified prompts)
+ is_browser_use_model = 'browser-use/' in self.llm.model.lower()
+
# Initialize message manager with state
# Initial system prompt with all actions - will be updated during each step
self._message_manager = MessageManager(
@@ -449,6 +452,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
use_thinking=self.settings.use_thinking,
flash_mode=self.settings.flash_mode,
is_anthropic=is_anthropic,
+ is_browser_use_model=is_browser_use_model,
).get_system_message(),
file_system=self.file_system,
state=self.state.message_manager_state,
diff --git a/browser_use/agent/system_prompts/__init__.py b/browser_use/agent/system_prompts/__init__.py
new file mode 100644
index 000000000..e91d5bec9
--- /dev/null
+++ b/browser_use/agent/system_prompts/__init__.py
@@ -0,0 +1 @@
+# System prompt templates for browser-use agent
diff --git a/browser_use/agent/system_prompt.md b/browser_use/agent/system_prompts/system_prompt.md
similarity index 100%
rename from browser_use/agent/system_prompt.md
rename to browser_use/agent/system_prompts/system_prompt.md
diff --git a/browser_use/agent/system_prompts/system_prompt_browser_use.md b/browser_use/agent/system_prompts/system_prompt_browser_use.md
new file mode 100644
index 000000000..2971d9b10
--- /dev/null
+++ b/browser_use/agent/system_prompts/system_prompt_browser_use.md
@@ -0,0 +1,13 @@
+You are a browser-use agent operating in thinking mode. You automate browser tasks by outputting structured JSON actions.
+
+<output>
+You must ALWAYS respond with a valid JSON in this exact format:
+{{
+ "thinking": "A structured reasoning block analyzing: current page state, what was attempted, what worked/failed, and strategic planning for next steps.",
+ "evaluation_previous_goal": "Concise one-sentence analysis of your last action. Clearly state success, failure, or uncertain.",
+ "memory": "1-3 sentences of specific memory of this step and overall progress. Track items found, pages visited, forms filled, etc.",
+ "next_goal": "State the next immediate goal and action to achieve it, in one clear sentence.",
+ "action": [{{"action_name": {{...params...}}}}]
+}}
+Action list should NEVER be empty.
+</output>
diff --git a/browser_use/agent/system_prompts/system_prompt_browser_use_flash.md b/browser_use/agent/system_prompts/system_prompt_browser_use_flash.md
new file mode 100644
index 000000000..e4cb73ea8
--- /dev/null
+++ b/browser_use/agent/system_prompts/system_prompt_browser_use_flash.md
@@ -0,0 +1,10 @@
+You are a browser-use agent operating in flash mode. You automate browser tasks by outputting structured JSON actions.
+
+<output>
+You must respond with a valid JSON in this exact format:
+{{
+ "memory": "Up to 5 sentences of specific reasoning about: Was the previous step successful / failed? What do we need to remember from the current state for the task? Plan ahead what are the best next actions. What's the next immediate goal? Depending on the complexity think longer.",
+ "action": [{{"action_name": {{...params...}}}}]
+}}
+Action list should NEVER be empty.
+</output>
diff --git a/browser_use/agent/system_prompts/system_prompt_browser_use_no_thinking.md b/browser_use/agent/system_prompts/system_prompt_browser_use_no_thinking.md
new file mode 100644
index 000000000..6d1936e78
--- /dev/null
+++ b/browser_use/agent/system_prompts/system_prompt_browser_use_no_thinking.md
@@ -0,0 +1,12 @@
+You are a browser-use agent. You automate browser tasks by outputting structured JSON actions.
+
+<output>
+You must ALWAYS respond with a valid JSON in this exact format:
+{{
+ "evaluation_previous_goal": "Concise one-sentence analysis of your last action. Clearly state success, failure, or uncertain.",
+ "memory": "1-3 sentences of specific memory of this step and overall progress. Track items found, pages visited, forms filled, etc.",
+ "next_goal": "State the next immediate goal and action to achieve it, in one clear sentence.",
+ "action": [{{"action_name": {{...params...}}}}]
+}}
+Action list should NEVER be empty.
+</output>
diff --git a/browser_use/agent/system_prompt_flash.md b/browser_use/agent/system_prompts/system_prompt_flash.md
similarity index 100%
rename from browser_use/agent/system_prompt_flash.md
rename to browser_use/agent/system_prompts/system_prompt_flash.md
diff --git a/browser_use/agent/system_prompt_flash_anthropic.md b/browser_use/agent/system_prompts/system_prompt_flash_anthropic.md
similarity index 100%
rename from browser_use/agent/system_prompt_flash_anthropic.md
rename to browser_use/agent/system_prompts/system_prompt_flash_anthropic.md
diff --git a/browser_use/agent/system_prompt_no_thinking.md b/browser_use/agent/system_prompts/system_prompt_no_thinking.md
similarity index 100%
rename from browser_use/agent/system_prompt_no_thinking.md
rename to browser_use/agent/system_prompts/system_prompt_no_thinking.md
diff --git a/pyproject.toml b/pyproject.toml
index 0b4b64f86..dfddba90d 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -163,10 +163,7 @@ include = [
"browser_use/**/*.py",
"!browser_use/**/tests/*.py",
"!browser_use/**/tests.py",
- "browser_use/agent/system_prompt.md",
- "browser_use/agent/system_prompt_no_thinking.md",
- "browser_use/agent/system_prompt_flash.md",
- "browser_use/agent/system_prompt_flash_anthropic.md",
+ "browser_use/agent/system_prompts/*.md",
"browser_use/code_use/system_prompt.md",
"browser_use/cli_templates/*.py",
"browser_use/py.typed",