Deterministic-First, Self-Healing Browser Execution Runtime with Closed-Loop Experience Distillation.
Web automation workflows frequently break due to UI drift, selector churn, layout refactors, and dark-pattern retention traps. Standard browser agents solve drift by throwing thousands of LLM tokens at every stepβintroducing unacceptable latency (15β45s) and recurring API costs.
driftless-playwright combines the raw sub-second speed of deterministic Playwright scripts with an adaptive 3-Tier Live Self-Healing Pipeline and Closed-Loop Experience Distillation:
- Deterministic Fast Path (
0LLM Tokens): Executes complex multi-step workflows in ~1.0β1.8s using versioned Playbooks and a 4-level Ranked Locator Waterfall. - Never-Break Live Self-Healing: Catches selector misses and dark pattern retention modals mid-flight on the active page without restarting the browser or losing session cookies.
- Closed-Loop Experience Distillation: When Tier 2/3 agent recovery navigates through unexpected retention traps, winning trajectories are verified by a deterministic Verification Judge and automatically compiled back into deterministic Playwright playbooks (
Playbook_v2). - Session Resilience & Handoff: Provides persistent
storage_statereuse, 2FA OTP handoffs (CLI & webhook), and CAPTCHA tripwire takeovers.
Designed as the core browser execution engine for embedded digital banking infrastructure:
| Pillar | Technical Solution | Code Component |
|---|---|---|
| 1. IDENTIFY | Live extraction of merchant subscription metadata, plan tiers, cadence, renewal dates, and payment instruments from merchant DOM. | RecurringBillAnalyzer.identify_recurring_bill |
| 2. UNDERSTAND | Audits recurring charges against historical banking transaction baselines; detects hidden price hikes (e.g. +$3.00/mo) and retention traps. |
RecurringBillAnalyzer.audit_bill |
| 3. MANAGE (IRIS) | Flagship Biller Action Suite: β’ 1-Click Cancellation: Navigates cancellation while blocking upsell traps. β’ Virtual Card Switching: Injects Driftless-Playwright protected cards vault://card/virtual_4242 into billing forms to lock charges.β’ Bill Savings: Applies negotiated promotional codes/retention discounts. β’ Plan Changes: Downgrades subscription tiers to reduce consumer burn. β’ Subscription Pausing: Temporarily suspends billing cycles. |
IrisActionEngine, DriftlessPlaywrightActionDispatcher, SecretVault |
IrisActionEngine powers in-app automated merchant connectivity across 60+ financial institutions:
- Oscillation Between Agentic & Deterministic Execution: Agents explore and conquer novel or changed billers; winning runs pass through compliance Eval Gates to compile into instant, zero-token deterministic playbooks.
-
Merchant Anti-Bot Classification & Tiering:
- Tier 1 (Standard): Headless Chromium, direct network egress (e.g., standard SaaS portals).
- Tier 2 (Stealth Residential): Anti-fingerprinting stealth arguments, residential proxy egress (e.g., Netflix, Spotify).
- Tier 3 (Headful Handoff): Interactive headful browser session with user-in-view for aggressive bot walls or retention chat (e.g., NYT).
- Tier 4 (Graceful Fallback): For manual/phone-only billers (e.g., Planet Fitness), Iris never silently failsβit produces structured, actionable fallback guides with pre-drafted cancellation emails and phone numbers.
-
Eval Gates & Compliance Rule: Iris never reports a cancellation it did not complete. Promoted instruction sets require verified 200 OK network mutations, DOM status confirmation, zero guardrail violations, and a reward score
$\ge 8.0$ .
The runtime implements a 3-tier adaptive agent hierarchy (exported via driftless_playwright.agents):
-
Tier 1:
Tier1SemanticAgent(nomic-embed-text+ VisualpHash)-
Cost / Latency:
0LLM Chat Tokens,<100ms. -
Role: Fast semantic locator healer. Scans visible interactive elements and evaluates a 4-factor scoring function:
$$\text{Score} = 0.45 \cdot \text{CosineSim}(\text{text}) + 0.25 \cdot \text{RoleMatch} + 0.20 \cdot \text{pHashSim} + 0.10 \cdot \text{BBoxProximity}$$ - When score
$\ge 0.82$ , patches the Ranked Locator Waterfall in-place without waking the LLM.
-
Cost / Latency:
-
Tier 2:
Tier2DOMAgent(Scopedbrowser-useMicro-Agent,use_vision=False)-
Model:
qwen2.5vl:7bresident in Ollama (or cloud frontier models via OpenAI API). -
Cost / Latency: ~150 tokens,
2β5s. -
Role: Scoped to bridge from a broken state past dark-pattern retention traps, popups, and surveys until
step.post_conditionis reached. Governed byGuardrailsInterceptorto block trap buttons ("Switch to Annual Billing").
-
Model:
-
Tier 3:
Tier3VisionAgent(Set-of-Marks Multimodal Vision Agent,use_vision=True)-
Model:
qwen2.5vl:7b(same loaded model in memory,0msswap). -
Optimization: Crops Region of Interest (ROI) to save vision tokens:
$\frac{W \times H}{28 \times 28}$ . -
Role: On-demand visual grounding for unlabeled
<svg>buttons, canvas controls, or visual dialogs when DOM text alone is insufficient.
-
Model:
For complete architectural specifications, the multi-tier self-healing execution state machine, and OpenTelemetry distributed tracing details, see DESIGN_AND_ARCHITECTURE.md:
- Architecture & Component Design Flowchart: Visual state machine of the fast path, 3-tier self-healing cascade, and experience distillation compiler.
- Observability & OpenTelemetry (o11y) Architecture: Microsecond-precision spans, W3C trace propagation, and telemetry endpoints (
/health,/api/v1/telemetry/stats,/dashboard).
Run the showcase directly via:
python demo/demo.py --gif| Scene | Story Stage | What Happens in the Demo |
|---|---|---|
| Scene 1 | User Taps Cancel in Bank | Inside Apex Digital Bank (/bank), user spots the Price Hike Alert on StreamPulse Ultra 4K ($22.99/mo), taps "Cancel Subscription", and confirms via the in-app savings modal ("Save $275.88/yr"). |
| Scene 2 | Headful Auth & Iris Takeover | User authenticates in-view on the merchant portal (/merchant/login) via 1-click biometric Face ID. Iris takes over via Playwright CDP, maintaining the authenticated session in Zero-Trust mode. |
| Scene 3 | Agentic Run on Novel Merchant (Agents Taking Actions for Agents) | In-app execution displays live progress ("Accessing your account..." POST /api/subscription/cancel -> 200 OK. |
| Scene 4 | Verified & Reported Back to Bank | Celebratory confetti screen displays π ("Cancellation successful β’ $275.88 Saved Per Year"). VerificationJudge and PlaybookEvalGate confirm 200 OK mutation and DOM confirmation badge (decision: PROMOTED). The result reports back to the banking app with monthly recurring spend reduced. |
| Scene 5 | Closed-Loop Convergence into Playbook v2 | Iris compiles the winning trajectory into deterministic Playbook_v2. Subsequent runs execute on the retention flow with 0 LLM Tokens in ~1.1s ($0 AI cost). |
| Scene 6 | Fallback to Agent on Flow Drift | When the merchant changes their selector (v2_minor), the deterministic path detects drift and seamlessly falls back to the Tier 1 Semantic Agent (nomic-embed-text), auto-healing in <95ms. |
| Scene | Stage | UI / Execution Mode | Tokens | Latency | Outcome |
|---|---|---|---|---|---|
| Scene 1 | Banking App 1-Tap Cancel | Apex Digital Bank (/bank) |
0 |
0.8s | β Tap "Cancel Subscription" |
| Scene 2 | Headful Merchant Auth Handoff | StreamPulse Login (/merchant/login) |
0 |
0.9s | β Auth In-View & Iris CDP Takeover |
| Scene 3 | Agentic Run on Novel Merchant | Unseen Dark Pattern Trap (/billing) |
148 | 2.1s | β Guardrail Agent Blocks $199 Annual Trap |
| Scene 4 | Report Back to Banking App | Eval Gate Verification (200 OK) |
0 |
0.5s | β Verified & Reported to Bank ($275/yr Saved) |
| Scene 5 | Compiled Deterministic Payoff | Deterministic Playbook v2 | 0 |
1.1s | β Fast Path (0 Tokens, $0 AI Cost) |
| Scene 6 | Fallback to Agent on Flow Drift | Changed Selector Drift (v2_minor) |
0 |
1.0s | β Tier 1 Semantic Agent Auto-Healed (<95ms) |
Never rely on brittle absolute XPaths (/html/body/div[1]/...). Every StepAnchor resolves elements using a 4-priority waterfall:
- Priority 1 β Accessibility Role + Name:
role=button[name='Cancel Membership'i] - Priority 2 β Stable Semantic Attributes:
css=[data-testid='cancel-btn'], button[aria-label='Cancel'] - Priority 3 β Text-Anchored Relative XPath:
xpath=//section[contains(., 'Billing')]//button[contains(normalize-space(), 'Cancel')] - Priority 4 β Relative Bounding Box Fallback:
bbox=[0.72, 0.45]
When autonomous agent recovery executes, guardrails.py actively blocks dark patterns and malicious retention traps before a click is dispatched:
- Blocked Keywords:
["upgrade", "annual plan", "buy now", "save 20%", "keep membership", "reactivate"]. - Idempotency Lock: Tracks state-changing endpoints (e.g.
POST /api/subscription/cancel). If a mutation has already succeeded with200 OK, duplicate submissions on retries are blocked immediately.
Never trust an LLM calling done(success=True) on its own.
step_reward = (
+1.0 * progressed_to_post_condition
-0.2 * action_latency_penalty
-0.5 * triggered_dom_validation_error
-1.0 * repeated_dom_state_hash
)
terminal_reward = (
+10.0 if (network_mutation_200_ok and dom_confirmation_present and not error_banner_visible)
else -10.0
)- Network Mutation Listener: Verifies
POST /api/subscription/cancelreturned200 OK. - DOM Confirmation Gate: Verifies confirmation badges (
Status: Canceled). - Error Banner Check: Ensures no error toast or alert banners are visible.
Optimized for 24 GB Unified Memory on Apple Silicon:
Total System RAM: 24.0 GB
OS & Chromium Headless: 7.5 GB
Safe LLM RAM Budget: 16.5 GB max
Resident Ollama Models (0ms Swap):
βββ nomic-embed-text (Tier 1 Embeddings): 0.3 GB
βββ qwen2.5vl:7b (Tier 2/3 Text + Vision): 5.5 GB
βββ KV Cache Allocation: 2.0 GB
Total AI Resident Footprint: ~7.8 GB (Safe within budget)
Because driftless-playwright uses standard OpenAI-compatible endpoints, swap seamlessly to frontier cloud models (gpt-4o, Claude, Gemini) with zero code changes:
export LLM_BASE_URL="https://api.openai.com/v1"
export LLM_API_KEY="sk-..."
export LLM_MODEL="gpt-4o"# Clone the repository
git clone https://github.com/driftless-playwright/driftless-playwright.git
cd driftless-playwright
# Create virtual environment
python3.12 -m venv .venv
source .venv/bin/activate
# Install dependencies and Chromium
pip install -e .
playwright install chromiumpytest -v# Headless run with demo/demo.gif generation:
python demo/demo.py --gif
# Headed visible Chromium run:
python demo/demo.py --headedWhen running tests or the demo server, open the dark-mode telemetry flight recorder at:
http://localhost:8000/dashboard
driftless-playwright/
βββ pyproject.toml # Dependencies & build configuration
βββ README.md # System documentation & showcase GIF
βββ HANDOFF.md # Complete architectural & technical specification
βββ DESIGN_AND_ARCHITECTURE.md # System design, state machines & o11y architecture
βββ scripts/
β βββ start.sh # Starts the sandbox portal & telemetry server (port 8000)
β βββ stop.sh # Stops running sandbox portal instances
βββ demo/
β βββ demo.py # Interactive showcase runner
β βββ demo.gif # 6-Scene animated showcase demo
βββ driftless_playwright/
β βββ __init__.py # Public package exports
β βββ iris.py # IrisActionEngine: Driftless-Playwright's flagship agentic execution engine
β βββ action_agents.py # 6 specialized biller action agents + unified dispatcher
β βββ merchant_tiering.py # 4-tier anti-bot classification & graceful fallback generator
β βββ eval_gates.py # PlaybookEvalGate: safe promotion of agent runs to playbooks
β βββ config.py # Ollama URLs, timeouts, paths, memory thresholds
β βββ schemas.py # Pydantic v2 schemas: Playbook, StepAnchor, ExecutionReceipt
β βββ embeddings.py # 768-dim nomic-embed-text + deterministic token-hash fallback
β βββ router.py # Contextual Bandit router + resilient_step() orchestrator
β βββ locator_waterfall.py # 4-level waterfall resolver + Tier 1 semantic/visual patch healer
β βββ visual_diff.py # ImageHash pHash, SSIM visual delta, ROI crop utilities
β βββ agent_bridge.py # Scoped browser-use bridge, Guardrails hooks, modal survey solver
β βββ guardrails.py # Pre-action policy interceptor (blocks upgrade traps & idempotency lock)
β βββ handoff.py # Persistent storage_state, 2FA OTP broker, CAPTCHA takeover
β βββ vault.py # Zero-trust credential & payment card injector
β βββ verifier.py # Deterministic reward equations & network mutation judge
β βββ compiler.py # Distills winning agent trajectories into Playbook v2 JSON
β βββ telemetry.py # Flight recorder: Playwright traces, receipts, failure taxonomy
β βββ playbooks/
β βββ merchant_billing_v1.json
βββ sandbox_portal/ # Chaos mock merchant portal & telemetry dashboard
β βββ __init__.py
β βββ mock_data.py # Pre-seeded test accounts and subscription state
β βββ server.py # FastAPI server supporting ?version=v1, v2_minor, v2_dark_pattern, 2fa, captcha
βββ tests/
βββ test_iris_and_merchant_tiering.py # Iris, merchant tiering, eval gates, and fallbacks
βββ test_action_agents.py # Cancellation, card swap, bill savings, plan changes
βββ test_recurring_bills_domain.py # Driftless-Playwright domain pillars (Identify, Understand, Manage)
βββ test_opentelemetry_endpoints.py # Health, stats, OpenTelemetry trace spans
βββ test_locator_healing.py # 4-level waterfall & semantic embedding similarity
βββ test_guardrails.py # Policy interceptor & idempotency lock tests
βββ test_reward_verifier.py # Step/terminal reward math & receipt tests
βββ test_e2e_self_healing.py # End-to-end 4-act self-healing, 2FA, and CAPTCHA tests
