Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions app/nullius/catalogue/benchmarks/webvoyager/auto_eval_one.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""WebVoyager's judge on one task's folder: the upstream's evaluation/auto_eval.py auto_eval_by_gpt4v, as its main
calls it for each task folder, with a client on the judge's route.

auto_eval_one.py UPSTREAM TASK_DIR OUT SCREENSHOTS [MODEL BASE_URL KEY]

OUT gets {"result": 1, 0 or None, "said": the judge's reply}. Without a model the client is None: auto_eval returns
0 for a folder with no ANSWER before it asks anything. Its own retries are kept: it asks again until it has a reply."""
import contextlib
import importlib.util
import io
import json
import os
import sys


class Tee(io.StringIO):
"""What auto_eval prints, kept for the judge's reply and passed on at once: a judge that never answers leaves its
retries in the log."""

def write(self, text):
sys.__stdout__.write(text)
sys.__stdout__.flush()
return super().write(text)

up, task_dir, out, screenshots = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4])
model, base_url, key = (sys.argv[5:8] if len(sys.argv) > 5 else (None, None, None))
spec = importlib.util.spec_from_file_location("auto_eval", os.path.join(up, "evaluation", "auto_eval.py"))
auto_eval = importlib.util.module_from_spec(spec)
spec.loader.exec_module(auto_eval)
client = auto_eval.OpenAI(api_key=key, base_url=base_url) if model else None
printed = Tee()
with contextlib.redirect_stdout(printed):
result = auto_eval.auto_eval_by_gpt4v(task_dir, client, model, screenshots)
lines = printed.getvalue().splitlines()
# auto_eval prints the judge's reply after the user message it sent, then "Auto_eval_res: ..."
said = ""
if model and "Auto_eval_res: " + str(result) in lines:
end = len(lines) - 1 - lines[::-1].index("Auto_eval_res: " + str(result))
start = next((i + 1 for i in range(end - 1, -1, -1) if lines[i].startswith("{'role': 'user'")), end)
said = "\n".join(lines[start:end]).strip()
with open(out, "w", encoding="utf-8") as f:
json.dump({"result": result, "said": said}, f)
62 changes: 62 additions & 0 deletions app/nullius/catalogue/benchmarks/webvoyager/benchmark.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"key": "webvoyager",
"title": "WebVoyager",
"category": "Web browsing",
"domain": "Questions answered on live public websites (Amazon, Apple, ArXiv, Booking, Google Flights and others), by clicking, typing and scrolling in a browser.",
"scoring": "Model judge",
"harness": [
"standard"
],
"origin": "official",
"good_to_know": [
"Pass or fail: a judge model reads the task, the agent's answer and its last 15 screenshots. A task with no answer fails without the judge.",
"Results change as the live websites change: compare runs made close in time.",
"Like the paper does not start from the builder: the paper's judge, GPT-4V, is retired. Run Original from the command line with --judge-model and a judge that reads images, or choose Any of your choice in the builder with a judge of your choice.",
"Original needs an OpenRouter key: OpenRouter serves gpt-4o-2024-05-13, the model it runs. Choose a judge that reads images, or the task gets no verdict. With Screenshots, the agent's model must take images too."
],
"upstream_limitations": [
"Live websites show CAPTCHAs to the agent's browser. A task stopped by one counts as failed.",
"The agent's model runs at the provider's default temperature: the upstream's agent never sends one.",
"The agent cannot read a PDF it downloads: the upstream sends PDFs to OpenAI's Assistants API, shut down on 2026-08-26, and tells the agent its action failed.",
"The judge sees no reference answer: no script reads the ones the upstream ships."
],
"limitations": [
"Choosing gpt-4-vision-preview runs gpt-4o-2024-05-13: OpenAI shut GPT-4V down on 2024-12-06 and named GPT-4o its replacement. These runs do not compare with the paper's GPT-4V rows.",
"The upstream's 90 GAIA web tasks are left out: its judge script never scores them.",
"The paper's text-only model, gpt-4-1106-preview, is not offered: OpenAI shut it down on 2026-10-23, and OpenRouter does not list it. The paper's Claude 3 Opus runs are not in Like the paper: the upstream's agent calls OpenAI's API only.",
"No run here is marked comparable with the paper. Its Table 1 was judged by GPT-4V; the closest is its Table 3 cell judged by GPT-4o.",
"Runs only on Linux x64 machines.",
"Nullius does not update the dates in Booking and Google Flights tasks: a task whose date has passed can fail whatever the agent does."
],
"datasets": [
{
"key": "webvoyager",
"title": "WebVoyager",
"tasks": 643,
"official": "https://github.com/MinorJerry/WebVoyager",
"source": "GitHub",
"registry": "",
"hub": "",
"verifier": "The upstream's judge: a model reads the task, the answer and the last 15 screenshots.",
"notes": "643 tasks on 15 websites, 40 or more each. Apache License 2.0."
}
],
"citation": "@article{he2024webvoyager,\n title={WebVoyager: Building an End-to-End Web Agent with Large Multimodal Models},\n author={He, Hongliang and Yao, Wenlin and Ma, Kaixin and Yu, Wenhao and Dai, Yong and Zhang, Hongming and Lan, Zhenzhong and Yu, Dong},\n journal={arXiv preprint arXiv:2401.13919},\n year={2024}\n}",
"citation_source": "https://github.com/MinorJerry/WebVoyager#citation",
"task_count": 643,
"evidence": [
{
"label": "Answer",
"path": "answer",
"reply": true
},
{
"label": "Judge said",
"path": "judge_said"
},
{
"label": "Steps",
"path": "steps"
}
]
}
260 changes: 260 additions & 0 deletions app/nullius/catalogue/benchmarks/webvoyager/driver.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
"""WebVoyager's driver for the Nullius standard (JSON lines on stdin and stdout).

Each unit is one task of the dataset file, run by the upstream's own agent at the tested commit
($NULLIUS_UPSTREAM): run.py opens the task's website in a headless Chrome and asks its model for one
action per step; evaluation/auto_eval.py's judge reads the task, the answer and the last screenshots.

driver.py [SELENIUM]

units - the dataset's task ids, in file order, a space written as "_" (a trial's name takes no space)
describe - each task's question and its website, from the dataset file alone
answer - a setup's (original, model): run.py on a test file of the one task, with run.sh's flags (the
README's text-only flags with the accessibility tree), the unit's folder as its output and
download folders, and the run's model as --api_model (the model setup: runs_as, the relay
sending the model chosen). Chrome is the one the driver's install downloaded (SELENIUM),
found by Selenium Manager from its SE_ variables
score - the upstream's auto_eval_by_gpt4v on the task's folder (auto_eval_one.py), with run_eval.sh's
15 screenshots and the judge's route; a control's unit (no setup) gets the folder run.py leaves
when no step runs: its interact_messages.json with the system message alone
setup - a control's unit only: the task's question

