🤖 AI/ML Workflows • Intermediate • 20-30 min

AI Page Agent

An in-page agent that reads a UI as text and acts on it, inspired by browser-agent frameworks like page-agent, Stagehand, and browser-use.

About Demo Browser No API keys Attribution: vinallcontact@gmail.com

What this demo is about

The pattern behind agentic UI control

Type a plain-English command and an in-page agent reads a support ticket queue as text (no screenshots, no vision model), decides which action matches, and acts directly on the real DOM — the same architectural pattern used by the open-source page-agent library. The "Decide" step has two real, swappable interpreters: a zero-setup rule-based parser (default), and an optional on-device AI mode that calls a real local model — either Chrome's built-in Prompt API (Gemini Nano, no download) or WebLLM (a small open-weight model downloaded once and run locally via WebGPU).

Learning objectives

  • Explain the observe-decide-act-result loop that browser-agent frameworks use to operate a UI.
  • Compare text/DOM-based grounding (no screenshots) against vision-based agent approaches.
  • Evaluate the build-vs-buy tradeoff between a custom in-page agent and frameworks like Stagehand, browser-use, or Nanobrowser.
  • Identify where a human-in-the-loop guardrail belongs when an agent can take destructive actions.
  • Run the same command through a rule-based parser and a real on-device model, and explain concretely why one succeeds where the other fails.

Run modes

  • Supported modes: Browser
  • Demo type: Interactive browser demo
  • Primary launch surface: index.html

Before you start

Starts immediately in browser with no installs, no API keys, and classroom-safe defaults. Rule-based mode is the default and never downloads anything.

On-device AI is opt-in: selecting it only checks for Chrome's built-in AI first (no download); if that's unavailable, it falls back to WebLLM, which downloads a small (roughly 300-500MB) model the first time over WebGPU. Nothing downloads until you explicitly choose that mode.

Two real interpreters, same pipeline

Rule-based parser vs. on-device AI

Both interpreters feed the exact same guardrail, DOM-execution, and trace-logging code — only the "Decide" step changes. That's deliberate: it isolates the one variable that actually matters for this comparison.

Rule-based (default)

Regex and keyword matching against the command text. Zero setup, deterministic, and instantly reproducible — but brittle. Natural phrasings outside its fixed vocabulary (e.g. "the customer paying twice needs this fixed") return "no confident match" even though a human reading it knows exactly what to do.

Chrome built-in AI

Uses Chrome's on-device Prompt API (LanguageModel/window.ai.languageModel), backed by Gemini Nano. No download managed by this page — Chrome handles that. Availability varies by Chrome version and may require enabling a flag; the demo detects this and reports status honestly rather than pretending it always works.

WebLLM fallback

If Chrome's built-in AI isn't available, the demo checks for WebGPU and, if present, downloads a small model (Qwen2.5-0.5B-Instruct) via WebLLM and runs it locally. Works in any WebGPU-capable browser, not just Chrome — at the cost of a real download and slower first response.

What the model actually receives: the same text-only observation list observePage() builds for the rule-based path, plus the user's command, wrapped in a prompt that asks for one JSON action object. The response is parsed defensively (malformed JSON, hallucinated ticket IDs, and off-schema actions all degrade to a visible "no confident match" rather than crashing or silently doing the wrong thing) and escaped before being shown in the trace log, since it's untrusted model output.

Build vs. buy

How this compares to production agent frameworks

None of these run as a live demo in this repo — Stagehand and browser-use need a backend and an LLM API key, and Nanobrowser needs a Chrome extension install. This demo's in-page pattern is the only one of the four that is just JavaScript in a page, which is why it's the one built here. Use the other three as reading/case-study material: what does it cost in infrastructure to move from this teaching demo to something production-grade?

Stagehand (Browserbase)

Node SDK, CDP-based, code + natural language hybrid. Needs a Browserbase account and an LLM API key.

Live-demo fit: Poor — needs a backend and paid keys.

browser-use

Python + Playwright. Needs Python 3.11+ and an LLM API key.

Live-demo fit: Poor — Python backend, not static-hostable.

Nanobrowser

