Stagehand is the SDK for browser agents.
This template uses LangChain Deep Agents for the reasoning loop and Stagehand V4 code mode for the browser. The agent opens San Francisco's official Open Data API, finds an exact DBA record, and returns a validated Pydantic object.
create_deep_agentowns planning, model calls, and structured output.- Stagehand code mode exposes one persistent Browserbase session through
run,snapshot, andscreenshotMCP tools. - Vercel AI Gateway supplies the bring-your-own agent model.
- The Stagehand MCP server runs in an isolated
uvxenvironment because the current Stagehand and Deep Agents clients require differentwebsocketsversions. - The template closes the MCP session and browser process automatically.
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 Stagehand Deep Agents integration from stagehand/main in uvx; the
integration pins its Stagehand server dependency to stagehand==4.0.0.
The agent opens the official SF Open Data JSON endpoint and returns the exact Jalebi Street record, including its business account number, location ID, address, NAICS data when present, and the official source URL. The script exits nonzero if the returned DBA or evidence source does not match.
BROWSERBASE_API_KEY: launches the Browserbase session.AI_GATEWAY_API_KEY: authenticates the Deep Agents model through Vercel AI Gateway.DEEPAGENTS_MODEL: optional model override; defaults toanthropic/claude-sonnet-4.6.STAGEHAND_RUN_TIMEOUT_MS: optional browser-tool timeout; defaults to 120 seconds.