Browser Automation Agent (WebPilot)
Covers: agent orchestration, computer use, human takeover, trace replay, FastAPI + Next.js Status: not started | Priority P1 (after the "AI Document Review Pipeline" MVP is done)
1. Business scenario
B2B customers have many legacy systems without APIs (government filing websites, supplier portals, internal OA systems), and operations staff repeat "log in → search → fill in the form → submit → screenshot for the record" every day. Build an agent: the user describes a task in natural language (or picks a preset flow), and the agent carries it out automatically in an isolated browser. When it meets a CAPTCHA, a confirmation prompt or a field it's unsure about, it pauses and asks a human to take over, and the whole run can be replayed for audit.
It connects directly to the "AI Document Review Pipeline": approved invoice results can be entered by WebPilot into the customer's legacy web ERP automatically.
2. Architecture and technology choices
Next.js console ── create tasks / live view (screenshot stream) / step timeline / "Take over" button
│ SSE/WebSocket
FastAPI ── Agent Runner (tool calling loop)
│ ├─ Observe: page accessibility tree / trimmed DOM + screenshot
│ ├─ Decide: the LLM picks a tool (click/type/select/scroll/wait/ask_human/done)
│ └─ Act: Playwright (an isolated browser in Docker)
├─ Safety layer: domain allowlist, forced human confirmation for high-risk actions (submit/pay/delete), step and time limits
└─ Traceability: every step stores screenshot + observation summary + model output + action + result| Component | Choice | Why |
|---|---|---|
| Browser control | Playwright (Python) | Stable, supports accessibility tree snapshots, can record traces |
| Perception | Hybrid: prefer accessibility tree / numbered DOM elements (cheap, accurate), fall back to screenshots + vision model coordinates (general) | Being able to explain the trade-off between the two approaches is an interview highlight |
| Decision model | A model that supports tool calling; optionally compare against vendors' computer use tool APIs | Compare success rate and cost of a "home-grown DOM agent" vs "vendor computer use" |
| Agent loop | Hand-written loop (no framework), optionally refactored with LangGraph | Writing it by hand first is what lets you explain the principles; the framework is for state persistence and interrupt/resume |
| Isolation | One containerized browser per task | Safety and concurrency |
| Frontend | Next.js + screenshot stream + timeline | Lets humans watch in real time and take over at any moment |
⚠️ Vendor computer use APIs (Anthropic's computer use tool, OpenAI's related agent capabilities) are still iterating quickly; follow the official docs as of 2026-11 for parameters and model names. The mobile use direction can extend to Appium / ADB + accessibility trees on the same principles.
3. Implementation plan (about 2–3 weeks)
| Stage | Content | Acceptance |
|---|---|---|
| D1–3 | Wrap Playwright as a tool set: goto/click(id)/type(id,text)/select/scroll/screenshot/get_a11y_tree; number the interactive elements | A script completes a fixed flow on the demo site |
| D4–6 | Hand-written agent loop: observe → LLM decides (tool calling) → act → send the result back; max steps, per-step timeout, tool errors returned to the model for self-correction | Completes "search for and download a report on the demo site" from natural language |
| D7–9 | Human takeover: an ask_human tool + interception of high-risk actions; the task suspends, and after "Take over" in the frontend a human acts or fills in the answer, then the agent continues | Pauses automatically on a CAPTCHA and resumes |
| D10–12 | Trace replay: every step's screenshot and decision stored, timeline replay in the frontend; one-click "retry from step N" for failed tasks | For any failed task, find which step failed and why the model did what it did |
| D13–15 | Evaluation: 10–20 fixed tasks, measuring success rate, average steps and cost; compare DOM mode vs screenshot mode vs vendor computer use | Evaluation report written into the README |
4. Hard problems and highlights
| Hard problem | Solution |
|---|---|
| Too many page elements, context blows up | Only interactive elements + the visible area; numbered elements; summarize past steps |
| Actions fail / the page hasn't finished loading | After acting, wait for network idle or for the element to appear; send failure info back to the model; hand over to a human after the same action fails N times |
| The agent drifts off course or loops forever | Max steps, repeated-state detection (same page hash + same action), goal checkpoints |
| Safety | Domain allowlist, human confirmation for sensitive actions, credentials never in the prompt (injected by the tool layer) |
| Explainability | Every step saves "what it saw → what it wanted to do → what it did → the result" |
5. Résumé description (STAR)
Browser Automation Agent | Independent design and development
- S: Many of the customer's business systems had no API, and operations staff had to repeat data entry and lookups across several web systems every day.
- T: Build an agent that understands natural-language tasks, operates web pages automatically, and asks a human to take over when unsure.
- A: Hand-wrote the agent execution loop on Playwright + LLM tool calling, with a hybrid perception approach based mainly on numbered accessibility tree elements and supplemented by screenshot-based visual targeting; designed
ask_humanand high-risk action interception for human takeover, with tasks that can suspend and resume; stored every step's screenshot and decision for replay and audit; built a fixed-task eval set to compare perception approaches. - R: Success rate X% on an eval set of N tasks, X steps on average, ¥X cost per task; human time on a given flow down X% after adoption. (Use measured numbers.)
6. Related knowledge base pages
- Agent: tool calling loop, computer use, safety
- Reliability: human takeover, timeouts and retries
- Frontend: live view and timeline
