Agentic Browser

AI agent for web automation and scraping, designed to plan, execute, and verify actions across any website

Component interactions and data flow

Introduction#

Request paths across side panel, background/content scripts, WebSocket, FastAPI, and the LangGraph agent, including HTTP fallback.

Project structure#

Pieces:

  • Extension (React UI, background script, content script, WebSocket client, utilities)
  • Backend API (FastAPI app, routers, services, models)
  • Agents and tools (LangGraph-based React agent, tool registry)
  • MCP server (external service integration)

Core components#

  • WebSocket client encapsulates connection lifecycle, event handling, and agent execution over WebSocket with automatic reconnection.
  • Side panel UI manages user input, command parsing, progress updates, and browser storage-backed sessions.
  • Background script handles cross-tab automation, content script injection, and runtime messaging.
  • Content script provides page context and executes DOM-level actions.
  • HTTP execution utility builds payloads, captures page context, and invokes backend endpoints.
  • Backend API exposes routers for agents, tools, and services; runs on Uvicorn.
  • React agent orchestrates LLM reasoning and tool execution via LangGraph.

Architecture overview#

The system supports two primary execution modes:

  • Real-time via WebSocket: UI emits commands; backend streams progress and returns results.
  • HTTP fallback: UI sends commands via HTTP; backend responds with completion.

Detailed component analysis#

WebSocket client and real-time execution#

  • Establishes persistent connections with automatic reconnection and transport fallback.
  • Emits connection status and generation progress events.
  • Provides executeAgent, stopAgent, and stats APIs with timeouts and cleanup.

Side panel UI and command parsing#

  • Parses slash commands into agent/action endpoints and validates availability.
  • Manages sessions, voice input, file attachments, and mention menus.
  • Streams progress updates and renders Markdown responses.

HTTP execution pipeline#

  • Resolves active or mentioned tab context, captures client HTML, normalizes URLs, and constructs payloads.
  • Supports special endpoints (React agent, YouTube, website, GitHub, PyJIIT, skills).
  • Uses GET/POST based on endpoint and returns structured responses.

Browser automation and content scripts#

  • Background script injects content scripts and routes actions to active tabs.
  • Content script performs DOM-level actions (click, type, scroll) and page info extraction.
  • Action executor translates agent action plans into tab messages.

Backend API and agent orchestration#

  • FastAPI app aggregates routers for agents, tools, and services.
  • Uvicorn runner starts the server on a configurable host/port.
  • React agent compiles a LangGraph workflow and executes tool calls asynchronously.

Dependency analysis#

  • UI depends on WebSocket client and HTTP execution utility.
  • Background script depends on content script and browser APIs.
  • HTTP execution utility depends on browser storage, tabs, and scripting APIs.
  • Backend API depends on routers and the React agent.
  • React agent depends on LLM and tool registry.

Performance considerations#

  • WebSocket streaming reduces latency for long-running agent executions; HTTP fallback ensures reliability when WebSocket is unavailable.
  • Payload construction captures minimal client HTML and limits DOM introspection to reduce overhead.
  • Action executor introduces small delays between actions to prevent race conditions and improve stability.
  • Caching: React agent graph is cached via LRU to avoid recompilation costs.
  • Recommendations:
  • Prefer WebSocket for interactive sessions; degrade to HTTP.
  • Limit DOM capture size and scope; avoid unnecessary reflows.
  • Batch browser actions and debounce UI updates.

Troubleshooting guide#

  • WebSocket connectivity:
  • Monitor connection_status events and fallback to HTTP when disconnected.
  • Use getStats with timeout to detect backend responsiveness.
  • Command parsing:
  • Ensure slash commands are complete; partial suggestions guide users.
  • Browser automation:
  • Verify content script injection and tab permissions.
  • Handle unknown action types and timeouts during navigation/reload.
  • HTTP errors:
  • Normalize error messages for rate limits, gateway errors, and service unavailability.
  • Storage and sessions:
  • Persist sessions in browser storage; migrate legacy chat history if needed.

Conclusion#

UI → transport → agent → tools → browser. WebSocket streams when it can; HTTP covers the rest. State lives where the component that needs it can see it.