Skip to content

Commit 909ec1a

Browse files
committed
enhance web agent; improve task instructions for URL navigation and screenshot capture, and expand browser action capabilities
1 parent b50556c commit 909ec1a

4 files changed

Lines changed: 79 additions & 10 deletions

File tree

argus/tools/ask_web_agent.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,17 @@ def execute(self, url: str, question: str = "", **_: Any) -> Content: # type: i
5959
)
6060
)
6161
self._call_count += 1
62-
task = (
63-
f"Navigate to {url} and take a screenshot. "
64-
f"Describe in detail what you see on the page and answer the question. "
65-
f"If the page appears to be blank or not rendering, check console logs and include any error messages in your description."
66-
)
62+
task = ""
6763
if question:
68-
task += f" Pay special attention to: {question}"
64+
task += f"QUESTION TO ANSWER: {question}\n\n"
65+
task += f"URL: {url}\n\n"
66+
task += (
67+
"Steps:\n"
68+
"1. Navigate to the URL and take a screenshot.\n"
69+
"2. If the page is blank or shows errors, get console logs and report the exact error messages.\n"
70+
"3. If the question requires interaction (clicking buttons, typing values, scrolling), perform those actions and take screenshots to capture the result.\n"
71+
"4. Use get_text to read specific values if visual inspection is not precise enough.\n"
72+
"5. End your response with a one-line verdict: PASS, FAIL, or PARTIAL — and explain why with specific evidence (values seen, errors found, etc.)."
73+
)
6974
text, screenshot = self._web_agent.run_with_screenshot(Content(text=task))
7075
return Content(text=text, images=[screenshot] if screenshot else [])

argus/tools/browser.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ class BrowserTool(Tool):
1818
"""
1919

2020
name = "browser"
21-
description = "Control a web browser. Supported actions: navigate, screenshot, click, type, scroll, get_text, get_console_logs."
21+
description = (
22+
"Control a web browser. Supported actions: "
23+
"navigate, screenshot, click, dblclick, hover, drag_and_drop, type, press, scroll, "
24+
"reload, get_text, get_console_logs."
25+
)
2226
parameters = {
2327
"type": "object",
2428
"properties": {
@@ -28,8 +32,13 @@ class BrowserTool(Tool):
2832
"navigate",
2933
"screenshot",
3034
"click",
35+
"dblclick",
36+
"hover",
37+
"drag_and_drop",
3138
"type",
39+
"press",
3240
"scroll",
41+
"reload",
3342
"get_text",
3443
"get_console_logs",
3544
],
@@ -38,12 +47,26 @@ class BrowserTool(Tool):
3847
"url": {"type": "string", "description": "URL to navigate to (navigate action)."},
3948
"selector": {
4049
"type": "string",
41-
"description": "CSS selector for the target element (click, type actions).",
50+
"description": (
51+
"CSS selector for the target element "
52+
"(click, dblclick, hover, drag_and_drop source, type, press actions)."
53+
),
54+
},
55+
"target_selector": {
56+
"type": "string",
57+
"description": "CSS selector for the drop target element (drag_and_drop action).",
4258
},
4359
"text": {
4460
"type": "string",
4561
"description": "Text to enter into the element (type action).",
4662
},
63+
"key": {
64+
"type": "string",
65+
"description": (
66+
"Key or key combination to press, e.g. 'Enter', 'ArrowDown', 'Control+a' "
67+
"(press action). Uses Playwright key names."
68+
),
69+
},
4770
"delta_x": {
4871
"type": "number",
4972
"description": "Horizontal scroll delta in pixels (scroll action).",
@@ -93,18 +116,47 @@ async def _execute_async(self, action: str, **kwargs: Any) -> Content:
93116
await self._page.click(selector)
94117
return Content(text=f"Clicked '{selector}'")
95118

119+
if action == "dblclick":
120+
selector = kwargs.get("selector", "")
121+
await self._page.dblclick(selector)
122+
return Content(text=f"Double-clicked '{selector}'")
123+
124+
if action == "hover":
125+
selector = kwargs.get("selector", "")
126+
await self._page.hover(selector)
127+
return Content(text=f"Hovered over '{selector}'")
128+
129+
if action == "drag_and_drop":
130+
selector = kwargs.get("selector", "")
131+
target_selector = kwargs.get("target_selector", "")
132+
await self._page.drag_and_drop(selector, target_selector)
133+
return Content(text=f"Dragged '{selector}' to '{target_selector}'")
134+
96135
if action == "type":
97136
selector = kwargs.get("selector", "")
98137
text = kwargs.get("text", "")
99138
await self._page.fill(selector, text)
100139
return Content(text=f"Typed into '{selector}'")
101140

141+
if action == "press":
142+
selector = kwargs.get("selector", "")
143+
key = kwargs.get("key", "")
144+
if selector:
145+
await self._page.press(selector, key)
146+
else:
147+
await self._page.keyboard.press(key)
148+
return Content(text=f"Pressed '{key}'" + (f" on '{selector}'" if selector else ""))
149+
102150
if action == "scroll":
103151
delta_x = kwargs.get("delta_x", 0)
104152
delta_y = kwargs.get("delta_y", 0)
105153
await self._page.mouse.wheel(delta_x, delta_y)
106154
return Content(text=f"Scrolled ({delta_x}, {delta_y})")
107155

156+
if action == "reload":
157+
await self._page.reload(wait_until="domcontentloaded")
158+
return Content(text="Page reloaded.")
159+
108160
if action == "get_text":
109161
return Content(text=await self._page.inner_text("body"))
110162

config.example.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ agent:
4545
- Do NOT use `applypatch`, `patch`, or any tool not available in a standard bash environment.
4646
- After each edit, verify the change took effect with `grep -n` or a small `sed -n` read.
4747
- If an edit fails twice in a row, switch to a different approach immediately.
48-
48+
- NEVER use `node - << 'EOF'` or `python3 - << 'EOF'` to edit files — heredoc + scripting language causes multi-level escaping bugs where replacements silently fail. Use `sed -i` for simple substitutions.
49+
4950
### Edit files with sed:
5051
```bash
5152
# Replace all occurrences
@@ -92,6 +93,17 @@ web_agent:
9293
headless: true
9394
max_steps: 20
9495
log_dir: logs/
96+
system_prompt: |
97+
You are a web browsing agent with the ability to navigate pages, take screenshots, click elements, type text, and scroll.
98+
99+
TASK to do: Navigate to a URL, take a screenshot, and describe what you see. Report the visual appearance of the page clearly and concisely so the caller can decide whether to make changes.
100+
101+
General rules:
102+
- Always navigate to the URL first, then take a screenshot before drawing conclusions.
103+
- If the server is unreachable or the page doesn't appear as expected, check console log and report that immediately.
104+
- If the question involves interaction (clicking a button, typing a value, scrolling), perform those actions and take a screenshot after each one.
105+
- Base your judgement on visual appearance and behaviour, not on source code.
106+
- If the page shows a blank white page or an error message, check console log and report that clearly.
95107
LLM:
96108
provider: openai
97109
model: gpt-5

run_swebench_multimodal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _build_task(problem_statement: str, port: int, max_steps: int) -> str:
7373
issue description:
7474
{problem_statement}
7575
76-
Please make changes to the codebase and fix the issue!
76+
You MUST make changes to the source code and fix the issue!
7777
"""
7878

7979

0 commit comments

Comments
 (0)