While using the "ChatGoogleGenerativeAI" class getting error object GenerateContentResponse can't be used in 'await' expression

Issue Description :
While utilizing the ChatGoogleGenerativeAI class, I encountered a TypeError indicating that the object GenerateContentResponse cannot be used within an await expression.

Steps to Reproduce:

  1. Initialize the ChatGoogleGenerativeAI class with the appropriate parameters, including the model and API key.
  2. Attempt to call an asynchronous method, such as ainvoke, on the instance.
  3. Observe the TypeError indicating that GenerateContentResponse cannot be used in an await expression.
ERROR    [agent] ❌ Result failed 1/3 times:
 object GenerateContentResponse can't be used in 'await' expression

Note : I am using this class with the browser-use Agent class to perform a task. Can anyone help me with this, Please refer the below code for reference.

async def script_validation():
task = (
‘Important : I am UI Automation tester validating the tasks’
‘Open website https://www.google.co.in/
)
gemini_api_key = os.environ[“GEMINI_API_KEY”]
llm = ChatGoogleGenerativeAI(model=‘gemini-2.0-flash’, api_key=SecretStr(gemini_api_key), transport=“rest”)
agent = Agent(task=task, llm=llm, use_vision=True)
result = await agent.run()

asyncio.run(script_validation())

Can anyone please help ?

1 Like