Chrome extension, multi-agent (Planner + Navigator). Needs an extension install and an LLM API key (or local Ollama).

Live-demo fit: Partial — real production pattern, but needs an install.

page-agent (this demo's inspiration)

Pure in-page JS, no backend. Needs any LLM endpoint you point it at.

Live-demo fit: Best — just JavaScript in a page.

Why this matters for AI product managers

Agents that operate your product, not just answer questions about it

Core context

A chatbot that answers questions about your product is a different (and much lower-risk) product decision than an agent that takes actions inside your product's own UI. This demo makes that second category concrete.

Concepts covered

DOM/text grounding
Observe-decide-act-result loop
Human-in-the-loop guardrails
Build-vs-buy framework tradeoffs

What students should note

The rule-based parser will fail on phrasings a real LLM handles easily — try "the customer paying twice needs this fixed" in both modes and compare. That gap is the honest tradeoff of zero-setup, zero-cost teaching demos versus what a production agent actually needs. On-device AI narrows that gap without needing an API key, but isn't guaranteed to be available in every browser.

How to use the demo

Recommended classroom flow

List of steps

  • Click an example command chip, or type your own (e.g. "Resolve ticket 101").
  • Watch the Agent Trace panel's four steps: Observe, Decide, Act, Result.
  • Try a destructive command (resolve/escalate) with the guardrail on, then confirm or cancel it.
  • Turn the guardrail off and re-run the same command to see it execute immediately.
  • Try a command the rule-based parser can't handle (e.g. "the customer paying twice needs this fixed"), note the "no confident match" result, then switch the interpreter to On-device AI and try the exact same command.
  • Check the "On-device AI status" panel — if it says "Not supported," that's a real, honest capability check, not a bug; discuss what that means for shipping AI features to a real user base with mixed browsers.

Controls explained

  • `Command input` is the only control a user needs — the ticket-level buttons and dropdowns still work by hand, for comparison.
  • `Command interpreter` switches the "Decide" step between the rule-based parser and on-device AI. Switching to on-device AI triggers a one-time capability check (and possibly a model download) — nothing loads until you choose it.
  • `Safety guardrail` toggles whether destructive actions (resolve, escalate) pause for human confirmation, regardless of which interpreter decided the action.
  • `Run Agent` executes the observe-decide-act-result loop once per click.

Buttons / actions

  • `Confirm Action` / `Cancel` only appear when the guardrail intercepts a destructive action.
  • `Reset Demo` restores the ticket queue, action counter, guardrail, and interpreter to their starting state. An already-loaded on-device model stays in memory — it won't re-download.

Outputs and interpretation

How to read the agent trace

Outputs explained

  • `Observe` shows how many actionable elements the agent found and one example, proving it read the live DOM, not a fixed script.
  • `Decide` shows the matched action and target element, or an honest "no confident match" when the parser fails.
  • `Act` / `Result` show the actual DOM mutation performed and the resulting ticket state.

Discussion and reflection

  • Which commands did the agent handle well, and which did it miss? What would a real LLM need to fix that gap?
  • Where in your own product would an agent like this be useful — and where would the guardrail be non-negotiable?
  • Given the framework comparison above, would you build a custom in-page agent, or adopt Stagehand/browser-use/Nanobrowser? What does that decision cost in infrastructure and risk?

Faculty guide

Prompt for discussion or assessment

Ask students to draft a one-page "agent risk memo" for a real feature in their own product: what actions would an AI agent be allowed to take unsupervised, which actions require confirmation, and why.

Suggested interpretation prompt: Ask learners to name one command the demo's rule-based parser got wrong, and explain specifically what an LLM-based agent would need to understand to get it right.

Feedback

Help make this resource better

Rate this About Demo page
0.0 (0 ratings)

Local to this browser. Ratings help faculty see which demos students find most useful.

Attribution & reuse

Created by Professor Vinaya Sathyanarayana as part of KateelLearningDemosToStudents. Please retain attribution and notify usage at vinallcontact@gmail.com. Architectural pattern inspired by the MIT-licensed alibaba/page-agent project (no code reused).