How eonisailabs/browser-use works
Project type and purpose
• This is an open-source Python library (with CLI) that enables AI agents to control a web browser programmatically.
• Key features: agent orchestration, LLM integration, DOM extraction, controller/command execution, telemetry, filesystem interaction, multi-agent sync.
High-level component breakdown
A. Entry Points
– CLI (“browser-use”) and Python API (import browser_use.Agent)
– bin/setup.sh, bin/lint.sh, bin/test.sh (dev scripts)
B. Core Agent Layer
– Agent class (browser_use/agent/service.py)
– Message Manager (parses LLM responses into structured commands)
– Prompts & System Prompt templates (browser_use/agent/prompts.py, .md)
C. LLM Integration Layer
– Abstract base (browser_use/llm/base.py) and exceptions
– Provider adapters: OpenAI, Anthropic, Google, AWS (Bedrock & Anthropic), Azure, Groq, Ollama
– Serializer & parser per provider
D. Controller Layer
– Registry of commands/actions (browser_use/controller/registry)
– Services & Views to execute commands on the browser abstraction
– Tests for custom structured outputs
E. Browser Abstraction Layer
– Wrapper over Playwright (browser_use/browser/browser.py)
– Session, Profile, Context management
– Extensions, utilities, views for high-level browser actions
F. DOM Processing Layer
– Services to build and traverse DOM tree (buildDomTree.js, history tree, clickable element processor)
– Exposed views for agent to inspect page state
G. Filesystem, Sync, Telemetry, Tokens
– filesystem service to read/write files
– sync service for multi-agent event streaming & auth
– telemetry service to log events and metrics
– tokens service to count usage & cost
H. Configuration & Utilities
– browser_use/config.py, logging_config.py, utils.py
I. External Dependencies and Services
– Playwright (Chromium)
– LLM endpoints (OpenAI, Anthropic, etc.)
– Docker images (for cloud/CI use)
Interactions and data flow
1. User issues a task (via CLI or Python script) → Agent receives task + config
2. Agent sends a chat request to LLM adapter → receives text response
3. Message Manager parses response into structured commands (e.g., click, input, navigate)
4. Controller looks up command in registry → invokes Browser Service with parameters
5. Browser Service executes via Playwright → DOM Service extracts updated page state
6. Feedback loop: updated DOM fed back into prompts for next LLM request
7. Throughout:
• Telemetry logs each step,
• Tokens service accumulates cost,
• Filesystem service handles uploads/downloads or data persistence,
• Sync service propagates events if multiple agents are coordinating
Architectural patterns and principles
• Layered architecture (Entry → Agent → Domain Modules → Infra → External)
• Plugin/adapter pattern for LLM providers and controller commands
• Separation of concerns: parsing (message_manager), execution (controller), I/O (browser, filesystem), monitoring (telemetry)
• Registry pattern for discoverability of custom actions
• Test-driven design with extensive test suites for each module