Skip to content

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

gemini example

Magnus Müllerf7c16976cb7f
diff --git a/examples/models/gemini.py b/examples/models/gemini.py
index 4ffdc0224..0b12f2ad7 100644
--- a/examples/models/gemini.py
+++ b/examples/models/gemini.py
@@ -5,7 +5,9 @@ from dotenv import load_dotenv
from langchain_google_genai import ChatGoogleGenerativeAI
from pydantic import SecretStr
-from browser_use import Agent
+from browser_use import Agent, BrowserConfig
+from browser_use.browser.browser import Browser
+from browser_use.browser.context import BrowserContextConfig
load_dotenv()
api_key = os.getenv('GEMINI_API_KEY')
@@ -14,14 +16,21 @@ if not api_key:
llm = ChatGoogleGenerativeAI(model='gemini-2.0-flash-exp', api_key=SecretStr(api_key))
+browser = Browser(
+ config=BrowserConfig(
+ new_context_config=BrowserContextConfig(
+ viewport_expansion=0,
+ )
+ )
+)
+
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'
- ),
+ task='Go to amazon.com, search for laptop, sort by best rating, and give me the price of the first result',
llm=llm,
max_actions_per_step=4,
+ browser=browser,
)
await agent.run(max_steps=25)