Skip to content

Commit 4e1bcd4

Browse files
committed
Merge branch 'main' of github.com:ServiceNow/BrowserGym
2 parents 56ba493 + 62d26a1 commit 4e1bcd4

File tree

12 files changed

+53
-73
lines changed

12 files changed

+53
-73
lines changed

README.md

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@ This package provides `browsergym`, a gym environment for web task automation in
44

55
## Setup
66

7-
1. Install the package
7+
To install browsergym, you can either install one of the `browsergym-miniwob`, `browsergym-webarena` and `browsergym-workarena` packages, or you can simply install `browsergym` which includes all of these by default.
88
```sh
99
pip install browsergym
1010
```
1111

12-
2. Install playwright browsers
12+
Then, a required step is to setup playwright by running
1313
```sh
1414
playwright install
1515
```
1616

17-
3. For each benchmark, specific setup instructions must be followed
17+
Finally, each benchmark comes with its its own specific setup that requires to follow additional steps.
1818
- for miniwob, see [miniwob/README.md](miniwob/README.md)
1919
- for webarena, see [webarena/README.md](webarena/README.md)
20-
- for workarena, see the [WorkArena](https://github.com/ServiceNow/WorkArena/README.md) repository
20+
- for workarena, see the [WorkArena README](https://github.com/ServiceNow/WorkArena/README.md)
2121

2222
4. (optional) if you want to run the UI assistant to create demos
2323

@@ -33,10 +33,10 @@ playwright install
3333

3434
### Open-ended task example
3535

36-
Boilerplate code to run an agent on the openended task:
36+
Boilerplate code to run an agent on an interactive, openended task:
3737
```python
3838
import gymnasium as gym
39-
import browsergym.core # register openended taskj as a gym environment
39+
import browsergym.core # register the openended task as a gym environment
4040

4141
env = gym.make(
4242
"browsergym/openended", start_url="https://www.google.com/", wait_for_user_message=True
@@ -63,6 +63,12 @@ while not done:
6363
obs, reward, terminated, truncated, info = env.step(action)
6464
```
6565

66+
List of all the available MiniWoB++ environments
67+
```python
68+
env_ids = [id for id in gym.envs.registry.keys() if id.startswith("browsergym/miniwob")]
69+
print("\n".join(env_ids))
70+
```
71+
6672
### WebArena task example
6773

6874
Boilerplate code to run an agent on a webarena task:
@@ -78,6 +84,12 @@ while not done:
7884
obs, reward, terminated, truncated, info = env.step(action)
7985
```
8086

87+
List of all the available WebArena environments
88+
```python
89+
env_ids = [id for id in gym.envs.registry.keys() if id.startswith("browsergym/webarena")]
90+
print("\n".join(env_ids))
91+
```
92+
8193
### WorkArena task example
8294

8395
Boilerplate code to run an agent on a workarena task:
@@ -93,5 +105,8 @@ while not done:
93105
obs, reward, terminated, truncated, info = env.step(action)
94106
```
95107

96-
## UI assistant
97-
108+
List of all the available WorkArena environments
109+
```python
110+
env_ids = [id for id in gym.envs.registry.keys() if id.startswith("browsergym/workarena")]
111+
print("\n".join(env_ids))
112+
```

core/README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,3 @@ This package provides `browsergym.core`, which provides the core functionalities
88
```sh
99
pip install browsergym-core
1010
```
11-
12-
2. Install playwright browsers
13-
```sh
14-
playwright install
15-
```
16-
17-
## Usage
18-
19-
```python
20-
import gymnasium as gym
21-
import browsergym.core # register gym environments
22-
23-
env = gym.make("browsergym/openended")
24-
```

core/src/browsergym/core/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.0.1a10"
1+
__version__ = "0.1.0rc0"
22

33
import playwright.sync_api
44

core/src/browsergym/core/chat_files/chatbox.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
.chat-debug {
4343
padding: 10px;
44-
max-height: 20%;
44+
max-height: 30%;
4545
overflow-y: auto;
4646
display: flex;
4747
flex-direction: column;

core/src/browsergym/core/env.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ def reset(self, seed=None, *args, **kwargs):
147147
)
148148
# create the chat at the same time to make sure videos are synced
149149
self.chat = Chat(
150-
headless=self.playwright_kwargs["headless"], record_video_dir=self.record_video_dir
150+
headless=self.playwright_kwargs["headless"],
151+
chat_size=(500, max(self.viewport["height"], 800)),
152+
record_video_dir=self.record_video_dir,
151153
)
152154
t_after = time.time()
153155
recording_start_time = (t_before + t_after) / 2 # recording start time
@@ -215,6 +217,9 @@ def reset(self, seed=None, *args, **kwargs):
215217
self.last_action = ""
216218
self.last_action_error = ""
217219

220+
# if asked, wait for user message
221+
self._wait_for_user_message()
222+
218223
# extract obs and info from environment
219224
obs = self._get_obs()
220225

@@ -245,21 +250,24 @@ def step(self, action: str) -> tuple:
245250
time.sleep(0.5) # wait for JS events to be fired (half a second)
246251
self.context.cookies() # trigger all waiting Playwright callbacks on the stack (hack, see https://playwright.dev/java/docs/multithreading)
247252

253+
# wait for the network to idle before extracting the observation, reward etc.
254+
self._wait_dom_loaded()
255+
248256
# after the action is executed, the active page might have changed
249257
# perform a safety check
250258
self._active_page_check()
251259

252-
# wait for the network to idle before extracting the observation, reward etc.
253-
self._wait_dom_loaded()
260+
# if asked, wait for user message
261+
self._wait_for_user_message()
254262

255-
# reward, done, user_message, info are task-specific
263+
# extract reward, done, user_message, info (task-specific)
256264
reward, done, user_message, info = self.task.validate(self.page, self.chat.messages)
257265

258266
# add any user message sent by the task to the chat
259267
if user_message:
260268
self.chat.add_message(role="user", msg=user_message)
261269

262-
# extract obs, reward etc.
270+
# extract observation (generic)
263271
obs = self._get_obs()
264272

265273
# new step API wants a 5-tuple (gymnasium)
@@ -268,6 +276,12 @@ def step(self, action: str) -> tuple:
268276

269277
return obs, reward, terminated, truncated, info
270278

279+
def _wait_for_user_message(self):
280+
# if last message is from the assistant, wait for a user message to continue
281+
# TODO: be smarter about when to wait for a user message (different action from the assistant?)
282+
if self.chat.messages[-1]["role"] == "assistant" and self.wait_for_user_message:
283+
self.chat.wait_for_user_message()
284+
271285
def _wait_dom_loaded(self):
272286
for page in self.context.pages:
273287
try:
@@ -322,11 +336,6 @@ def _active_page_check(self):
322336

323337
def _get_obs(self):
324338

325-
# if last message is from the assistant, wait for a user message to continue
326-
# TODO: be smarter about when to wait for a user message (different action from the assistant?)
327-
if self.chat.messages[-1]["role"] == "assistant" and self.wait_for_user_message:
328-
self.chat.wait_for_user_message()
329-
330339
for retries_left in reversed(range(EXTRACT_OBS_MAX_TRIES)):
331340
try:
332341
# pre-extraction, mark dom elements (set bid, set dynamic attributes like value and checked)

miniwob/README.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,3 @@ export MINIWOB_URL="file://<PATH_TO_MINIWOB_CLONED_REPO>/miniwob/html/miniwob/"
2121
```
2222

2323
Alternatively, one can [setup a simple HTTP server](https://miniwob.farama.org/content/viewing/) and use a proper URL.
24-
25-
## Usage
26-
27-
```python
28-
import gymnasium as gym
29-
import browsergym.miniwob # register gym environments
30-
31-
env = gym.make("browsergym/miniwob.choose-list")
32-
```
33-
34-
List of all the available MiniWoB++ environments
35-
```python
36-
env_ids = [id for id in gym.envs.registry.keys() if id.startswith("browsergym/miniwob")]
37-
print("\n".join(env_ids))
38-
```

miniwob/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
browsergym-core==0.0.1a10
1+
browsergym-core==0.1.0rc0

miniwob/src/browsergym/miniwob/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.0.1a10"
1+
__version__ = "0.1.0rc0"
22

33
from browsergym.core.registration import register_task
44

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ classifiers = [
2525
"Topic :: Scientific/Engineering :: Artificial Intelligence",
2626
"License :: OSI Approved :: Apache Software License",
2727
]
28-
version="0.0.1a10"
28+
version="0.1.0rc0"
2929
dependencies = [
30-
"browsergym-core==0.0.1a10",
31-
"browsergym-miniwob==0.0.1a10",
32-
"browsergym-webarena==0.0.1a10",
33-
"browsergym-workarena==0.0.1a10",
30+
"browsergym-core==0.1.0rc0",
31+
"browsergym-miniwob==0.1.0rc0",
32+
"browsergym-webarena==0.1.0rc0",
33+
"browsergym-workarena==0.1.0rc0",
3434
]
3535

3636
[tool.setuptools]

webarena/README.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,3 @@ export WIKIPEDIA="$BASE_URL:8888/wikipedia_en_all_maxi_2022-05/A/User:The_other_
3131
export MAP="$BASE_URL:3000"
3232
export HOMEPAGE="$BASE_URL:4399"
3333
```
34-
35-
## Usage
36-
37-
```python
38-
import gymnasium as gym
39-
import browsergym.webarena # register gym environments
40-
41-
env = gym.make("browsergym/webarena.310")
42-
```
43-
44-
List of all the available WebArena environments
45-
```python
46-
env_ids = [id for id in gym.envs.registry.keys() if id.startswith("browsergym/webarena")]
47-
print("\n".join(env_ids))
48-
```

0 commit comments

Comments
 (0)