run.py gets only the variables below: no key of this machine; its --api_key is the relay's word."""
import contextlib
import glob
import json
import os
import queue
import signal
import subprocess
import sys
import threading
import time

UP = os.environ["NULLIUS_UPSTREAM"]
HERE = os.path.dirname(os.path.abspath(__file__))
SELENIUM = sys.argv[1] if len(sys.argv) > 1 else "" # the driver's install: Chrome and chromedriver
CHROME = "119" # as the install's command downloads it
STANDARD_FILE = os.path.join(HERE, "standard.json")
JUDGE = os.path.join(HERE, "auto_eval_one.py")
RESULTS, DOWNLOADS, TEST_FILE, LOG, CONTROL = "results", "downloads", "task.jsonl", "run.log", "control"
# run.sh; the README's text-only script for the accessibility tree
MAX_ITER = "15"
FLAGS = {"screenshots": ["--headless", "--max_iter", MAX_ITER, "--max_attached_imgs", "3", "--temperature", "1",
"--fix_box_color", "--seed", "42"],
"accessibility_tree": ["--headless", "--max_iter", MAX_ITER, "--max_attached_imgs", "1", "--temperature", "1",
"--text_only", "--seed", "42"]}
JUDGE_SCREENSHOTS = "15" # run_eval.sh's --max_attached_imgs
KEPT = ("PATH", "HOME", "USER", "LANG", "LC_ALL", "TMPDIR", "XDG_RUNTIME_DIR",
"http_proxy", "https_proxy", "no_proxy", "HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY")
STOP_SECONDS = 30
# the core waits for answer turn_seconds, and for score score_seconds, on its monotonic clock: each bound is on
# the same clock, early enough for the stop (STOP_SECONDS) and the reply
MARGIN_SECONDS = 120


class EnvironmentSetupError(RuntimeError):
pass


class VerifierError(RuntimeError):
pass


class CancelledError(RuntimeError):
pass


LINES, CLOSED = queue.Queue(), threading.Event()


def _read():
for line in sys.stdin:
LINES.put(line)
CLOSED.set()
LINES.put(None)


def _load(path):
with open(path, encoding="utf-8") as f:
return json.load(f)


