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
Include time later to enable prompt caching
magmueller70d2e194e47c
diff --git a/browser_use/agent/message_manager/service.py b/browser_use/agent/message_manager/service.pyindex 5b89a026f..71ddf52cb 100644--- a/browser_use/agent/message_manager/service.py+++ b/browser_use/agent/message_manager/service.py@@ -54,7 +54,6 @@ class MessageManager:self.sensitive_data = sensitive_datasystem_message = self.system_prompt_class(self.action_descriptions,- current_date=datetime.now(),max_actions_per_step=max_actions_per_step,).get_system_message()diff --git a/browser_use/agent/prompts.py b/browser_use/agent/prompts.pyindex 904fc201d..57ec86bc4 100644--- a/browser_use/agent/prompts.py+++ b/browser_use/agent/prompts.py@@ -1,3 +1,4 @@+import datetimefrom datetime import datetimefrom typing import List, Optional@@ -8,9 +9,8 @@ from browser_use.browser.views import BrowserStateclass SystemPrompt:- def __init__(self, action_description: str, current_date: datetime, max_actions_per_step: int = 10):+ def __init__(self, action_description: str, max_actions_per_step: int = 10):self.default_action_description = action_description- self.current_date = current_dateself.max_actions_per_step = max_actions_per_stepdef important_rules(self) -> str:@@ -120,14 +120,12 @@ Notes:Returns:str: Formatted system prompt"""- time_str = self.current_date.strftime('%Y-%m-%d %H:%M')AGENT_PROMPT = f"""You are a precise browser automation agent that interacts with websites through structured commands. Your role is to:1. Analyze the provided webpage elements and structure2. Plan a sequence of actions to accomplish the given task3. Respond with valid JSON containing your action sequence and state assessment-Current date and time: {time_str}{self.input_format()}@@ -162,11 +160,6 @@ class AgentMessagePrompt:self.step_info = step_infodef get_user_message(self, use_vision: bool = True) -> HumanMessage:- if self.step_info:- step_info_description = f'Current step: {self.step_info.step_number + 1}/{self.step_info.max_steps}'- else:- step_info_description = ''-elements_text = self.state.element_tree.clickable_elements_to_string(include_attributes=self.include_attributes)has_content_above = (self.state.pixels_above or 0) > 0@@ -188,13 +181,21 @@ class AgentMessagePrompt:else:elements_text = 'empty page'+ if self.step_info:+ step_info_description = f'Current step: {self.step_info.step_number + 1}/{self.step_info.max_steps}'+ else:+ step_info_description = ''+ time_str = datetime.now().strftime('%Y-%m-%d %H:%M')+ step_info_description += f'Current date and time: {time_str}'+state_description = f"""-{step_info_description}+Current url: {self.state.url}Available tabs:{self.state.tabs}-Interactive elements from current page view:+Interactive elements from current page:{elements_text}+{step_info_description}"""if self.result: