Stagehand is the SDK for browser agents.
This template pairs a bring-your-own Gemini model with LangChain Deep Agents and Stagehand V4 code mode. The agent researches the next two visible solar eclipses in North America, cross-checks live NASA and Timeanddate sources, and cites only URLs it opened in the browser.
create_deep_agentowns the Gemini reasoning and tool loop.- Stagehand code mode exposes one persistent Browserbase session through
run,snapshot, andscreenshotMCP tools. - Vercel AI Gateway provides the Gemini model through its OpenAI-compatible endpoint.
- Closing the MCP session shuts down the Stagehand client and Browserbase browser.
Requirements: Python 3.11–3.13 and uv.
cp .env.example .env
# Add BROWSERBASE_API_KEY and AI_GATEWAY_API_KEY to .env.
uv sync
uv run python main.pyThe first run installs the pinned Stagehand Deep Agents integration in uvx; the integration pins
its Stagehand server dependency to stagehand==4.0.0.
The agent returns the expected dates of the next two visible solar eclipses in North America and the live source URLs it opened. The script exits nonzero only when the agent workflow itself fails.
BROWSERBASE_API_KEY: launches the Browserbase session.AI_GATEWAY_API_KEY: authenticates Gemini through Vercel AI Gateway.DEEPAGENTS_MODEL: optional model override; defaults togoogle/gemini-3-flash-preview.STAGEHAND_RUN_TIMEOUT_MS: optional browser-tool timeout; defaults to 120 seconds.