def _tasks():
"""The dataset file's tasks, as run.py reads its --test_file: one JSON object a line."""
path = os.environ.get("NULLIUS_DATASET") or ""
if not path:
raise RuntimeError("no dataset file ($NULLIUS_DATASET)")
with open(path, encoding="utf-8") as f:
return [json.loads(line) for line in f if line.strip()]


def _unit_id(task):
return task["id"].replace(" ", "_")


def _task(unit):
found = [t for t in _tasks() if _unit_id(t) == unit]
if len(found) != 1:
raise RuntimeError(f"no task {unit}")
return found[0]


def units(**_):
return {"units": [_unit_id(t) for t in _tasks()]}


def describe(**_):
"""Each task from the dataset file alone: its question and its website."""
out = {}
for t in _tasks():
line = " ".join(str(t["ques"]).split())
title = line if len(line) <= 100 else line[:100].rsplit(" ", 1)[0] + " ..."
out[_unit_id(t)] = {"title": title, "text": str(t["ques"]), "categories": {"website": t["web_name"]}}
return {"units": out}


def setup(unit, dir, **_):
"""A control's unit (the setups run the upstream's agent, with no setup): the task's question."""
return {"prompt": _task(unit)["ques"]}


def _tail(log, n=3):
try:
with open(log, encoding="utf-8", errors="replace") as f:
lines = [ln.strip() for ln in f.read().splitlines() if ln.strip()]
except OSError:
return "nothing logged"
return " | ".join(lines[-n:])[:600] or "nothing logged"


def _run(argv, cwd, env, until, log):
"""The program in a session of its own, its output in ``log``; stopped with its browser when the run is stopped
or the time runs out. Its exit code."""
with open(log, "w") as f:
p = subprocess.Popen(argv, cwd=cwd, env=env, stdin=subprocess.DEVNULL, stdout=f, stderr=subprocess.STDOUT,
start_new_session=True)
why = None
while p.poll() is None:
if CLOSED.wait(1) or time.monotonic() > until:
why = "the run was stopped" if CLOSED.is_set() else "the time ran out"
os.killpg(p.pid, signal.SIGTERM)
try:
p.wait(STOP_SECONDS)
except subprocess.TimeoutExpired:
os.killpg(p.pid, signal.SIGKILL)
p.wait()
break
with contextlib.suppress(ProcessLookupError): # what run.py left of its group: Chrome, chromedriver
os.killpg(p.pid, signal.SIGKILL)
if why:
raise (CancelledError if CLOSED.is_set() else EnvironmentSetupError)(why)
return p.returncode


def _base_env():
return {**{k: v for k, v in os.environ.items() if k in KEPT}, "PYTHONUNBUFFERED": "1"}


def _task_dir(dir, task):
"""The task's folder run.py wrote: <output_dir>/<its start time>/task<id>."""
found = glob.glob(os.path.join(glob.escape(os.path.join(dir, RESULTS)), "*", glob.escape("task" + task["id"])))
if len(found) != 1:
raise EnvironmentSetupError(f"run.py wrote no folder for task {task['id']}: " + _tail(os.path.join(dir, LOG)))
return found[0]


def answer(unit, dir, setup, model, base_url, key, **_):
task = _task(unit)
if setup == "model":
model = _load(STANDARD_FILE)["setups"]["model"]["runs_as"] # the relay sends the model chosen
elif setup != "original":
raise RuntimeError(f"unknown setup {setup}")
if not SELENIUM or not os.path.isdir(SELENIUM):
raise EnvironmentSetupError("no Chrome: the definition's command names the driver's install")
observation = os.environ.get("NULLIUS_OPTION_OBSERVATION", "screenshots")
if observation not in FLAGS:
raise RuntimeError(f"unknown observation {observation}")
until = time.monotonic() + _load(STANDARD_FILE)["setups"]["original"]["turn_seconds"] - MARGIN_SECONDS
if os.path.lexists(os.path.join(dir, RESULTS)): # an earlier attempt's folder, kept aside
os.replace(os.path.join(dir, RESULTS), os.path.join(dir, f"{RESULTS}.{time.time_ns()}"))
os.makedirs(os.path.join(dir, DOWNLOADS), exist_ok=True)
with open(os.path.join(dir, TEST_FILE), "w", encoding="utf-8") as f:
f.write(json.dumps(task) + "\n")
env = {**_base_env(), "OPENAI_BASE_URL": base_url,
"SE_CACHE_PATH": SELENIUM, "SE_BROWSER_VERSION": CHROME, "SE_OFFLINE": "true"}
argv = [sys.executable, os.path.join(UP, "run.py"), "--test_file", os.path.join(dir, TEST_FILE),
"--api_key", key, "--api_model", model, "--output_dir", os.path.join(dir, RESULTS),
"--download_dir", os.path.join(dir, DOWNLOADS), *FLAGS[observation]]
code = _run(argv, dir, env, until, os.path.join(dir, LOG))
if code:
raise EnvironmentSetupError(f"run.py exited {code}: " + _tail(os.path.join(dir, LOG)))
task_dir = _task_dir(dir, task)
messages = _load(os.path.join(task_dir, "interact_messages.json"))
if len(messages) == 1: # its system message alone: it broke before its first observation
raise EnvironmentSetupError("run.py ended before its first step: " + _tail(os.path.join(task_dir, "agent.log")))
last = messages[-1]
said = last.get("content") if last.get("role") == "assistant" else ""
return {"answer": said if isinstance(said, str) else "", "model": model}


