For the complete documentation index, see llms.txt. This page is also available as Markdown.

Browser-Use with Any-LLM

Open In Colab

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-use unchanged

  • switch providers by changing one model string

  • avoid adding langchain-anyllm just 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 -q

Note: 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 install
import 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=true

  • restart the notebook kernel so browser-use can launch a fresh browser process

  • rerun browser-use install

  • on Linux or in containers, run python -m playwright install chromium --with-deps

  • switch to BROWSER_USE_HEADLESS=false only 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

  1. Run the smoke test once to show the adapter is real.

  2. Run the Hacker News task with BROWSER_USE_HEADLESS=false on your local machine.

  3. Change only MODEL to another provider/model string you already use with any-llm.

  4. Recreate llm = BrowserUseAnyLLM(model=MODEL, api_base=API_BASE, temperature=0.0).

  5. Re-run the same task and call out that the browser workflow stayed the same while the backend changed in one line.

Last updated