AAI SDK
    Preparing search index...

    Type Alias ToolDef<P, S>

    Definition of a custom tool that the agent can invoke.

    Tools are the primary way to extend agent capabilities. Each tool has a description (shown to the LLM), an optional input schema, and an execute function that runs inside the sandboxed worker.

    import { tool } from "@alexkroman1/aai";
    import { z } from "zod";

    const weatherTool = tool({
    description: "Get current weather for a city",
    inputSchema: z.object({
    city: z.string().describe("City name"),
    }),
    execute: async ({ city }) => {
    const res = await fetch(`https://wttr.in/${city}?format=j1`);
    return await res.json();
    },
    });
    type ToolDef<
        P extends ToolInputSchema = ToolInputSchema,
        S = DefaultSessionState,
    > = {
        description: string;
        inputSchema?: P;
        execute(args: InferSchemaOutput<P>, ctx: ToolContext<S>): unknown;
    }

    Type Parameters

    • P extends ToolInputSchema = ToolInputSchema

      The tool's input schema: any Standard Schema that can convert to JSON Schema — a Zod object schema (the documented default) or e.g. an ArkType type. Defaults to a permissive record schema so tools without inputs don't need an explicit type argument.

    • S = DefaultSessionState
    Index
    description: string

    Human-readable description shown to the LLM.

    inputSchema?: P

    Schema for the tool's input, shown to the LLM and used to validate each call's arguments before execute runs. Named after the Vercel AI SDK's tool({ inputSchema }).

    • Function that executes the tool and returns a result. The result is JSON-serialized for the LLM and the client, and capped at MAX_TOOL_RESULT_CHARS (4000) characters — longer results are trimmed and end with a [truncated] marker.

      Parameters

      Returns unknown