@browser-ai/transformers-js
Agents
Build autonomous AI agents with @browser-ai/transformers-js 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 { transformersJS } from "@browser-ai/transformers-js";
import { z } from "zod";
const weatherAgent = new ToolLoopAgent({
model: transformersJS("onnx-community/Qwen3-0.6B-ONNX"),
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 agentFor best agent results, use reasoning models like Qwen3 which handle multi-step reasoning better.
Check the Vercel documentation for more information.