def _judge(task_dir, judge, log):
"""auto_eval_one.py on the task's folder: {"result": 1, 0 or None, "said": the judge's reply}."""
out = os.path.join(os.path.dirname(task_dir), "judged.json")
env = _base_env()
argv = [sys.executable, JUDGE, UP, task_dir, out, JUDGE_SCREENSHOTS]
if judge:
argv += [judge["model"], judge["base_url"], judge["key"]]
until = time.monotonic() + _load(STANDARD_FILE).get("limits", {}).get("score_seconds", 600) - MARGIN_SECONDS
try:
code = _run(argv, os.path.dirname(task_dir), env, until, log)
except EnvironmentSetupError: # auto_eval asks again until it has a reply: the judge's failure
raise VerifierError("the judge gave no verdict in time: " + _tail(log))
if code or not os.path.exists(out):
raise VerifierError(f"auto_eval exited {code}: " + _tail(log))
return _load(out)


def _control_dir(dir, task):
"""What run.py leaves for a task when no step runs: its folder with interact_messages.json, the system
message alone (print_message of [{'role': 'system', ...}])."""
if UP not in sys.path:
sys.path.insert(0, UP)
from prompts import SYSTEM_PROMPT # the upstream's own, as run.py starts its messages
task_dir = os.path.join(dir, CONTROL, "task" + task["id"])
os.makedirs(task_dir, exist_ok=True)
with open(os.path.join(task_dir, "interact_messages.json"), "w", encoding="utf-8") as f:
json.dump([{"role": "system", "content": SYSTEM_PROMPT}], f, indent=2)
return task_dir


def score(unit, dir, setup=None, judge=None, **_):
task = _task(unit)
if setup is None: # the core sends a control's unit no setup
task_dir = _control_dir(dir, task)
elif setup not in ("original", "model"):
raise RuntimeError("only the upstream's own agent runs this benchmark: its Original setup")
elif not judge:
raise VerifierError("no judge: the official one, gpt-4-vision-preview, is retired; run with --judge-model")
else:
task_dir = _task_dir(dir, task)
r = _judge(task_dir, judge, os.path.join(dir, "judge.log"))
if r["result"] is None:
raise VerifierError("the judge's reply says neither SUCCESS nor NOT SUCCESS: " + str(r["said"])[-300:])
passed = r["result"] == 1
messages = _load(os.path.join(task_dir, "interact_messages.json"))
return {"reward": 1.0 if passed else 0.0, "passed": passed,
"detail": {"judge_said": r["said"], "steps": sum(1 for m in messages if m.get("role") == "assistant"),
"steps_limit": int(MAX_ITER)}}


if __name__ == "__main__":
HANDLERS = {"units": units, "describe": describe, "setup": setup, "answer": answer, "score": score}
threading.Thread(target=_read, daemon=True).start()
while (line := LINES.get()) is not None:
try:
req = json.loads(line)
with contextlib.redirect_stdout(sys.stderr):
out = HANDLERS[req.pop("op")](**req)
except Exception as e:
out = {"error": f"{type(e).__name__}: {e}"}
print(json.dumps(out), flush=True)
25 changes: 25 additions & 0 deletions app/nullius/catalogue/benchmarks/webvoyager/proofs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"schema": "nullius.proofs/v1",
"kind": "benchmark",
"key": "webvoyager",
"versions": {
"": {
"proven": {
"webvoyager": {
"units": {
"units": 643,
"passed": "643 ids, the same twice, unique"
},
"nop": {
"passed": "0/643",
"value": 0.0,
"expect": {
"at_most": 0.0
},
"units": 643
}
}
}
}
}
}
Loading
Loading