Tools
Tools let an agent take actions and fetch data. They're typed with Zod, so inputs are validated before your code runs.
Creating a tool
tools.ts
import { createTool } from '@redtuma/core/tools'
import { z } from 'zod'
export const getWeather = createTool({
id: 'get-weather',
description: 'Get the current weather for a city.',
inputSchema: z.object({ city: z.string() }),
execute: async ({ context }) => {
// context is the validated input
return { city: context.city, tempC: 21 }
},
})The id is the tool name presented to the model, and description tells it when to use the tool. Attach tools to an agent under any key:
const agent = new Agent({
id: 'assistant',
instructions: '...',
model: 'anthropic/claude-opus-4-8',
tools: { getWeather },
})Execute context
execute receives the validated context, a per-call runtimeContext, and an abortSignal.
execute: async ({ context, runtimeContext, abortSignal }) => {
const userId = runtimeContext.get('userId')
const res = await fetch(url, { signal: abortSignal })
return res.json()
}AI SDK tools
Redtuma tools and raw AI SDK tools are both accepted in an agent's tools map. Convert a single Redtuma tool to the AI SDK shape with toAISDKTool when you need it.