# Browser AI agent examples — build a goal-driven web agent on the live APIs [QuanticData's Browser AI](https://quanticdata.io/browser-ai/) — describe a goal, an agent drives a real cloud browser and returns schema-valid JSON with an auditable trace — is **in closed development**; you can [join the waitlist](https://quanticdata.io/browser-ai/). Meanwhile, most of what people want from a browser agent is buildable today with the APIs that are already live, and this repo is that build: a small planner-executor loop over `search`, `map`, `scrape` (with `render`, `actions` and `xhr`) and `ai_schema`, with a step trace and schema validation at the end. ```bash pip install requests jsonschema export QUANTICDATA_API_KEY=qd_live_your_key_here python3 agent.py "Collect the name, price and rating of every product under 'Grinders'" \ --start https://example-shop.test/ --out grinders.json python3 interactions.py https://quotes.toscrape.com/js/ # click, scroll, wait, capture python3 discover_api.py https://quotes.toscrape.com/js/ # find the page's own JSON endpoint ``` ## Files | File | What it does | |---|---| | [`browser.py`](browser.py) | the primitives: render, act, capture, extract | | [`agent.py`](agent.py) | plan → navigate → paginate → extract → validate, with a JSON trace | | [`interactions.py`](interactions.py) | the `actions` array: click, scroll, wait, and reading what changed | | [`discover_api.py`](discover_api.py) | `xhr: true` to find the page's own API, then call it directly | | [`trace.py`](trace.py) | the step log — what an auditable run looks like | ## The three tiers, cheapest first Reaching for a browser on every page is the most common and most expensive mistake in this area. | Tier | Cost | When it is the right answer | |---|---|---| | **HTTP** — `render: false` | $0.0002 | the content is in the served HTML. Check this first, always. | | **Hydration** — `app_state: "auto"` | $0.0002 | it is an SPA, but the data is in `__NEXT_DATA__` or a JSON island | | **The page's own API** — `xhr: true`, then call it | $0.0002/call | the page fetches JSON; that JSON is cleaner than any DOM | | **Browser** — `render: true` + `actions` | more | genuinely needs clicks, or renders server-side per interaction | `discover_api.py` exists because tier three wins far more often than people expect: an SPA's own endpoint returns typed, paginated, complete data, and you can call it a thousand times for the price of two browser renders. ## Interactions ```jsonc { "url": "https://shop.example/catalog", "render": true, "actions": [ { "click": "#accept-cookies" }, { "click": "a[href*='grinders']" }, { "waitForSelector": ".product-grid" }, { "scroll": "bottom" }, { "wait": 1500 } ], "ai_prompt": "Extract every product with name, price and rating.", "ai_schema": { "type": "object", "properties": { "products": { "type": "array", "items": { "type": "object", "properties": { "name": { "type": "string" }, "price": { "type": ["number", "null"] }, "rating": { "type": ["number", "null"] } } } } } } } ``` Actions run in order before the capture. One special action ends the sequence: `{"fetchResource": {"pattern": "/api/items"}}` returns the matching **network response body** instead of the page — the browser does the navigating, and you get the JSON. ## What "auditable" means here An agent that returns 38 rows and cannot tell you where they came from is not a data source. Every run in `agent.py` writes a trace: each step, its parameters, what came back, what it cost, and whether the final output validated against the schema. `trace.py` prints it. If a number in your report is wrong, you can find the step that produced it. ## Related - [Browser AI (waitlist)](https://quanticdata.io/browser-ai/) · [AI web scraping service](https://quanticdata.io/ai-web-scraping-service/) · [Web Scraping API](https://quanticdata.io/web-scraping-api/) - [How to build an AI browser agent](https://quanticdata.io/blog/how-to-build-an-ai-browser-agent/) · [What is browser automation?](https://quanticdata.io/blog/what-is-browser-automation/) - [Playwright stealth in Python](https://quanticdata.io/blog/playwright-stealth-in-python/) · [How to use Playwright for scraping](https://quanticdata.io/blog/how-to-use-playwright-for-scraping/) MIT licensed.