@threadplane/chatFunctionv0.3.4

action

Declare an async function tool the model can call; its resolved return value becomes the tool result shipped back to the model.

import { action } from '@threadplane/chat';

Declaration · overload 1

export declare function action<S extends StandardSchemaV1, R>(description: string, schema: S, handler: (args: StandardSchemaInferOutput<S>, context: FunctionToolHandlerContext) => R | Promise<R>, options?: ClientToolExecutionOptions): FunctionToolDef<S, R>;

Type parameters

R

Parameters

description · required
string

Natural-language description the model sees.

schema · required
S

Standard Schema (e.g. a Zod object) for the arguments; the handler's argument type is inferred from it.

handler · required
(args: StandardSchemaInferOutput<S>, context: FunctionToolHandlerContext) => R | Promise<R>

Runs in the browser when the model calls the tool. The second argument carries an AbortSignal; its return type R is carried on the resulting FunctionToolDef.

options · optional
ClientToolExecutionOptions

Execution policy options, including idempotent: true to skip durable pre-execution claims when a guard is configured.

Returns

FunctionToolDef<S, R>

A FunctionToolDef for inclusion in tools.

Examples

const move = action('Move a stop', z.object({ fromDay: z.number() }), (a) => a.fromDay);
const registry = tools({ move_stop: move });