Options
Agent(task, llm=None, *, ...). Everything after llm is keyword-only. Every parameter with its exact default: All parameters.
Options that 1.0 dropped raise a
TypeError before a browser starts, naming the replacement when there is one. A few 0.x tuning knobs (flash_mode, use_thinking, max_failures, …) log a warning and are ignored. See Migrating.
run()
await agent.run(max_steps=100, timeout=1700) returns an AgentHistoryList.
max_steps: model requests. The last one is a delivery-only turn: the agent must hand in what it has. One delivery repair request may follow it.timeout: seconds for the agent loop (model requests and cells). Starting the browser and stopping it are not counted. The delivery-only turn starts at 90% of the timeout, or up to 30 seconds before the end on timeouts under 300 seconds.- A run that hits either budget gets one delivery turn. If the agent delivers,
statusis'completed'andsuccessisFalsewhen it reports the task unfinished. If not,statusis'max_steps'or'timeout'; readresult.partial. See Long tasks. max_steps < 1ortimeout <= 0raisesValueErrorbefore any browser starts.- One
run()at a time perAgent, and one runningAgentperBrowser. Otherwiserun()raisesRuntimeError. - Configuration errors raise before any browser starts: a missing key (
MissingAPIKeyError), a removed option or bad argument (TypeError,ValueError), a Chrome or cloud profile name that matches none (browser_use.exceptions.BrowserConfigError, aValueError). After that,run()does not raise. A rejected key or model, a browser that fails to start (cloud create 402, 5xx or timeout) and failures inside the run returnstatus='error'with the reason inresult.error. Cancelling the task still raisesCancelledError.
run() ends, unless you pass Browser(keep_alive=True).
Sync and async
agent.run_sync(max_steps=100, timeout=1700) is run() without async. It raises inside a running event loop (async code, Jupyter); use await agent.run() there.
async with closes the agent and its browser when the block ends:
await agent.close() does the same by hand. After run_sync(), use agent.close_sync().
Cancel
Cancel the task that awaitsrun(). The browser stops.
loop.call_soon_threadsafe(task.cancel). To get a partial result back instead, bound the run with max_steps and timeout.
Highlights
While the agent works, orange corner brackets show for 1 second around the element it clicks, focuses or types into, so you can follow it in a visible browser or a cloud live view. They never show up in the agent’s own screenshots, and the page’s accessibility tree, text and clicks don’t see them. Turn them off:Writing tasks
The task is the agent’s only instruction. What helps:- Say where to start. “Open https://quotes.toscrape.com” beats “find a quotes site”.
- Say what done looks like. “Return the first 3 quotes with their authors as a list” beats “get some quotes”.
- Ask for a format, or pass
output_model_schemafor typed data. - Give the fallback. “If the page asks for a login, stop and report it.”
- Name your tools. With custom tools, say when to use them: “Use
get_2fa_codefor the code; never read it from the page.” - Keep secrets out of the task. Pass them as
sensitive_dataand refer to them by name.