# fast-automation [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.22904595.svg)](https://doi.org/10.5281/zenodo.22904595) [![License: MIT](https://img.shields.io/badge/code-MIT-blue.svg)](LICENSE) [![Data: CC BY 4.0](https://img.shields.io/badge/data-CC%20BY%204.0-lightgrey.svg)](LICENSE) **Plan-and-execute web agents vs ReAct.** A 200-task browser benchmark with scraped ground truth, 2,800 recorded runs across two models, and the paper: planning once matches a budget-matched ReAct baseline on success while using ~84% fewer input tokens. Paper: [`paper.pdf`](paper.pdf) · DOI [10.5281/zenodo.22904595](https://doi.org/10.5281/zenodo.22904595) **Two agent modes.** `plan` (default): the LLM writes the whole plan in one call; Laya (System 1, ~20 ms/call on MLX) grounds each step to a page element, waits for async content, and checks actions that changed nothing visible. The LLM is called again only to replan after a failure and to write the answer — typically 2 LLM calls per task. `react`: the LLM picks every action (baseline). Code: `src/planner.js` vs `src/agent.js`. DeepSeek (via OpenRouter) drives a real Chromium browser through Playwright tools. After every action a System‑1 verifier — **Laya running locally on Apple MLX** — returns calibrated probabilities (action succeeded? task done? what next?). Every LLM call, tool call and verifier call is traced and shown in a live analytics UI (timeline strips per task, time‑to‑first‑token, per‑function stats). ## Setup ```sh npm install # playwright + @receptron/laya (ONNX fallback) cd mlx && uv venv -p 3.12 .venv && uv pip install -p .venv/bin/python mlx tokenizers huggingface_hub && cd .. ``` `.env`: `OPENROUTER_KEY=...` and `TYPESAFE_API_KEY=...` (Jev, used as fallback verifier). ## Run ```sh npm run mlx # terminal 1: Laya on MLX, downloads weights (~1.7 GB) once, serves :8765 npm start # terminal 2: chat UI http://localhost:3000, analytics http://localhost:3000/analytics npm run agent -- "Go to https://news.ycombinator.com and report the top 3 titles" # CLI instead of UI npm run agent -- --file tasks.txt npm test # MLX port vs ONNX reference ``` The browser opens as a visible window by default (`HEADLESS=1` to hide it). Each chat conversation keeps its own browser and message history, so follow-ups continue on the current page; idle browsers close after 10 min. Env knobs: `MODEL` (default `deepseek/deepseek-v4.1-flash`), `JUDGE=mlx|laya|typesafe`, `HEADLESS=1`, `PROVIDERS`, `PORT`. ## Layout - `src/agent.js` – `createSession()` (one browser + history per conversation), LLM loop (streamed, TTFT measured), tool dispatch, verifier after each action - `src/tools.js` – Playwright tools: navigate, snapshot, click, type, press, scroll, extract, wait, done - `src/judge.js` – verifier backends (MLX HTTP, ONNX in‑process, TypeSafe Jev API) + the questions asked - `src/server.js` – HTTP + SSE; `/api/conversations` (create, message, runs, delete), persists `runs/*.json` - `ui/chat/` – chat interface (index.html, app.js, style.css): streaming text, tool cards, verifier chips, final answer - `ui/analytics.html` – analytics dashboard - `mlx/laya_mlx.py` – ModernBERT‑large + Laya decision head in MLX, loads HF safetensors directly ## 200-task benchmark (paper results) `bench/tasks-200.json`: 200 tasks on 7 public sites. Ground truth is scraped from the sites or produced by scripted Playwright runs (`bench/gen-tasks-200.js`, fixed seed, self-checked). Each task ran three times under each of four configs with the same LLM (DeepSeek v4.1 flash, temperature 0, reasoning off): 2,400 runs, no API errors. | config | passes per repeat | pooled rate (95% CI) | mean time | LLM calls | input tokens | cost / task | |---|---|---|---|---|---|---| | react | 158, 163, 163 | 80.7% (77.3-83.6) | 32.8 s | 6.03 | 20,523 | $0.00186 | | react-eq (same budget: 12k-char extract, 30 turns) | 183, 183, 186 | **92.0%** (89.6-93.9) | 42.2 s | 6.22 | 24,697 | $0.00202 | | plan + Laya | 177, 179, 177 | 88.8% (86.1-91.1) | **10.2 s** | **2.03** | **4,060** | **$0.00040** | | plan + lexical (no Laya) | 173, 168, 178 | 86.5% (83.5-89.0) | 10.8 s | 2.12 | 4,305 | $0.00042 | - **Accuracy is a tie once budgets match.** plan+laya vs react-eq: -3.2 points [-7.7, +1.2], not significant in any repeat (McNemar p = 0.31, 0.54, 0.12). The apparent win over plain `react` (+8.2 points) comes from its 4,000-char `extract` and 15-turn cap: raising both gains react 11.3 points. - **Efficiency is the real result.** vs react-eq: 83.6% fewer input tokens, 67.3% fewer LLM calls, 80.4% less money, 4.1x less wall-clock time (Wilcoxon p < 1e-25 each). On the 505 paired runs both solved: 3,905 vs 13,298 tokens, 1.88 vs 4.41 calls, 9.6 vs 17.4 s. - **Laya vs word matching: no significant difference** (+2.3 points [-0.2, +5.0], p = 0.07). It does help where identical controls need context (saucedemo 60/60 vs 49/60 runs). Grounding calls take 31 ms median. Post-action verification never fired. - **Weak spot of planning ahead:** TodoMVC 0/30 and 2/30 runs for the plan configs vs 26/30 for react-eq. A plan written before the page exists cannot name list items that appear only after typing them. ```sh node bench/gen-tasks-200.js # regenerate tasks (needs network) TRACE_FULL=1 node bench/run-200.js --concurrency 8 # rerun (needs npm run mlx + OPENROUTER_KEY); resumable uv run --with matplotlib --with scipy --with numpy python bench/analyze-200.py bench/data-200-rep1 # stats, tables, figures uv run --with matplotlib --with scipy --with numpy python bench/analyze-reps.py # across repeats ``` Data layout: `bench/data-200/` (react, plan+laya, plan+lexical) and `bench/data-200-r1eq/` (react-eq) are repeat 1, merged into `bench/data-200-rep1/` for analysis. `bench/data-200-r2/` and `-r3/` are further repeats. Each folder has `manifest.json` (code and task checksums, environment), `results.jsonl` (one graded row per run) and `runs/__.json` (full traces: every prompt, completion, tool call and Laya decision). The paper is `paper.tex` / `paper.pdf` (`tectonic paper.tex`). ## Development suites The suites below were used while building the agents, and the agent code was tuned on them. Headline numbers come from the 200-task benchmark above. `bench/tasks.json` holds 16 real-world browser tasks (levels 1–4: reading, category navigation, logins, multi-step checkout, dropdowns, async loading, forms with radios/checkboxes, site search, heavy pages). Each has `expect` regexes so success is objective, not model-judged. ```sh npm run bench # llm-only vs llm+laya-mlx node src/bench.js --configs llm,laya,jev # add TypeSafe Jev as verifier node src/bench.js --only saucedemo-checkout --repeat 3 ``` Writes `bench/RESULTS.md` (+ timestamped json/md in `bench/results/`). Runs are tagged `bench:` in `runs/` so they show up in the analytics dashboard. ### Results (hard suite, DeepSeek v4.1 flash, reasoning off) | mode | pass | avg time | LLM calls (14 tasks) | avg input tokens | |---|---|---|---|---| | react (LLM every step) | 13/14 | 18.4 s | 80 | 15,509 | | plan + Laya | 12/14 → 14/14 after answer-step fixes* | 14.1 s | 29 | 3,230 | \* the two misses were answer-writing issues (planner notes, heading wording); the three affected tasks were rerun individually after the fix and passed with 2 LLM calls each. See `bench/RESULTS-hard.md`. Things that mattered, found from traces: - DeepSeek "thinking" cost ~4k hidden tokens / ~19 s per plan → `reasoning: {enabled:false}` (set `REASONING=1` to re-enable). - On a 16 GB Mac the OS evicted Laya's weights under browser memory pressure (30 ms → 5–9 s/call) → wired memory + keepalive. - Grounding accuracy depends on the element text Laya sees: aria-label over badge numbers, `title=` for truncated text, link destinations (`→ /wiki/...`), product-card context for duplicate buttons, whole-document scan. - Links to the same destination pool their probability; a pick with no word overlap needs ≥ 80 % or the LLM replans. ## Paper, data and citation Repository: https://github.com/TheDivyanshShukla/plan-once-ground-locally Paper and data archive (DOI): https://doi.org/10.5281/zenodo.22904595 The study behind the benchmark numbers is written up in `paper.tex` / `paper.pdf` ("Plan Once, Ground Locally: Plan-and-Execute Web Agents Match ReAct Accuracy at One-Sixth of the Token Cost"). Build it with `tectonic paper.tex`. `bench/DATA.md` documents every file, the schema of a result row and the schema of a run trace. The per-run traces (every prompt, completion, tool result and model decision for all 2,400 runs) are shipped compressed: ```sh cd bench/data-200 && tar -xzf ../traces/data-200-runs.tar.gz # recreates runs/ ``` Code is MIT licensed; the benchmark tasks, results and traces are CC BY 4.0. See `LICENSE`. If you use any of it, please cite the paper (`CITATION.cff`). ## How to cite ```bibtex @misc{shukla2026planonce, title = {Plan Once, Ground Locally: Plan-and-Execute Web Agents Match ReAct Accuracy at One-Sixth of the Token Cost}, author = {Shukla, Divyansh}, year = {2026}, publisher = {Zenodo}, doi = {10.5281/zenodo.22904595}, url = {https://doi.org/10.5281/zenodo.22904595} } ```