Open Agent Loops
API Reference

defineTool

@open-agent-loops/core


function defineTool<S>(tool): Tool<S>;

Defined in: tools/tools.ts:46

Author a tool while preserving the schema's inferred argument type for execute.

Type Parameters

Type ParameterDescription
S extends ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>The Zod schema type for the tool's arguments.

Parameters

ParameterTypeDescription
toolTool<S>The tool definition, including its argument schema and execute handler.

Returns

Tool<S>

The same tool, typed so execute receives fully-inferred arguments.

Remarks

This is an identity function at runtime — it returns its argument unchanged. Its only job is to bind the generic S to the supplied Zod schema so that the args parameter of execute is typed as z.infer<S> instead of the default z.ZodType. Always author tools through this helper to get that inference.

See

Tool

Example

import { z } from "zod";
import { defineTool } from "@open-agent-loops/core/tools/tools";

const addTool = defineTool({
  name: "add",
  description: "Add two numbers.",
  parameters: z.object({ a: z.number(), b: z.number() }),
  // `args` is inferred as { a: number; b: number }
  execute: (args) => ({ content: String(args.a + args.b) }),
});

On this page