import { Agent } from "@ai_kit/core";
import { Output } from "@ai_kit/core/agents";
import { z } from "zod";
import { openaiProvider } from "@ai-sdk/openai";
const siretOutput = Output.object({
schema: z.object({
siret: z.string().length(14, "Must contain 14 digits."),
}),
});
const assistantSiret = new Agent({
name: "assistant_siret",
instructions:
"You find SIRET identifiers by combining web search and business directories.",
model: openaiProvider("gpt-4.1-mini"),
tools: {
web_search: openaiProvider.tools.webSearch({}),
},
toon: true, // default to TOON for every generate() call
});
const result = await assistantSiret.generate({
prompt:
'Find the SIRET of "Aidalinfo". Return only the 14-digit ID as a string.',
structuredOutput: siretOutput,
});
console.log(result.experimental_output);
// -> { siret: "38347481400100" }