Skip to content

Commit a6813aa

Browse files
Update custom_prompts.py
1 parent 419b6f5 commit a6813aa

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/agent/custom_prompts.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
# @ProjectName: browser-use-webui
55
# @FileName: custom_prompts.py
66

7-
from datetime import datetime
87
from typing import List, Optional
98

10-
from langchain_core.messages import HumanMessage, SystemMessage
11-
12-
from browser_use.agent.views import ActionResult, AgentStepInfo
9+
from browser_use.agent.prompts import SystemPrompt
10+
from browser_use.agent.views import ActionResult
1311
from browser_use.browser.views import BrowserState
14-
from browser_use.agent.prompts import SystemPrompt, AgentMessagePrompt
12+
from langchain_core.messages import HumanMessage, SystemMessage
1513

1614
from .custom_views import CustomAgentStepInfo
1715

@@ -26,7 +24,7 @@ def important_rules(self) -> str:
2624
{
2725
"current_state": {
2826
"prev_action_evaluation": "Success|Failed|Unknown - Analyze the current elements and the image to check if the previous goals/actions are successful like intended by the task. Ignore the action result. The website is the ground truth. Also mention if something unexpected happened like new suggestions in an input field. Shortly state why/why not. Note that the result you output must be consistent with the reasoning you output afterwards. If you consider it to be 'Failed,' you should reflect on this during your thought.",
29-
"important_contents": "Output important contents closely related to user\'s instruction or task on the current page. If there is, please output the contents. If not, please output \"None\".",
27+
"important_contents": "Output important contents closely related to user\'s instruction or task on the current page. If there is, please output the contents. If not, please output empty string ''.",
3028
"completed_contents": "Update the input Task Progress. Completed contents is a general summary of the current contents that have been completed. Just summarize the contents that have been actually completed based on the current page and the history operations. Please list each completed item individually, such as: 1. Input username. 2. Input Password. 3. Click confirm button",
3129
"thought": "Think about the requirements that have been completed in previous operations and the requirements that need to be completed in the next one operation. If the output of prev_action_evaluation is 'Failed', please reflect and output your reflection here. If you think you have entered the wrong page, consider to go back to the previous page in next action.",
3230
"summary": "Please generate a brief natural language description for the operation in next actions based on your Thought."
@@ -93,7 +91,7 @@ def important_rules(self) -> str:
9391
- Try to be efficient, e.g. fill forms at once, or chain actions where nothing changes on the page like saving, extracting, checkboxes...
9492
- only use multiple actions if it makes sense.
9593
"""
96-
text += f' - use maximum {self.max_actions_per_step} actions per sequence'
94+
text += f" - use maximum {self.max_actions_per_step} actions per sequence"
9795
return text
9896

9997
def input_format(self) -> str:
@@ -128,7 +126,7 @@ def get_system_message(self) -> SystemMessage:
128126
Returns:
129127
str: Formatted system prompt
130128
"""
131-
time_str = self.current_date.strftime('%Y-%m-%d %H:%M')
129+
time_str = self.current_date.strftime("%Y-%m-%d %H:%M")
132130

133131
AGENT_PROMPT = f"""You are a precise browser automation agent that interacts with websites through structured commands. Your role is to:
134132
1. Analyze the provided webpage elements and structure
@@ -182,22 +180,24 @@ def get_user_message(self) -> HumanMessage:
182180
if self.result:
183181
for i, result in enumerate(self.result):
184182
if result.extracted_content:
185-
state_description += (
186-
f'\nResult of action {i + 1}/{len(self.result)}: {result.extracted_content}'
187-
)
183+
state_description += f"\nResult of action {i + 1}/{len(self.result)}: {result.extracted_content}"
188184
if result.error:
189185
# only use last 300 characters of error
190186
error = result.error[-self.max_error_length:]
191-
state_description += f'\nError of action {i + 1}/{len(self.result)}: ...{error}'
187+
state_description += (
188+
f"\nError of action {i + 1}/{len(self.result)}: ...{error}"
189+
)
192190

193191
if self.state.screenshot:
194192
# Format message for vision model
195193
return HumanMessage(
196194
content=[
197-
{'type': 'text', 'text': state_description},
195+
{"type": "text", "text": state_description},
198196
{
199-
'type': 'image_url',
200-
'image_url': {'url': f'data:image/png;base64,{self.state.screenshot}'},
197+
"type": "image_url",
198+
"image_url": {
199+
"url": f"data:image/png;base64,{self.state.screenshot}"
200+
},
201201
},
202202
]
203203
)

0 commit comments

Comments
 (0)