defineTool creates a validated, type-safe tool definition usable by Agent.
Parameters
ToolDefinition
required
Configuration object describing tool behavior:
ToolContext Parameter
Theexecute function receives a ToolContext instance as its second argument:
Record<string, unknown>
KeyValue store for run metadata (e.g., user session details).
(undo: () => Promise<void>) => void
Function used to register a compensating action executed if a later tool call in the same batch fails.
Schema Serialization
kenpachi includes a universal Zod schema serializerserializeZodSchema(schema: z.ZodTypeAny) that transforms any Zod definition into a standard JSON Schema object (type: "object", properties, required), automatically stripping non-standard fields (like $schema) for LLM provider compliance: