gptme-browser-semantic

v0.1.0 Semantic browser primitives (observe/act/extract) for gptme computer-use — Path A: ARIA-snapshot scoring over gptme's existing Playwright tools, no stagehand dependency packages/gptme-browser-semantic View on GitHub

gptme-browser-semantic

Stagehand-style observe / act / extract browser primitives for gptme computer-use: find elements by natural-language description ("the submit button") and reuse the resulting Playwright selectors across several actions, without re-reading the page between steps.

Status: experimental (0.1.0, alpha). A pure-Python library layered on gptme's existing Playwright browser tool and its ARIA snapshot — no Stagehand dependency, no new browser-launching code. It is a Python library, not a registered gptme tool or plugin: call it from gptme's ipython tool or from your own scripts.

Why

The stock browser tool exposes snapshots and deterministic actions. The outer agent model normally interprets each fresh snapshot before choosing the next action:

snapshot_page()   # outer model interprets ARIA
click_element()
snapshot_page()   # outer model re-interprets
fill_element()
snapshot_page()   # outer model verifies

The semantic pattern makes selector discovery reusable:

observed = browser_observe("the submit button")
browser_act(observed[0])
browser_extract()

browser_observe is the load-bearing primitive: one call produces a ranked list of reusable Playwright-anchored selectors that subsequent deterministic actions act on with no extra model interpretation.

Install

Not published to PyPI. Install from the repository subdirectory into the same environment as gptme:

pip install "git+https://github.com/gptme/gptme-contrib#subdirectory=packages/gptme-browser-semantic"

The package itself has no runtime dependencies, but at runtime it imports gptme.tools.browser, so you need gptme with its browser extra and a Chromium build for Playwright:

pip install "gptme[browser]"
playwright install chromium

has_semantic_browser() returns True when that backend is importable.

Usage

With a page already open in gptme's browser tool:

from gptme_browser_semantic import browser_observe, browser_act, browser_extract

obs = browser_observe("the search box")
browser_act(obs[0], arguments=["rust async"])   # textbox -> fill
browser_act("click the Search button")          # observe + dispatch top match
state = browser_extract()                       # ExtractResult; .data is the ARIA snapshot

The three primitives

ActResult and ExtractResult both report success, elapsed_ms, and llm_calls (always 0 in this implementation).

Design notes: Path A vs Stagehand

Benchmark

benchmark.py preserves five representative action sequences and applies a static counting heuristic. It does not open fixtures/hn.html, invoke a browser or model, or record success. The scenario proxy is:

Proxy units
Raw browser path 11
Path A semantic path 7
Difference -4

This is not a measured LLM, token, latency, or success-rate result. A verdict requires both paths to execute against the same page while recording outer agent turns and any inner provider calls separately. Run the proxy with make benchmark. tests/test_benchmark.py pins the scenario arithmetic and its stated limitations so it cannot silently become a performance claim.

Tests

make test

The suite never touches a live browser: gptme.tools.browser is stubbed in sys.modules, so observe/act/extract run against a recorded ARIA snapshot and a recording dispatch layer. Coverage includes ranking, ambiguous labels, stale selectors, re-observe-on-failure, and the no-ref gptme snapshot shape.

See also