Skip to main content

Import

import {
  tool,
  dynamicTool,
  toolRegistry,
  executeTool,
} from "veryfront/tool";

Examples

Basic tool

import { tool } from "veryfront/tool";
import { z } from "zod";

const weather = tool({
  id: "weather",
  description: "Get current weather for a city",
  inputSchema: z.object({ city: z.string() }),
  execute: async ({ city }) => {
    const res = await fetch(`https://api.weather.com/${city}`);
    return res.json();
  },
});

Use with an agent

import { tool } from "veryfront/tool";
import { agent } from "veryfront/agent";
import { z } from "zod";

const weather = tool({
  id: "weather",
  description: "Get current weather for a city",
  inputSchema: z.object({ city: z.string() }),
  execute: async ({ city }) => {
    const res = await fetch(`https://api.weather.com/${city}`);
    return res.json();
  },
});

const assistant = agent({
  model: "openai/gpt-4o",
  system: "You help with weather questions.",
  tools: [weather],
});

API

tool(config)

Create typed tool (Zod-validated)
PropertyTypeDescription
id?stringTool identifier (optional, inferred from filename)
descriptionstringTool description for the AI model
inputSchemaz.ZodSchema<TInput>Input schema (Zod schema)
allowUnknownSchema?booleanAllow unknown/non-Zod schemas to fall back to a permissive JSON schema.
execute(input: TInput, context?: ToolExecutionContext) => Promise<TOutput> | TOutputTool execution function
mcp?{ enabled?: boolean; requiresAuth?: boolean; cachePolicy?: “no-cache” | “cache” | “cache-first” }MCP configuration
Returns: Tool<TInput, TOutput>

Exports

Functions

NameDescription
dynamicToolCreate tool with runtime schema
executeToolExecute tool by ID
toolCreate typed tool (Zod-validated)

Types

NameDescription
DynamicToolConfigdynamicTool() config
JsonSchemaJSON Schema for tool input
ToolTool instance (returned by tool() function)
ToolConfigTool configuration options
ToolDefinitionProvider-facing tool definition used for model/tool registration.
ToolExecutionContextContext passed to tool execution

Constants

NameDescription
toolRegistryGlobal tool registry