Skip to content

Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.

Gemini example

magmueller4137db40c9ba
diff --git a/examples/gemini.py b/examples/gemini.py
new file mode 100644
index 000000000..9d7dd77c7
--- /dev/null
+++ b/examples/gemini.py
@@ -0,0 +1,33 @@
+import asyncio
+import os
+
+from dotenv import load_dotenv
+from langchain_google_genai import ChatGoogleGenerativeAI
+from langchain_ollama import ChatOllama
+from pydantic import SecretStr
+
+from browser_use import Agent
+
+load_dotenv()
+api_key = os.getenv('GEMINI_API_KEY')
+if not api_key:
+ raise ValueError('GEMINI_API_KEY is not set')
+
+llm = ChatGoogleGenerativeAI(model='gemini-1.5-pro', api_key=SecretStr(api_key))
+
+
+async def run_search():
+ agent = Agent(
+ task=(
+ 'Go to url r/LocalLLaMA subreddit and search for "browser use" in the search bar and click on the first post and find the funniest comment'
+ ),
+ llm=llm,
+ max_actions_per_step=4,
+ tool_call_in_content=False,
+ )
+
+ await agent.run(max_steps=25)
+
+
+if __name__ == '__main__':
+ asyncio.run(run_search())