@built-in-ai/core
Agents
Build autonomous AI agents with @built-in-ai/core 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 { builtInAI } from "@built-in-ai/core";
import { z } from 'zod';
const weatherAgent = new ToolLoopAgent({
model: builtInAI(),
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 agentCheck the Vercel documentation for more information.