BrowserGym: a gym environment for web task automation in the Chromium browser
Project description
BrowserGym: a Gym Environment for Web Task Automation
[Setup] [Usage] [Demo] [Citation]
This package provides browsergym
, a gym environment for web task automation in the Chromium browser.
https://github.com/ServiceNow/BrowserGym/assets/26232819/e0bfc788-cc8e-44f1-b8c3-0d1114108b85
Example of a GPT4-V agent executing openended tasks (top row, chat interactive), as well as WebArena and WorkArena tasks (bottom row)
BrowserGym includes the following benchmarks by default:
Designing new web benchmarks with BrowserGym is easy, and simply requires to inherit the AbstractBrowserTask
class.
Setup
To install browsergym, you can either install one of the browsergym-miniwob
, browsergym-webarena
, browsergym-visualwebarena
and browsergym-workarena
packages, or you can simply install browsergym
which includes all of these by default.
pip install browsergym
Then, a required step is to setup playwright by running
playwright install chromium
Finally, each benchmark comes with its own specific setup that requires to follow additional steps.
- for miniwob, see miniwob/README.md
- for webarena, see webarena/README.md
- for visualwebarena, see visualwebarena/README.md
- for workarena, see WorkArena
Development setup
To install browsergym locally for development, use the following commands:
git clone https://github.com/ServiceNow/BrowserGym.git
cd BrowserGym
make install
Usage
Open-ended task example
Boilerplate code to run an agent on an interactive, open-ended task:
import gymnasium as gym
import browsergym.core # register the openended task as a gym environment
env = gym.make(
"browsergym/openended",
task_kwargs={"start_url": "https://www.google.com/"}, # starting URL
wait_for_user_message=True, # wait for a user message after each agent message sent to the chat
)
obs, info = env.reset()
done = False
while not done:
action = ... # implement your agent here
obs, reward, terminated, truncated, info = env.step(action)
done = terminated or truncated
MiniWoB++ task example
Boilerplate code to run an agent on a MiniWoB++ task:
import gymnasium as gym
import browsergym.miniwob # register miniwob tasks as gym environments
env = gym.make("browsergym/miniwob.choose-list")
obs, info = env.reset()
done = False
while not done:
action = ... # implement your agent here
obs, reward, terminated, truncated, info = env.step(action)
done = terminated or truncated
To list all the available MiniWoB++ environments run
env_ids = [id for id in gym.envs.registry.keys() if id.startswith("browsergym/miniwob")]
print("\n".join(env_ids))
WebArena task example
Boilerplate code to run an agent on a WebArena task:
import gymnasium as gym
import browsergym.webarena # register webarena tasks as gym environments
env = gym.make("browsergym/webarena.310")
obs, info = env.reset()
done = False
while not done:
action = ... # implement your agent here
obs, reward, terminated, truncated, info = env.step(action)
done = terminated or truncated
To list all the available WebArena environments run
env_ids = [id for id in gym.envs.registry.keys() if id.startswith("browsergym/webarena")]
print("\n".join(env_ids))
VisualWebArena task example
Boilerplate code to run an agent on a VisualWebArena task:
import gymnasium as gym
import browsergym.webarena # register webarena tasks as gym environments
env = gym.make("browsergym/webarena.721")
obs, info = env.reset()
done = False
while not done:
action = ... # implement your agent here
obs, reward, terminated, truncated, info = env.step(action)
done = terminated or truncated
To list all the available VisualWebArena environments run
env_ids = [id for id in gym.envs.registry.keys() if id.startswith("browsergym/visualwebarena")]
print("\n".join(env_ids))
WorkArena task example
Boilerplate code to run an agent on a WorkArena task:
import gymnasium as gym
import browsergym.workarena # register workarena tasks as gym environments
env = gym.make("browsergym/workarena.servicenow.order-ipad-pro")
obs, info = env.reset()
done = False
while not done:
action = ... # implement your agent here
obs, reward, terminated, truncated, info = env.step(action)
done = terminated or truncated
To list all the available WorkArena environments run
env_ids = [id for id in gym.envs.registry.keys() if id.startswith("browsergym/workarena")]
print("\n".join(env_ids))
Demo
If you want to experiment with an agent in BrowserGym, follow these steps:
cd demo-agent
conda env create -f environment.yml; conda activate demo-agent
# or simply use `pip install -r requirements.txt`
playwright install chromium
Optional: Set your OPENAI_API_KEY
to use a GPT agent.
Launch the demo on the open web:
python run_demo.py --task_name openended --start_url https://www.google.com
You can customize your experience by changing the model_name
to your preferred LLM, toggling Chain-of-thought with use_thinking
, adding screenshots for your VLMs with use_screenshot
, and much more!
Citing This Work
Please use the following BibTeX to cite our work:
@inproceedings{workarena2024,
title = {{W}ork{A}rena: How Capable are Web Agents at Solving Common Knowledge Work Tasks?},
author = {Drouin, Alexandre and Gasse, Maxime and Caccia, Massimo and Laradji, Issam H. and Del Verme, Manuel and Marty, Tom and Vazquez, David and Chapados, Nicolas and Lacoste, Alexandre},
booktitle = {Proceedings of the 41st International Conference on Machine Learning},
pages = {11642--11662},
year = {2024},
editor = {Salakhutdinov, Ruslan and Kolter, Zico and Heller, Katherine and Weller, Adrian and Oliver, Nuria and Scarlett, Jonathan and Berkenkamp, Felix},
volume = {235},
series = {Proceedings of Machine Learning Research},
month = {21--27 Jul},
publisher = {PMLR},
url = {https://proceedings.mlr.press/v235/drouin24a.html},
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file browsergym-0.4.1.tar.gz
.
File metadata
- Download URL: browsergym-0.4.1.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bf474a4f8238ff0d430870cb564eec9263123c37f767c5dc0b2a24978e055d7 |
|
MD5 | 334351457ac1c7d1c37a420524fdc288 |
|
BLAKE2b-256 | bffbcc9104b08c90c7bdc2440995c36daffee128c49f2bff07bc4b08c25816a2 |
File details
Details for the file browsergym-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: browsergym-0.4.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82a7b1496c1645ec259b4a9b369c8ea369cb8d5d9283743c876f31da58e2bbfd |
|
MD5 | e08e12f8df8947d607c11bef71e305d9 |
|
BLAKE2b-256 | 755137375036972ac1717584b3decccdc99300fe63fcdf29100e7f2767876d8e |