Browser automation for agents usually means serializing the entire DOM, sending it to an LLM, waiting for a decision, then repeating. Agent-First-Browse replaces that pattern with delta snapshots: incremental state diffs that track only what changed since the last agent step. Combined with LangGraph’s state graph orchestration, the result is a workflow engine that maintains context across navigation, dynamic content loads, and retries without re-parsing the full page every time.
The project targets web automation as a primitive for agent workflows, not standalone RPA. It sits between simple Playwright scripts and full agent platforms, exposing the plumbing needed to build multi-step browser tasks that remember what they’ve seen.
Why Delta Snapshots Matter
Traditional browser automation sends the full accessibility tree or DOM snapshot to the LLM on every turn. For a typical e-commerce page, that’s 50-200 KB of JSON per step. If your agent takes ten steps to complete a checkout flow, you’ve serialized the same header, footer, and navigation elements ten times.
Delta snapshots track state changes:
- Initial snapshot: Full accessibility tree or DOM structure.
- Subsequent snapshots: Only nodes that appeared, disappeared, or changed attributes.
- Navigation events: New page load triggers a fresh baseline, then deltas resume.
This cuts token costs by 60-80% on multi-step workflows. Latency drops because the LLM processes smaller payloads. The agent’s context window stays focused on what actually changed, not static chrome.
What Gets Tracked
The delta engine monitors:
- DOM mutations: New elements, removed nodes, attribute changes.
- Visibility shifts: Elements entering or leaving the viewport.
- Interactive state: Focus changes, form input updates, button state toggles.
- Network activity: XHR/fetch requests that signal dynamic content loads.
Each delta includes a timestamp and a reference to the previous snapshot ID, so the orchestrator can reconstruct full state if needed (for debugging or recovery).
LangGraph Integration
LangGraph provides the state machine layer. Instead of a linear Playwright script, you define a graph where nodes represent agent actions (click, type, wait, extract) and edges represent transitions based on page state or LLM decisions.
State Graph Structure
A typical checkout flow graph:
- Navigate → Load product page, capture initial snapshot.
- Select options → Agent reads delta (size dropdown appeared), chooses size.
- Add to cart → Click button, wait for cart modal delta.
- Proceed to checkout → Navigate, new baseline snapshot.
- Fill shipping → Type into form fields, track input deltas.
- Submit → Final action, extract confirmation number from delta.
Each node receives:
- Current delta snapshot.
- Full state history (compressed).
- LangGraph’s shared state object (session ID, user context, retry count).
Edges can be conditional. If the “Add to cart” delta shows an error modal instead of a success message, the graph routes to a retry node or fallback path.
What LangGraph Adds Over Raw Playwright
| Feature | Playwright Alone | LangGraph + Delta Snapshots |
|---|---|---|
| State persistence | Manual variables, no built-in checkpointing | Automatic state snapshots, replay from any node |
| Conditional branching | Nested if/else in script | Declarative edges with predicates |
| Retry logic | Try/catch blocks, custom backoff | Graph-level retry nodes, exponential backoff built-in |
| Observability | Console logs, custom instrumentation | Structured state transitions, LangSmith tracing |
| Multi-agent coordination | Not supported | Parallel subgraphs, message passing between agents |
The graph abstraction makes it easier to reason about failure modes. If the agent gets stuck in a loop (clicking the same button three times because the delta never shows the expected modal), LangGraph’s cycle detection can surface that as a graph topology issue, not a buried runtime bug.
Implementation Shape
The repository exposes two interfaces: a Python library and a Model Context Protocol (MCP) server.
Python Library
from agent_first_browse import BrowserAgent, DeltaTracker
agent = BrowserAgent(
headless=True,
delta_mode="accessibility-tree" # or "dom-snapshot"
)
tracker = DeltaTracker(agent)
# Initial navigation captures baseline
await agent.navigate("https://example.com/product")
baseline = tracker.current_snapshot()
# Agent action triggers delta
await agent.click("button[data-action='add-to-cart']")
delta = tracker.get_delta(since=baseline.id)
# Delta contains only the cart modal that appeared
assert delta.added_nodes[0].role == "dialog"
assert "Item added" in delta.added_nodes[0].text
The DeltaTracker maintains a sliding window of snapshots. You configure retention (default: last 10 snapshots or 5 minutes) to balance memory and replay capability.
MCP Server Mode
The MCP server wraps the agent in a tool-calling interface. LLMs can invoke:
navigate(url): Load page, return baseline snapshot.click(selector): Perform action, return delta.type(selector, text): Fill input, return delta.extract(selector): Pull text/attributes from current state.get_delta(since_id): Retrieve specific delta by snapshot ID.
This lets you plug the browser agent into any MCP-compatible orchestrator (LangChain, Semantic Kernel, custom frameworks). The agent becomes a stateful tool that remembers what it’s seen across multiple LLM turns.
State Management and Persistence
LangGraph checkpoints state at every node transition. For browser automation, that means:
- Snapshot history: Last N deltas stored in SQLite or Postgres.
- Session cookies: Persisted to disk, reloaded on retry.
- Form state: Input values cached, restored if the agent navigates back.
- Navigation stack: Full URL history with timestamps.
If the agent crashes mid-workflow, you can resume from the last checkpoint. The system reloads the browser session, navigates to the last known URL, and applies any pending deltas to reconstruct state.
Handling Dynamic Content
Single-page apps and infinite scroll break traditional snapshot approaches. Agent-First-Browse uses mutation observers to detect:
- Lazy-loaded content: New DOM nodes appearing after scroll or intersection.
- Optimistic updates: React/Vue components updating before server confirmation.
- WebSocket messages: Real-time data pushing new elements into the page.
The delta tracker debounces mutations (default: 300ms) to avoid capturing intermediate render states. You can configure debounce per workflow (e.g., 1 second for slow SPAs, 100ms for static sites).
Security Boundaries
Running an agent that clicks arbitrary links and fills forms requires isolation:
- Sandboxed browser contexts: Each agent session runs in a separate Playwright context with its own cookies, storage, and permissions.
- URL allowlists: Configure domains the agent can navigate to. Attempts to leave the allowlist fail fast.
- Action rate limits: Max clicks per minute, max form submissions per session.
- Credential vaulting: Secrets (passwords, API keys) injected via environment variables, never logged in deltas.
The MCP server adds an additional layer: tool calls require authentication tokens, and each token is scoped to specific domains and actions.
Observability
LangGraph’s built-in tracing captures:
- Node execution time: How long each click, type, or wait took.
- Delta size: Bytes added/removed per snapshot.
- LLM token usage: Prompt and completion tokens per decision.
- Error rates: Failed actions, retry counts, final outcomes.
You can export traces to LangSmith or any OpenTelemetry-compatible backend. The delta snapshots themselves are structured JSON, so you can replay a workflow in a debugger by stepping through the snapshot history.
Likely Failure Modes
| Failure | Cause | Mitigation |
|---|---|---|
| Stale selectors | Page redesign breaks CSS selectors | Use accessibility roles or data attributes, not brittle class names |
| Infinite loops | Agent clicks same element repeatedly | Graph cycle detection, max retry limits per node |
| Session expiry | Cookies timeout during long workflows | Checkpoint cookies, re-authenticate on 401/403 |
| Rate limiting | Site blocks agent after N requests | Exponential backoff, respect Retry-After headers |
| Delta drift | Mutation observer misses rapid updates | Increase debounce window, add manual sync points |
Deployment Shape
The project is designed for local development and self-hosted deployment. No managed service, no cloud dependencies.
Local: Run the MCP server on localhost:8080, connect your LLM orchestrator via HTTP.
Docker: Provided Dockerfile bundles Playwright, Chromium, and the Python runtime. Mount a volume for snapshot persistence.
Kubernetes: Deploy as a StatefulSet with persistent volumes for session state. Use a sidecar container for observability (Prometheus exporter scrapes delta metrics).
The browser agent is stateful, so horizontal scaling requires session affinity (sticky sessions) or a shared state backend (Redis for snapshot cache, Postgres for checkpoints).
Technical Verdict
Use Agent-First-Browse when:
- You need multi-step browser workflows that maintain context across navigation and dynamic content loads.
- Token costs and latency matter (delta snapshots cut both by 60-80%).
- You want declarative orchestration (LangGraph) instead of imperative Playwright scripts.
- You’re building an agent platform and need browser automation as a composable primitive.
Avoid it when:
- Your automation is single-step or stateless (plain Playwright is simpler).
- You need a managed service with SLA guarantees (this is self-hosted infrastructure).
- Your target sites use heavy anti-bot measures (delta tracking won’t bypass CAPTCHAs or fingerprinting).
- You require real-time collaboration (multiple agents sharing one browser session isn’t supported).
The delta snapshot pattern is the key insight. It turns browser automation from a stateless script into a stateful agent primitive. LangGraph provides the orchestration layer to make that state useful across complex workflows.
Source Links
- GitHub Repository: Agent-First-Browse
- Show HN Discussion: Hacker News