AI SDK
AI SDK tool
An AI SDK tool whose output is the details plus the text.
- title
- Text Slug
- inputSchema
- jsonSchema()
- output
- details + text
- failure
- thrown
Access
- Import
import { toAiTool } from "@agntn/tools/ai" - Peer
ai >=7.0.0 <8 - Fails
thrown, tool error
import { toAiTool, toAiTools } from "@agntn/tools/ai";
import { slugTool, tools } from "./tools.ts";
const one = toAiTool(slugTool);
const all = toAiTools(tools); // keyed by tool name
The schema goes through the AI SDK's jsonSchema() with the core's validator attached. So the model sees the same JSON Schema every other host sees, and a bad input gets refused with the same lines. No second schema in Zod. That used to be the fourth copy.
The output
execute returns the details with the text added: { ...details, text }. The AI SDK hands that object to the model as JSON, so it gets the structured facts and the sentence a human would read. When details isn't an object, you get { details, text }.
A details object with its own text field would lose it under the spread, so the adapter throws a ToolDefinitionError instead of guessing. Rename the field.
Failures
A bad input is refused by the input schema before execute. A result with isError throws its text, and the AI SDK turns any throw into a tool error the model can read.
Types
toAiTool keeps the input and details types. When you export the tool from a package, annotate it with your own types, Tool<SearchParams, AiToolOutput<SearchDetails>>. The inferred type points into the bundled TypeBox, and your declaration build can't name it.