Build a typed browser agent with the Vercel AI SDK
Use Steel with the Vercel AI SDK v6 ToolLoopAgent for typed, tool-using browser agents.
Scaffolds a starter project locally. Requires the Steel CLI.
The Vercel AI SDK v6 ships ToolLoopAgent, a typed agent that picks a tool, calls it, observes the result, and decides the next step. Give it tools that drive a Playwright page connected to a Steel session and you get a terminal browser agent with no UI scaffolding in the way.
const researchAgent = new ToolLoopAgent({model: anthropic("claude-haiku-4-5"),instructions: "You operate a Steel cloud browser via tools...",stopWhen: [stepCountIs(15), hasToolCall("reportFindings")],tools: { openSession, navigate, snapshot, extract, reportFindings },onStepFinish: async ({ stepNumber, toolCalls, usage }) => { ... },});const result = await researchAgent.generate({ prompt: "..." });
reportFindings is the terminator. Its inputSchema is a Zod object (a summary string and an array of repo records) and it has no execute. In AI SDK v6, a tool with no execute stops the loop the moment the model calls it, and the call's input is your final typed answer. This sidesteps the Anthropic-on-tools issue where forcing JSON response format disables tool calling.
Run it
cd examples/vercel-ai-sdk-tscp .env.example .env # set STEEL_API_KEY and ANTHROPIC_API_KEYnpm installnpm start
Get keys at app.steel.dev/settings/api-keys and console.anthropic.com. The demo task is wired into main(): find the top 3 AI/ML repos on github.com/trending/python?since=daily and return name, URL, stars, and description.
Your output varies. Structure looks like this:
Steel + AI SDK v6 (ToolLoopAgent) Starter============================================================openSession: session=842ms cdp=411msstep 1: openSession | 1183 tokensnavigate: 1621msstep 2: navigate | 1402 tokenssnapshot: 124ms (3892 chars, 48 links)step 3: snapshot | 5104 tokensextract: 98ms (10 rows)step 4: extract | 2881 tokensstep 5: reportFindings | 3150 tokensAgent finished.Structured output:{"summary": "The top trending Python repos today center on...","repos": [{ "name": "owner/repo", "url": "...", "stars": "1,204", "description": "..." },...]}Releasing Steel session...Session released. Replay: https://app.steel.dev/sessions/ab12cd34...
A full run takes ~20 seconds and costs a few cents of Steel session time plus a small number of Anthropic tokens. The finally block in main calls steel.sessions.release().
Make it yours
- Swap the task. Change the
promptinmain()and thereportFindingsschema. Everything else is task-agnostic. - Swap the model.
claude-haiku-4-5is the default. For harder tasks, tryanthropic("claude-sonnet-4-6"),openai("gpt-5"), orgoogle("gemini-2.5-pro"). You can also use the AI Gateway string form, like"anthropic/claude-haiku-4-5", to route through Vercel. - Add tools. A
clicktool wrappingpage.click, afilltool overpage.fill, ascreenshottool that returns a base64 PNG for vision models. - Phase-gate steps. Use
prepareStepto restrict which tools are callable on a given step. See the AI SDK's loop control page. - Turn on stealth. Pass
useProxy,solveCaptcha, orsessionTimeouttosteel.sessions.create({...})insideopenSessionfor sites with anti-bot.
Related
Next.js version · AI SDK agents docs · ToolLoopAgent reference
Related recipes
Build a typed browser agent with Pydantic AI
Use Steel with Pydantic AI to build typed, provider-agnostic browser agents with dependency injection.
Build a typed browser agent with LangGraph
Use Steel with LangGraph to build a typed browser agent with an explicit state-machine loop and a structured-output formatter node.
Build a typed browser agent with Mastra
Use Steel with Mastra to build a typed browser agent with the Mastra Model Router and Studio playground.