Skip to content

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.

TSchema extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>

CreateGadgetConfig<TSchema>

Configuration with execute function and schema

AbstractGadget

Gadget instance ready to be registered

import { z } from 'zod';
import { createGadget } from 'llmist';
// Simple calculator gadget
const 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 timeout
const 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 agent
const agent = LLMist.createAgent()
.withGadgets(calculator, weather)
.ask("What's the weather in Paris and what's 10 + 5?");