pythonpython-3.xlangchaingoogle-generativeaibrowser-use

Expected type 'BaseChatModel', got 'ChatGoogleGenerativeAI' instead In Agent AI


I am trying to create a AI Automation Agent for my QA project .

I have Python 3.1x installed, PyCharm as IDE. I have imported browser-use, pydantic, lang chain, google-generative-ai libraries from the settings of PyCharm.

Next, I have created a task and specified agent as below.

from browser_use.agent.service import Agent
from langchain_google_genai import ChatGoogleGenerativeAI

async def SiteValidation():
    task = (
        'I am a UI automation UI tester validating this task'
        'Open the website https://www.google.com'
    )
    llm=ChatGoogleGenerativeAI(model='',api_key='')
    Agent(task,llm)

But the llm parameter [i.e Agent(task,llm)] throws an error. It says as below.

Expected type 'BaseChatModel', got 'ChatGoogleGenerativeAI' instead 

I have tried downgrading the version as well. Nothing worked.


Solution

  • The Browser Use library comes with its own list of supported models. To use a Google (Gemini) model you should import ChatGoogle and use that instead as explained in their documentation:

        from browser_use.llm import ChatGoogle
        ...
        llm = ChatGoogle(model='gemini-2.0-flash-exp')