Gymnasium-compatible SDK for ThetaBench web agent training & evaluation
Project description
ThetaBench Python SDK
Gymnasium-compatible SDK for training and evaluating web agents on ThetaBench environments.
Installation
pip install thetabench
# With browser-mode support (Playwright)
pip install 'thetabench[browser]'
playwright install chromium
Quick start
The SDK talks to a running ThetaBench server over HTTP. Point it at any URL
that exposes the standard /api/health, /api/sim/*, and /api/rl routes
— a local dev server, a Vercel deployment, or your own self-hosted instance.
REST mode (fast — 1-5 ms / step, ideal for RL training)
import thetabench
env = thetabench.make("http://localhost:3000", task_id="<task-id>")
obs, info = env.reset()
print(f"Task: {info['task_goal']}")
print(f"Max steps: {info['max_steps']}")
done = False
while not done:
action = my_agent(obs, info)
obs, reward, terminated, truncated, info = env.step(action)
done = terminated or truncated
result = env.finish()
print(f"Score: {result['score']:.0%} | Steps: {result['steps']} | Reward: {result['total_reward']:.2f}")
env.close()
Browser mode (realistic — Chromium + accessibility tree, ~100-500 ms / step)
import thetabench
env = thetabench.make(
"http://localhost:3000",
task_id="<task-id>",
mode="browser",
headless=True,
)
obs, info = env.reset()
# obs includes screenshot, accessibility tree, URL, and structured state
print(f"URL: {obs['url']}")
obs, reward, terminated, truncated, info = env.step({"type": "navigate", "url": "/some/path"})
obs, reward, terminated, truncated, info = env.step({"type": "fill", "selector": "#price", "value": "34.99"})
obs, reward, terminated, truncated, info = env.step({"type": "click", "selector": "button:has-text('Save')"})
result = env.finish()
env.close()
Curriculum training
import thetabench
def my_agent(obs, info):
# your decision logic here
return {"action": "navigate", "url": "/some/path"}
runner = thetabench.CurriculumRunner(
base_url="http://localhost:3000",
mastery_threshold=0.8,
)
for stage_result in runner.run(my_agent):
print(f"Stage {stage_result['stage']}: {stage_result['title']}")
print(f" Score: {stage_result['avg_score']:.0%}")
print(f" Mastery: {'Yes' if stage_result['mastery_achieved'] else 'No'}")
runner.close()
Browse the task catalog
from thetabench import ThetaBenchClient
client = ThetaBenchClient("http://localhost:3000")
# List all tasks on the connected server
tasks = client.list_tasks()
print(f"Total tasks: {tasks.total}")
# Filter by domain / difficulty / type / curriculum stage
filtered = client.list_tasks(domain="<domain>", difficulty="easy")
for t in filtered.tasks:
print(f" {t.id}: {t.title}")
# Walk the curriculum
curriculum = client.get_curriculum()
for stage in curriculum.stages:
print(f"Stage {stage.stage}: {stage.title} ({len(stage.taskIds)} tasks)")
# Server self-identity (site, version, task counts)
health = client.fetch_health()
print(f"Connected to: {health['site']} (v{health['version']}, {health['tasks']} tasks)")
client.close()
CLI
thetabench --url http://localhost:3000 info
thetabench --url http://localhost:3000 tasks --domain <domain> --difficulty easy
thetabench --url http://localhost:3000 run --task <task-id> --agent path/to/your_agent.py
thetabench --url http://localhost:3000 eval --agent path/to/your_agent.py --output results.json
Your agent file must export agent_step(obs, info) -> action. Optionally
agent_response(obs, info) -> str | None for retrieval / impossibility
tasks. Optionally a module-level MODEL = "..." for results metadata.
API Reference
thetabench.make(base_url, task_id, *, mode='rest', **kwargs) -> ThetaBenchEnv
Factory that constructs a ThetaBenchEnv pointed at a running server.
| Param | Type | Default | Description |
|---|---|---|---|
base_url |
str | (required) | Server URL — local dev server, Vercel deployment, or self-hosted. |
task_id |
str | (required) | Task identifier exposed by the server's /api/sim/tasks. |
mode |
"rest" | "browser" |
"rest" |
Transport mode. |
**kwargs |
Forwarded to ThetaBenchEnv — seed, config_overrides, headless, viewport, render_mode. |
The server self-identifies its site at /api/health; the SDK does not
maintain a hardcoded site → URL map.
ThetaBenchEnv (Gymnasium)
| Method | Returns | Description |
|---|---|---|
reset() |
(obs, info) |
Start a new episode. |
step(action) |
(obs, reward, terminated, truncated, info) |
Execute one action. |
evaluate() |
dict |
Mid-episode score check (non-destructive). |
finish(agent_response=None) |
dict |
End the episode and get the final score. |
close() |
None |
Release HTTP + browser resources. |
CurriculumRunner
| Method | Description |
|---|---|
run(agent_fn, agent_response_fn=None, start_stage=1) |
Generator yielding stage results, advancing on mastery. |
run_stage(stage, agent_fn, ...) |
Run all tasks in one stage. |
run_task(task_id, agent_fn, ...) |
Run a single task. |
get_curriculum() |
List of stages from the server. |
BatchRunner
| Method | Description |
|---|---|
run_all(domain=None, difficulty=None, task_type=None) |
Run every (filtered) task; returns standardized JSON results with per-domain and per-stage breakdowns. The meta.site field is filled from the server's /api/health response. |
close() |
Close the underlying HTTP client. |
ThetaBenchClient
Thin typed httpx wrapper over the standard endpoints. See the source for
the full method list — start_episode, finish_episode, evaluate,
step, observe, reset_env, get_state, get_snapshot, get_episode,
list_tasks, get_task, get_curriculum, log_action, get_action_space,
fetch_health.
License
MIT — see LICENSE.
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file thetabench-0.2.0.tar.gz.
File metadata
- Download URL: thetabench-0.2.0.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
840117ec822eb614e06291938b22fd63f1321c05063567ee91aa611511ae2a13
|
|
| MD5 |
03e3021bbac326cef9619819574bdc8b
|
|
| BLAKE2b-256 |
f14db215ad39fe212101d319f0765d28176eefea7cd53e6e70d8f2a637a21e76
|
Provenance
The following attestation bundles were made for thetabench-0.2.0.tar.gz:
Publisher:
release.yml on theta-rl-lab/thetabench
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thetabench-0.2.0.tar.gz -
Subject digest:
840117ec822eb614e06291938b22fd63f1321c05063567ee91aa611511ae2a13 - Sigstore transparency entry: 1366911713
- Sigstore integration time:
-
Permalink:
theta-rl-lab/thetabench@08f51a9a4e5ef8863ba4d80ebec7e13b411faf19 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/theta-rl-lab
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@08f51a9a4e5ef8863ba4d80ebec7e13b411faf19 -
Trigger Event:
push
-
Statement type:
File details
Details for the file thetabench-0.2.0-py3-none-any.whl.
File metadata
- Download URL: thetabench-0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
742edcb0d3ddab4d6d53e184e7c88b6ff414a5df65b64f9d3d7960bfd98d427b
|
|
| MD5 |
ecab04642b54f202cd5f7502405a95c0
|
|
| BLAKE2b-256 |
bd87f4beee218f5f631a0ea643d18ace17d10bb8a7466b310103cdbcae632284
|
Provenance
The following attestation bundles were made for thetabench-0.2.0-py3-none-any.whl:
Publisher:
release.yml on theta-rl-lab/thetabench
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thetabench-0.2.0-py3-none-any.whl -
Subject digest:
742edcb0d3ddab4d6d53e184e7c88b6ff414a5df65b64f9d3d7960bfd98d427b - Sigstore transparency entry: 1366911728
- Sigstore integration time:
-
Permalink:
theta-rl-lab/thetabench@08f51a9a4e5ef8863ba4d80ebec7e13b411faf19 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/theta-rl-lab
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@08f51a9a4e5ef8863ba4d80ebec7e13b411faf19 -
Trigger Event:
push
-
Statement type: