Browser-Use with Any-LLM
This cookbook shows how to run browser-use with core any-llm locally.
browser-use uses its own lightweight async chat-model protocol internally, so the recipe below adds a tiny adapter around any_llm.acompletion. That keeps the demo simple:
keep
browser-useunchangedswitch providers by changing one
modelstringavoid adding
langchain-anyllmjust for this demo
Install the dependencies
If you are iterating on a local checkout of any-llm, replace the PyPI install below with an editable install from your repo path.
%pip install "any-llm-sdk[openai]" browser-use nest-asyncio python-dotenv -qNote: If you see a rich version conflict involving bigframes or pyiceberg, you can safely ignore it. Those packages are not used in this notebook.
!browser-use installimport nest_asyncio
# Jupyter already runs an event loop; nest_asyncio lets asyncio.run() and
# top-level await work inside it without raising "event loop already running".
nest_asyncio.apply()Choose a model
The default below uses OpenAI for the fastest first run, but the adapter works with any provider/model string supported by any-llm.
Create a tiny browser-use adapter
browser-use expects a chat model with its own async interface. This notebook adds a small adapter that translates browser-use messages and runtime metadata into any-llm calls.
Smoke test the adapter
It is worth confirming the model wiring before you launch a browser session.
Run a browser-use task
This task is public, easy to narrate, and looks good on video. The browser profile below defaults to headless=True, which is much more reliable in notebooks, containers, and remote Linux environments.
Set BROWSER_USE_HEADLESS=false only if you are running locally on your own laptop or desktop and want to record the visible browser.
Troubleshooting
If you see Cannot connect to host 127.0.0.1:<port>, the local Chromium process died before its CDP endpoint came up.
Try this:
keep
BROWSER_USE_HEADLESS=truerestart the notebook kernel so
browser-usecan launch a fresh browser processrerun
browser-use installon Linux or in containers, run
python -m playwright install chromium --with-depsswitch to
BROWSER_USE_HEADLESS=falseonly on a local desktop or laptop when you want to record video
Also let Agent.run() start the browser session for you. Pre-starting and reusing half-failed sessions makes notebook debugging harder.
Video flow
Run the smoke test once to show the adapter is real.
Run the Hacker News task with
BROWSER_USE_HEADLESS=falseon your local machine.Change only
MODELto another provider/model string you already use withany-llm.Recreate
llm = BrowserUseAnyLLM(model=MODEL, api_base=API_BASE, temperature=0.0).Re-run the same task and call out that the browser workflow stayed the same while the backend changed in one line.
Last updated