$ show ntegrals/openbrowser
This repository is a TypeScript monorepo for an AI-powered autonomous web browsing agent called 'open-browser'. It consists of three packages: core library (open-browser), CLI (@open-browser/cli), and sandbox (@open-browser/sandbox). The core library orchestrates an agent loop that uses Playwright to control a Chromium browser, extracts DOM state via CDP, sends it to an LLM (OpenAI, Anthropic, Google) which decides actions in structured JSON, and executes those actions via a CommandExecutor. The system supports vision screenshots, extended thinking, compact mode, planning, evaluation, replay recording, and MCP server integration. The CLI provides commands for running agents, interactive sessions, and direct browser manipulation. The sandbox provides resource-limited execution. Key entry points include the Agent class, Viewport browser session, CommandExecutor, and BridgeServer. External dependencies include Playwright, Vercel AI SDK, Zod, Turndown, and various LLM provider SDKs. The architecture follows a modular monorepo with clear separation of concerns, event-driven communication via EventHub, and a guard/watchdog pattern for browser lifecycle management. The codebase demonstrates strong engineering practices with extensive use of Zod schemas for structured outputs, a command catalog pattern, and comprehensive telemetry and cost tracking.
The LLM identified 4 files worth highlighting for reuse:
ConversationManager handles the full lifecycle of agent conversation history: tracking messages, token estimation, history items, ephemeral messages, basic compaction (screenshot removal, old-message replacement), and LLM-based compaction with summarization schema. It also supports redaction, save/load, and integration with the agent's execution log. This component is reusable for any LLM agent that needs structured conversation state management with compaction strategies.
StallDetector monitors agent progress by hashing DOM and text content and tracking action fingerprints. It detects when the agent is stuck in a loop or making no meaningful progress, allowing the system to intervene or abort. The pattern is generic and can be applied to any autonomous agent loop that produces observable state snapshots and actions.
EventHub provides a typed event bus with history replay and a timed() telemetry wrapper. It enables loose coupling between components (viewport, guards, agent) and supports event-driven architecture. The implementation is clean, generic, and can be extracted for use in any TypeScript application requiring a lightweight event system with history.
BridgeServer implements the Model Context Protocol (MCP) over stdio and SSE, providing tools/list, tools/call, resources/list/read/subscribe, and progress notifications. It exposes browser resources (state, DOM, screenshot, tabs) and integrates with the agent's command catalog. This is a standalone MCP server implementation that could be reused or adapted for other MCP-compatible systems.