2025, Oct 04 23:00

Fix the Expected type 'BaseChatModel' error when wiring Browser Use Agent to Google Gemini: use ChatGoogle instead of LangChain

Resolve the Expected type 'BaseChatModel' error when wiring Browser Use Agent with Google Gemini. Use ChatGoogle instead of LangChain for a clean setup.

Fixing “Expected type 'BaseChatModel'” when wiring Browser Use Agent with Gemini

Building an AI Automation Agent for UI testing should be straightforward, yet a small mismatch between libraries can derail the setup. A common stumbling block is trying to pass a LangChain-driven Google Gemini client directly into the Browser Use Agent and getting a type error. Below is a minimal reproduction and a clear path to a working configuration.

Problem setup

The environment uses Python 3.1x with PyCharm, and the libraries installed include browser-use, pydantic, langchain, and google-generative-ai. The Agent is initialized with a Gemini-backed LLM instance:

from browser_use.agent.service import Agent
from langchain_google_genai import ChatGoogleGenerativeAI
async def run_ui_check():
    scenario = (
        'I am a UI automation UI tester validating this task'
        'Open the website https://www.google.com'
    )
    genai_client = ChatGoogleGenerativeAI(model='', api_key='')
    Agent(scenario, genai_client)

This produces the following exception:

Expected type 'BaseChatModel', got 'ChatGoogleGenerativeAI' instead

Why this happens

Browser Use ships with its own LLM interface and a curated set of supported models. The Agent expects an object that conforms to its internal BaseChatModel contract. The LangChain adapter ChatGoogleGenerativeAI is not the type the Agent is designed to accept, so the runtime raises a type mismatch error. In other words, you’re handing the Agent a client from a different abstraction layer than the one it supports.

The solution

Use the LLM integration provided by Browser Use itself for Google Gemini. The library exposes a ChatGoogle class that matches the Agent’s expectations. Replace the LangChain client with this adapter and pass it to the Agent. The model selection follows what Browser Use documents for Gemini support.

from browser_use.agent.service import Agent
from browser_use.llm import ChatGoogle
async def run_ui_check():
    scenario = (
        'I am a UI automation UI tester validating this task'
        'Open the website https://www.google.com'
    )
    llm_adapter = ChatGoogle(model='gemini-2.0-flash-exp')
    Agent(scenario, llm_adapter)

This aligns the Agent with a compatible LLM implementation and removes the type error.

Why this matters

AI tooling ecosystems evolve quickly, and different frameworks wrap models behind their own interfaces. Mixing adapters across ecosystems can look fine at the import level yet fail at runtime due to differing expectations. Knowing which LLM wrapper a framework natively supports saves time, prevents brittle glue code, and makes the behavior predictable.

Takeaways

When using Browser Use, pair the Agent with an LLM class that the library explicitly supports. For Google Gemini, instantiate the ChatGoogle class provided by Browser Use and set the model accordingly. If you encounter a type mismatch, double-check that the LLM object comes from the Browser Use integration rather than from another SDK. Keeping the abstractions consistent is the simplest path to a stable automation agent.

The article is based on a question from StackOverflow by user12730187 and an answer by Selcuk.