Agent class is the main entry point for Browser Use. It orchestrates the LLM, browser interactions, and tools to complete tasks autonomously.
Constructor
Parameters
str
required
The task description for the agent to complete.
BaseChatModel
required
Language model instance. Defaults to
ChatBrowserUse() if not provided. See Supported Models.Browser | None
Browser instance to use. If not provided, a new browser will be created with default settings.
BrowserSession | None
Deprecated: Use
browser parameter instead. Alias for backward compatibility.Tools[Context] | None
Registry of tools (actions) the agent can use. If not provided, default tools are loaded. See Tools.
Tools[Context] | None
Deprecated: Use
tools parameter instead. Alias for backward compatibility.LLM Configuration
BaseChatModel | None
Separate LLM for page content extraction. Use a smaller/faster model for efficiency. Defaults to main
llm.BaseChatModel | None
LLM for judging agent trace quality. Defaults to main
llm.BaseChatModel | None
Fallback LLM to use if the primary LLM fails.
Vision & Screenshots
bool | Literal['auto']
default:"True"
Vision mode:
True: Always include screenshots in LLM contextFalse: Never include screenshots, excludes screenshot tool'auto': Include screenshot tool but only use vision when requested
Literal['auto', 'low', 'high']
default:"'auto'"
Screenshot detail level for vision models.
tuple[int, int] | None
Target size
(width, height) to resize screenshots before sending to LLM. Coordinates from LLM are automatically scaled back to original viewport size.Skills Integration
list[str | Literal['*']] | None
List of skill IDs to enable, or
['*'] for all skills. Skills are pre-built actions from the cloud.list[str | Literal['*']] | None
Deprecated: Use
skills parameter instead. Alias for backward compatibility.Any | None
Pre-configured skill service instance for advanced use cases.
Actions & Behavior
list[dict[str, dict[str, Any]]] | None
List of actions to execute before starting the main task (without LLM). Format:
[{'action_name': {'param': value}}]int
default:"5"
Maximum actions the agent can output per step (e.g., for form filling).
int
default:"5"
Maximum consecutive failures before stopping.
bool
default:"True"
If
True, agent attempts one final recovery call after reaching max_failures.bool
default:"True"
Enable explicit reasoning steps in agent output.
bool
default:"False"
Fast mode that skips evaluation, planning, and thinking. Overrides
use_thinking and enable_planning when enabled.bool
default:"True"
If
True, automatically navigate to URLs detected in the task.Planning
bool
default:"True"
Enable agent planning with step-by-step todo items.
int
default:"3"
Number of consecutive failures before suggesting plan revision. Set to
0 to disable.int
default:"5"
Number of steps without a plan before nudging agent to create one. Set to
0 to disable.Loop Detection
bool
default:"True"
Enable detection of repetitive action patterns.
int
default:"20"
Rolling window size for tracking action similarity.
System Messages
str | None
Completely replace the default system prompt.
str | None
Add additional instructions to the default system prompt.
File & Data Management
str | Path | None
Directory path to save conversation history.
str
default:"'utf-8'"
Encoding for saved conversations.
list[str] | None
List of file paths the agent can access for upload actions.
str | None
Path for agent’s file system operations.
bool
default:"True"
Show file information in completion messages.
dict[str, str | dict[str, str]] | None
Dictionary of sensitive data to handle securely. Format:
{key: value} or {domain: {key: value}}.Output Format
type[AgentStructuredOutput] | None
Pydantic model class for structured output validation. See Custom Output.
dict | None
JSON schema for data extraction. Auto-detected from
output_model_schema if not provided.Visual Output
bool | str
default:"False"
Generate GIF of agent actions. Set to
True or a file path string.list[str] | None
List of HTML attributes to include in DOM analysis.
Performance & Limits
int | None
Maximum number of recent steps to keep in LLM memory.
None keeps all steps.int
default:"90"
Timeout in seconds for LLM calls. Auto-detected based on model.
int
default:"180"
Timeout in seconds for each agent step.
MessageCompactionSettings | bool | None
default:"True"
Compact old messages to reduce prompt size. Set to
False to disable or provide MessageCompactionSettings for custom configuration.int
default:"40000"
Maximum characters for clickable elements in prompt.
Judge & Validation
bool
default:"True"
Enable post-execution judge to validate task completion.
str | None
Ground truth answer for judge validation.
Cloud Callbacks
Callable | None
Callback function called after each step. Signature:
(BrowserStateSummary, AgentOutput, int) -> None | Awaitable[None]Callable | None
Callback function called when agent completes. Signature:
(AgentHistoryList) -> None | Awaitable[None]Callable[[], Awaitable[bool]] | None
Callback to check if agent should stop. Returns
True to stop.Callable[[], Awaitable[bool]] | None
Callback to check external agent status. Raises
InterruptedError if returns True.Advanced Options
bool
default:"False"
Calculate and track API token costs.
bool
default:"False"
Include tool usage examples in system prompt.
bool
default:"False"
Include recent browser events in context.
list[ContentPartTextParam | ContentPartImageParam] | None
Sample images to include in prompts for vision models.
bool | None
Enable demo mode with browser overlay UI.
str | None
Custom task ID. Auto-generated if not provided.
AgentState | None
Pre-existing agent state for resuming sessions.
str | None
Source identifier for telemetry.
Methods
run()
Execute the agent to complete the task.int
default:"100"
Maximum number of steps the agent can take.
AgentHistoryList
Complete execution history with results, screenshots, and metadata.
step()
Execute a single step of the task.AgentStepInfo | None
Optional step information including step number and max steps.
add_new_task()
Add a follow-up task to the agent.str
required
The new task description.
stop()
Stop the agent execution gracefully.kill()
Force-stop the agent and clean up resources.Properties
state
AgentState
Current agent state including step counter, failures, and internal state.
history
AgentHistoryList
Complete history of agent actions and results.
browser_session
BrowserSession
The browser session instance being used.
tools
Tools[Context]
The tools registry containing all available actions.
settings
AgentSettings
Agent configuration settings.