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 Large Language Models (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:
Copy
Ask AI
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({});// Initialize the AI agent with GPT-5.1const agent = new Agent({ model: openai('gpt-5.1'), tools: { playwright_execute: playwrightExecuteTool({ client: kernel, sessionId: browser.session_id, }), }, 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 { text, steps, usage } = await agent.generate({ prompt: 'Go to news.ycombinator.com, find the top 3 posts, and summarize them',});console.log('Agent response:', text);console.log('Steps taken:', steps.length);console.log('Token usage:', usage);await kernel.browsers.deleteByID(browser.session_id);
const result = await generateText({ model: openai('gpt-5.1'), prompt: 'Go to producthunt.com and extract the top 5 product names and descriptions', tools: { playwright_execute: playwrightTool, },});
const agent = new Agent({ model: openai('gpt-5.1'), tools: { playwright_execute: playwrightTool, }, stopWhen: stepCountIs(10), system: 'You are a form filling assistant.',});const result = await agent.generate({ prompt: 'Navigate to example.com/contact, fill out the contact form with name "John Doe" and email "john@example.com", and submit it',});
const result = await generateText({ model: openai('gpt-5.1'), prompt: 'Visit github.com/onkernel/kernel-nextjs-template, extract the README content, and count how many code examples are shown', tools: { playwright_execute: playwrightTool, },});
If the LLM isn’t using the tool, make your prompt more explicit:
Copy
Ask AI
const result = await generateText({ model: openai('gpt-5.1'), prompt: 'Use the Playwright tool to navigate to example.com and extract the page title', tools: { playwright_execute: playwrightTool, },});
If you’re experiencing timeout errors, the LLM can request longer timeouts by including the timeout_sec parameter in the generated Playwright code execution request.