Skip to main content

Overview

The Tools system is the bridge between the LLM and browser actions. It provides a registry of actions the agent can perform, handles parameter validation, and manages action execution. Each tool is a function that the LLM can call to interact with the web.

Architecture

Registry

Centralized catalog of available actions

Action Models

Pydantic models for type-safe parameters

Parameter Injection

Automatic dependency injection from context

Result Handling

Structured responses with ActionResult

The Tools Class

The Tools class (line 345 in tools/service.py) manages the action registry:

Creating a Tools Instance

Default Browser Actions

Search the web using a search engine
Implementation (line 362 in tools/service.py):
  • Encodes query for URL safety
  • Constructs search URL for specified engine
  • Navigates to search results
  • Returns: "Searched {engine} for '{query}'"

Interaction Actions

Click an element by index or coordinate
Implementation (line 565 for index, line 521 for coordinate):
  • Looks up element from selector_map
  • Highlights element visually
  • Detects if click opens new tab
  • Handles special cases (dropdowns, file inputs)
  • Returns: "Clicked {element_description}"
Coordinate clicking is auto-enabled for Claude Sonnet 4, Claude Opus 4, Gemini 3 Pro, and Browser Use models.

Content Extraction

Extract structured data from page using LLM
Implementation (line 947):
  1. Extracts clean markdown from page (removes ads/noise)
  2. Chunks content if over 100k chars
  3. Calls page_extraction_llm with query
  4. Returns structured or free-text result
  5. Saves to file if result is large
Content Processing:
  • Original HTML → Initial Markdown → Filtered Markdown
  • Structure-aware chunking (preserves tables, lists)
  • Overlap context for continuation chunks
  • Stats included in response
Returns: <url>...</url><query>...</query><result>...</result>

Tab Management

Switch to another tab
Returns: "Switched to tab #{tab_id}"

File Operations

Upload file to input[type=file]
Implementation (line 721):
  • Validates file exists and has content
  • Finds file input near selected element
  • Falls back to closest file input to scroll position
  • Returns: "Successfully uploaded file"
Files must be in available_file_paths parameter when creating the agent.

Form Controls

Get dropdown options
Returns all options with values and text.

Completion

Complete the task
Signals task completion with final output.

Creating Custom Tools

Basic Custom Tool

Tool with Browser Access

Critical: The parameter must be named exactly browser_session with type BrowserSession. Parameter injection works by name matching.

Tool with Multiple Injections

Available injectable parameters (line 77 in tools/service.py):

Domain-Restricted Tools

ActionResult Response

The ActionResult class structures tool responses:
ActionResult Fields:
  • extracted_content: Main result text (shown to agent)
  • error: Error message if action failed
  • is_done: Mark task as complete
  • success: Whether task succeeded (for done action)
  • attachments: List of file paths
  • metadata: Additional structured data
  • long_term_memory: Summary for agent’s memory
  • include_extracted_content_only_once: Show full content once, use memory after

Parameter Injection System

The tools system automatically injects context based on parameter names:
The injection happens at execution time, not registration. You don’t need to pass these values when registering tools.

Tools Registry

The Registry class manages action registration:

Excluding Default Actions

Remove actions you don’t need:
Common exclusions:
  • screenshot: When use_vision != 'auto'
  • search: For domain-restricted tasks
  • upload_file: For read-only tasks

Coordinate Clicking

Enable coordinate-based clicking for advanced models:
When enabled, click action accepts coordinates:

Structured Output Integration

Define expected output format:

Real-World Examples

Human-in-the-Loop

API Integration

Database Access

Deterministic Automation

Performance Considerations

Use search_page and find_elements for fast, LLM-free lookups:

Troubleshooting

Check:
  • Tool description is clear and specific
  • Parameter types are correct
  • Tool isn’t excluded in Tools(exclude_actions=[…])
  • Domain restrictions don’t block current page
Verify:
  • Parameter name matches exactly (e.g., browser_session)
  • Type hint is correct (e.g., BrowserSession)
  • Parameter is available in current context
Ensure:
  • Return type is ActionResult or str
  • Don’t raise exceptions, return ActionResult(error=’…’)
  • Use proper field names (extracted_content, not content)

Next Steps

Available Tools

Complete list of default actions

Add Custom Tools

Detailed guide to creating tools

Tool Response

Advanced ActionResult patterns

Actor API

Playwright-like browser control