AAI SDK
    Preparing search index...

    Function agent

    • Define an agent with tools, system prompt, and configuration.

      Applies sensible defaults for omitted fields. Export as the default export of your agent.ts file.

      Type Parameters

      • S = any

        Per-session state, inferred from the state factory. Tools are then checked against it, so a tool reading ctx.state under a different shape is a compile error rather than a runtime surprise.

      Parameters

      Returns AgentDef<S>

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

      const myTool = tool({
      description: "Echo a message",
      inputSchema: z.object({ message: z.string() }),
      execute: ({ message }) => message,
      });

      export default agent({
      name: "Echo Agent",
      tools: { echo: myTool },
      });

      Session mode: with no provider fields the agent runs the default all-AssemblyAI cascaded pipeline. Set any subset of stt, llm, tts to swap individual stages (unset stages keep the AssemblyAI default), and voice to pick the default pipeline's TTS voice — or set s2s (e.g. assemblyAIS2s()) to opt into the speech-to-speech path instead. See AgentDef for every field.

      import { agent } from "@alexkroman1/aai";

      export default agent({
      name: "My Agent",
      voice: "michael",
      llm: "claude-sonnet-4-6",
      });