createGadget
createGadget<
TSchema>(config):AbstractGadget
Defined in: gadgets/create-gadget.ts:123
Creates a gadget from a function (simpler than class-based approach).
This is perfect for simple gadgets where you don’t need the full power of a class. Parameters are automatically typed from the schema.
Type Parameters
Section titled “Type Parameters”TSchema
Section titled “TSchema”TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>
Parameters
Section titled “Parameters”config
Section titled “config”CreateGadgetConfig<TSchema>
Configuration with execute function and schema
Returns
Section titled “Returns”Gadget instance ready to be registered
Examples
Section titled “Examples”import { z } from 'zod';import { createGadget } from 'llmist';
// Simple calculator gadgetconst calculator = createGadget({ description: "Performs arithmetic operations", schema: z.object({ operation: z.enum(["add", "subtract", "multiply", "divide"]), a: z.number().describe("First number"), b: z.number().describe("Second number"), }), execute: ({ operation, a, b }) => { // Parameters are automatically typed! switch (operation) { case "add": return String(a + b); case "subtract": return String(a - b); case "multiply": return String(a * b); case "divide": return String(a / b); } },});// Async gadget with custom name and timeoutconst weather = createGadget({ name: "weather", description: "Fetches current weather for a city", schema: z.object({ city: z.string().min(1).describe("City name"), }), timeoutMs: 10000, execute: async ({ city }) => { const response = await fetch(`https://api.weather.com/${city}`); const data = await response.json(); return `Weather in ${city}: ${data.description}, ${data.temp}°C`; },});// Use with agentconst agent = LLMist.createAgent() .withGadgets(calculator, weather) .ask("What's the weather in Paris and what's 10 + 5?");