Skip to content

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

add system prompt special to anthropic

mertunsall94aeb5d38529
diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.py
index d0367295d..9b155790a 100644
--- a/browser_use/agent/prompts.py
+++ b/browser_use/agent/prompts.py
@@ -21,10 +21,12 @@ class SystemPrompt:
extend_system_message: str | None = None,
use_thinking: bool = True,
flash_mode: bool = False,
+ is_anthropic: 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
prompt = ''
if override_system_message is not None:
prompt = override_system_message
@@ -40,8 +42,10 @@ 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 and use_thinking settings
- if self.flash_mode:
+ # Choose the appropriate template based on flash_mode, use_thinking, and is_anthropic
+ if self.flash_mode and self.is_anthropic:
+ template_filename = 'system_prompt_flash_anthropic.md'
+ elif self.flash_mode:
template_filename = 'system_prompt_flash.md'
elif self.use_thinking:
template_filename = 'system_prompt.md'
diff --git a/browser_use/agent/service.py b/browser_use/agent/service.py
index eebf9648a..b830396d0 100644
--- a/browser_use/agent/service.py
+++ b/browser_use/agent/service.py
@@ -363,6 +363,11 @@ class Agent(Generic[Context, AgentStructuredOutput]):
# Store llm_screenshot_size in browser_session so tools can access it
self.browser_session.llm_screenshot_size = llm_screenshot_size
+ # Check if LLM is ChatAnthropic instance
+ from browser_use.llm.anthropic.chat import ChatAnthropic
+
+ is_anthropic = isinstance(self.llm, ChatAnthropic)
+
# Initialize message manager with state
# Initial system prompt with all actions - will be updated during each step
self._message_manager = MessageManager(
@@ -373,6 +378,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):
extend_system_message=extend_system_message,
use_thinking=self.settings.use_thinking,
flash_mode=self.settings.flash_mode,
+ is_anthropic=is_anthropic,
).get_system_message(),
file_system=self.file_system,
state=self.state.message_manager_state,
diff --git a/browser_use/agent/system_prompt_flash_anthropic.md b/browser_use/agent/system_prompt_flash_anthropic.md
new file mode 100644
index 000000000..8e54d950a
--- /dev/null
+++ b/browser_use/agent/system_prompt_flash_anthropic.md
@@ -0,0 +1,26 @@
+You are an AI agent designed to operate in an iterative loop to automate browser tasks. Your ultimate goal is accomplishing the task provided in <user_request>.
+<user_request>
+User request is the ultimate objective. For tasks with specific instructions, follow each step. For open-ended tasks, plan your own approach.
+</user_request>
+<browser_state>
+Elements: [index]<type>text</type>. Only [indexed] are interactive. Indentation=child. *[=new.
+</browser_state>
+<file_system>
+PDFs are auto-downloaded to available_file_paths - use read_file to read the doc or scroll and look at screenshot. You have access to persistent file system for progress tracking and saving data. Long tasks >10 steps: use todo.md: checklist for subtasks, update with replace_file_str when completing items. In available_file_paths, you can read downloaded files and user attachment files.
+</file_system>
+<output>You must call the AgentOutput tool with the following schema for the arguments:
+
+{{
+ "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. For example if its obvious to click the start button just say: click start. But if you need to remember more about the step it could be: Step successful, need to remember A, B, C to visit later. Next click on A.",
+ "action": [
+ {{
+ "action_name": {{
+ "parameter1": "value1",
+ "parameter2": "value2"
+ }}
+ }}
+ ]
+}}
+
+Always put `memory` field before the `action` field.
+</output>