Pydantic AI Toolsets for browser use
Project description
pai-browser-use
⚠️ Early Stage Project This project is currently in early development. APIs and features may change. We welcome your feedback and contributions!
- 🐛 Found a bug? Submit an issue
- 💡 Have ideas or suggestions? Join the discussion
- 🤝 Want to contribute? Check out our Contributing Guide
Pydantic AI Toolsets for browser automation using Chrome DevTools Protocol (CDP).
Inspired by browser-use, designed for Pydantic AI agents.
Features
- Browser Automation Tools: Navigation, state inspection, interaction, and element queries
- Multi-Modal Screenshots: Automatic image splitting for long pages with ToolReturn support
- Type-Safe CDP Integration: Direct access to cdp-use API with full type hints
- Fully Tested: Comprehensive test suite with Docker-based Chrome container
Installation
Use pip:
pip install pai-browser-use
Or use uv:
uv add pai-browser-use
Quick Start
Prerequisites
Start a Chrome instance with CDP enabled:
# Option 1: Using Chrome directly
google-chrome --remote-debugging-port=9222
# Option 2: Using Docker container
./dev/start-browser-container.sh
Basic Usage
import os
from pydantic_ai import Agent
from pai_browser_use import BrowserUseToolset
agent = Agent(
model="anthropic:claude-sonnet-4-5",
system_prompt="You are a helpful assistant.",
toolsets=[
BrowserUseToolset(cdp_url="http://localhost:9222/json/version"),
],
)
result = await agent.run("Find the number of stars of the wh1isper/pai-browser-use repo")
print(result.output)
See examples/agent.py for a complete example.
Configuration
BrowserUseToolset supports configuration via environment variables. See .env.example for all available options.
You can override environment variables by passing explicit parameters:
toolset = BrowserUseToolset(
cdp_url="http://localhost:9222/json/version",
max_retries=10, # Override PAI_BROWSER_USE_MAX_RETRIES
prefix="custom_browser", # Override PAI_BROWSER_USE_PREFIX
always_use_new_page=True, # Override PAI_BROWSER_USE_ALWAYS_USE_NEW_PAGE
auto_cleanup_page=False, # Override PAI_BROWSER_USE_AUTO_CLEANUP_PAGE
)
Priority: Explicit parameters > Environment variables > Defaults
Page Management
always_use_new_page: WhenTrue, creates a new browser page instead of reusing existing ones. Defaults toFalse.auto_cleanup_page: WhenTrue, automatically closes created pages on context exit. Defaults toFalse.
Use Case Examples:
# Default behavior: Reuse existing page, no cleanup needed
toolset = BrowserUseToolset(cdp_url="http://localhost:9222/json/version")
# Create new page but keep it open for debugging/inspection (default when using always_use_new_page)
toolset = BrowserUseToolset(
cdp_url="http://localhost:9222/json/version",
always_use_new_page=True, # Create fresh page
# auto_cleanup_page defaults to False - page remains open
)
# Create new page and automatically clean up (for production/batch processing)
toolset = BrowserUseToolset(
cdp_url="http://localhost:9222/json/version",
always_use_new_page=True, # Create fresh page
auto_cleanup_page=True, # Clean up after execution
)
Logging
Use PAI_BROWSER_USE_LOG_LEVEL environment variable to set logging level. The default is ERROR. Set to DEBUG for more verbose logging.
Development
# Install dependencies
uv sync
# Run tests
pytest tests/
# Run example
python examples/agent.py
# Try DEBUG logging demo (shows extracted content)
PAI_BROWSER_USE_LOG_LEVEL=DEBUG python demo_debug_logging.py
License
BSD 3-Clause License - see LICENSE for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pai_browser_use-0.3.0.tar.gz.
File metadata
- Download URL: pai_browser_use-0.3.0.tar.gz
- Upload date:
- Size: 180.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95e94cc36fb04b6b97db7cd6ea661bd47f82aa17b5962b3dbcfb142ced96801b
|
|
| MD5 |
1a4e6212ee596ac337dc54e2426d6745
|
|
| BLAKE2b-256 |
d163e8fcabc0516cfc2371a1868c3ff550bb3d3b0d1fbdc0cb180c805d88b78a
|
File details
Details for the file pai_browser_use-0.3.0-py3-none-any.whl.
File metadata
- Download URL: pai_browser_use-0.3.0-py3-none-any.whl
- Upload date:
- Size: 33.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72397336e46433c8c3a720d123b78599d42bb69b96e712a8c50828a0f8bfd8d0
|
|
| MD5 |
44b17a5a7554a68981f0b1ba66e930d2
|
|
| BLAKE2b-256 |
470179d4f5635e5979d71bafbee7fc087b264783d055425e88250719677e8423
|