fix: make browser agent compatible with PlayWright 1.50 (#381)

Co-authored-by: Rafael Uzarowski <uzarowski.rafael@proton.me>

ehl0wr0ld committed May 19, 2025 at 14:42 UTC ace6dccfca68cbf29b130e676b09e00aba748419
3 files changed +35 -17
prompts/default/browser_agent.system.md
+25 -7
@@ -1,7 +1,25 @@
1 -# important
2 -do not overdo task
3 -when told go to website open website and stop
4 -do not interact unless told to
5 -waiting for instructions means ending task as done
6 -accept any cookies do not go to cokkie settings
7 -in page_summary respond with one paragraph of main content plus brief overview of page elements
\ No newline at end of file
1 +# Operation instruction
2 +Keep your tasks solution as simple and straight forward as possible
3 +Follow instructions as closely as possible
4 +When told go to website, open the website. If no other instructions: stop there
5 +Do not interact with the website unless told to
6 +Always accept all cookies if prompted on the website, NEVER go to browser cookie settings
7 +In page_summary respond with one paragraph of main content plus an overview of page elements
8 +If asked specific questions about a website, be as precise and close to the actual page content as possible
9 +If you are waiting for instructions: you should end the task and mark as done
10 +
11 +## Response Format
12 +Your responses must always be formatted as a JSON object
13 +The response JSON must contain at least the following fields: "title", "response", "page_summary"
14 +
15 +## Response fields
16 + * title (type: str) - The ttitle of the current web page
17 + * response (type: str) - Your response to your superior's last request
18 + * page_summary (type: str) - Summary of the current web page as requested by superior
19 +
20 +## Example response
21 +{
22 + "title": "Google Search",
23 + "response": "I have succesfully navigated to the response page.",
24 + "page_summary": "The page contains a menu bar with ... and a search input field. Under the search field there are two buttons with ... and ..."
25 +}
python/tools/browser_agent.py
+7 -7
@@ -5,13 +5,13 @@ from agent import Agent, InterventionException
5
6 import models
7 from python.helpers.tool import Tool, Response
8 -from python.helpers import dirty_json, files, rfc_exchange, defer, strings, persist_chat
9 -from python.helpers.print_style import PrintStyle
8 +from python.helpers import files, defer, persist_chat
9 from python.helpers.browser_use import browser_use
10 from python.extensions.message_loop_start._10_iteration_no import get_iter_no
11 from pydantic import BaseModel
12 import uuid
14 -
13 +from python.helpers.dirty_json import DirtyJson
14 +from langchain_core.messages import SystemMessage
15
16 class State:
17 @staticmethod
@@ -83,10 +83,10 @@ class State:
83 await self._initialize()
84
85 class CustomSystemPrompt(browser_use.SystemPrompt):
86 - def important_rules(self) -> str:
87 - existing_rules = super().important_rules()
86 + def get_system_message(self) -> SystemMessage:
87 + existing_rules = super().get_system_message().text()
88 new_rules = agent.read_prompt("prompts/browser_agent.system.md")
89 - return f"{existing_rules}\n{new_rules}".strip()
89 + return SystemMessage(content=f"{existing_rules}\n{new_rules}".strip())
90
91 # Model of task result
92 class DoneResult(BaseModel):
@@ -183,7 +183,7 @@ class BrowserAgent(Tool):
183 result = await task.result()
184 answer = result.final_result()
185 try:
186 - answer_data = dirty_json.DirtyJson.parse_string(answer)
186 + answer_data = DirtyJson.parse_string(answer)
187 answer_text = strings.dict_to_text(answer_data) # type: ignore
188 except Exception as e:
189 answer_text = answer
requirements.txt
+3 -3
@@ -1,6 +1,6 @@
1 ansio==0.0.1
2 beautifulsoup4==4.12.3
3 -browser-use==0.1.37
3 +browser-use==0.1.40
4 docker==7.1.0
5 duckduckgo-search==6.1.12
6 faiss-cpu==1.8.0.post1
@@ -10,7 +10,7 @@ flaredantic==0.1.4
10 GitPython==3.1.43
11 inputimeout==1.0.4
12 langchain-anthropic==0.3.3
13 -langchain-community==0.3.13
13 +langchain-community==0.3.19
14 langchain-google-genai==2.0.8
15 langchain-groq==0.2.2
16 langchain-huggingface==0.1.2
@@ -22,7 +22,7 @@ lxml_html_clean==0.3.1
22 markdown==3.7
23 newspaper3k==0.2.8
24 paramiko==3.5.0
25 -playwright==1.49.0
25 +playwright==1.52.0
26 pypdf==4.3.1
27 python-dotenv==1.0.1
28 sentence-transformers==3.0.1