The @onkernel/ai-sdk package provides Vercel AI SDK-compatible tools for browser automation powered by Kernel. This package exposes a Playwright execution tool that allows LLMs to browse the web, interact with websites, and perform automation tasks through natural language instructions.With this tool, AI agents can execute Playwright code on Kernel’s remote browsers, enabling powerful browser automation capabilities in your AI-powered applications.
For more complex, multi-step automation tasks, use the Vercel AI SDK’s Agent() class. Agents can autonomously plan and execute a series of actions to accomplish a goal:
import 'dotenv/config';import { openai } from '@ai-sdk/openai';import { playwrightExecuteTool } from '@onkernel/ai-sdk';import { Kernel } from '@onkernel/sdk';import { Experimental_Agent as Agent, stepCountIs } from 'ai';const kernel = new Kernel({ apiKey: process.env.KERNEL_API_KEY,});const browser = await kernel.browsers.create({});const sessionId = browser.session_id;console.log('Browser session started:', sessionId);console.log('Browser session URL:', browser.browser_live_view_url);// Initialize the AI agent with GPT-5.1const agent = new Agent({ model: openai('gpt-5.1'), tools: { playwright_execute: playwrightExecuteTool({ client: kernel, sessionId }), }, stopWhen: stepCountIs(20), // Maximum 20 steps system: `You are a browser automation expert. You help users execute tasks in their browser using Playwright.`,});// Execute the agent with the user's taskconst result = await agent.generate({ prompt: 'Go to news.ycombinator.com and get the titles of the top 3 posts.',});console.log('Agent response:', result.text);await kernel.browsers.deleteByID(browser.session_id);