@built-in-ai
@built-in-ai/web-llm

Agents

Build autonomous AI agents with @built-in-ai/web-llm and AI SDK v6

Basic Agent Example

Create an agent that can search the web and analyze content:

import { ToolLoopAgent, stepCountIs, tool } from 'ai';
import { webLLM } from "@built-in-ai/web-llm";
import { z } from 'zod';

const weatherAgent = new ToolLoopAgent({
  model: webLLM("Qwen3-1.7B-q4f16_1-MLC"),
  instructions: 'You are a weather assistant.',
  tools: {
    weather: tool({
      description: 'Get the weather in a location (in Fahrenheit)',
      inputSchema: z.object({
        location: z.string().describe('The location to get the weather for'),
      }),
      execute: async ({ location }) => ({
        location,
        temperature: 72 + Math.floor(Math.random() * 21) - 10,
      }),
    }),
    convertFahrenheitToCelsius: tool({
      description: 'Convert temperature from Fahrenheit to Celsius',
      inputSchema: z.object({
        temperature: z.number().describe('Temperature in Fahrenheit'),
      }),
      execute: async ({ temperature }) => {
        const celsius = Math.round((temperature - 32) * (5 / 9));
        return { celsius };
      },
    }),
  },
  // Agent's default behavior is to stop after a maximum of 20 steps
  // stopWhen: stepCountIs(20),
});

const result = await weatherAgent.generate({
  prompt: 'What is the weather in San Francisco in celsius?',
});

console.log(result.text); // agent's final answer
console.log(result.steps); // steps taken by the agent

For best agent results, use reasoning models like Qwen3 which handle multi-step reasoning better.

Check the Vercel documentation for more information.

On this page