@browser-ai/core

Agents

Build autonomous AI agents with @browser-ai/core and AI SDK v7

Basic Agent Example

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

import { ToolLoopAgent, isStepCount, tool } from "ai";
import { browserAI } from "@browser-ai/core";
import { z } from "zod";

const weatherAgent = new ToolLoopAgent({
  model: browserAI(),
  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: isStepCount(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

Check the Vercel documentation for more information.

On this page