Skip to content

Commit

Permalink
Add interactive option to web_browser() for disabling interactive…
Browse files Browse the repository at this point in the history
… tools (clicking, typing, and submitting forms) (#642)

* Add `interactive` option to `web_browser()` for disabling interactive tools (clicking, typing, and submitting forms)

* filter web browser docs based on interactive

---------

Co-authored-by: aisi-inspect <[email protected]>
  • Loading branch information
jjallaire-aisi and aisi-inspect authored Oct 4, 2024
1 parent d2f3a27 commit 95ed9b2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Unreleased

- Add `interactive` option to `web_browser()` for disabling interactive tools (clicking, typing, and submitting forms).
- Provide token usage and raw model API calls for OpenAI o1-preview.
- Add support for reading CSV files of dialect 'excel-tab'.
- Improve prompting for Python tool to emphasise the need to print output.
Expand Down
41 changes: 34 additions & 7 deletions src/inspect_ai/tool/_tools/_web_browser/_web_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,40 @@

from inspect_ai._util.error import PrerequisiteError
from inspect_ai.tool._tool import Tool, ToolError, tool
from inspect_ai.tool._tool_info import parse_tool_info
from inspect_ai.tool._tool_with import tool_with
from inspect_ai.util._sandbox import SandboxEnvironment, sandbox_with
from inspect_ai.util._sandbox.docker.internal import INSPECT_WEB_BROWSER_IMAGE


def web_browser() -> list[Tool]:
def web_browser(interactive: bool = True) -> list[Tool]:
"""Tools used for web browser navigation.
Args:
interactive (bool): Provide interactive tools (enable
clicking, typing, and submitting forms). Defaults
to True.
Returns:
List of tools used for web browser navigation.
"""
return [
web_browser_go(),
web_browser_click(),
web_browser_type_submit(),
web_browser_type(),
# start with go tool (excluding interactive docs if necessary)
go = web_browser_go()
if not interactive:
go = go_without_interactive_docs(go)
tools = [go]

# add interactive tools if requested
if interactive:
tools = tools + [
web_browser_click(),
web_browser_type_submit(),
web_browser_type(),
]

# add navigational tools
return tools + [
web_browser_scroll(),
web_browser_back(),
web_browser_forward(),
Expand Down Expand Up @@ -46,7 +64,7 @@ async def execute(url: str) -> str:
[4] StaticText "Gmail"
[91] button "Google apps" [expanded: False]
[21] combobox "Search" [editable: plaintext, autocomplete: both, hasPopup: listbox, required: False, expanded: False, controls: Alh6id]
```
```
To execute a Google Search for 'dogs', you would type into the "Search" combobox with element ID 21 and then press ENTER using the web_browser_type_submit tool:
Expand All @@ -65,6 +83,15 @@ async def execute(url: str) -> str:
return execute


def go_without_interactive_docs(tool: Tool) -> Tool:
tool_info = parse_tool_info(tool)
description_lines = tool_info.description.splitlines()
description_lines = [
line for line in description_lines if "web_browser_type_submit" not in line
]
return tool_with(tool, description="\n".join(description_lines))


@tool(parallel=False)
def web_browser_click() -> Tool:
"""Web Browser tool for clicking an element on a web page.
Expand Down

0 comments on commit 95ed9b2

Please sign in to comment.