Skip to content

defineTool

function defineTool<S, R>(config): Tool<InferToolInput<S>, R>;
Type Parameter Default type

S extends | ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>> | StandardSchemaV1<unknown, unknown> | undefined

undefined

R

unknown

Parameter Type Description

config

{ description: string; estimatedDurationMs?: number; execute: (args, ctx?) => Promise<R> | AsyncIterable<R, any, any>; filler?: string; idempotencyKey?: (args) => string; input?: S; interim?: string; interimAfterMs?: number; interruptible?: boolean; name?: string; needsApproval?: boolean; onError?: (error, args) => R | Promise<R>; output?: StandardSchemaV1<R, R>; parallelSafe?: boolean | ((args) => boolean); replay?: boolean; timeoutMs?: number; }

config.description

string

config.estimatedDurationMs?

number

config.execute

(args, ctx?) => Promise<R> | AsyncIterable<R, any, any>

config.filler?

string

config.idempotencyKey?

(args) => string

config.input?

S

config.interim?

string

config.interimAfterMs?

number

config.interruptible?

boolean

config.name?

string

config.needsApproval?

boolean

config.onError?

(error, args) => R | Promise<R>

Turns a thrown error into a result the model can act on, instead of a generic failure. Return a value to recover; rethrow (or omit this) to let the error propagate.

Runs only for genuine failures — never for a timeout, an abort, an input/output schema violation, or a control-flow signal, all of which must stay distinguishable from a result the tool chose to return.

config.output?

StandardSchemaV1<R, R>

config.parallelSafe?

boolean | ((args) => boolean)

Safe to run concurrently with sibling calls in the same model-emitted batch. A function form receives the RAW (unvalidated) model args — classification happens before schema validation — and must not throw; a throw or a non-boolean return is treated as NOT parallel-safe. Never model-controlled: the model cannot assert this, only the tool author.

config.replay?

boolean

config.timeoutMs?

number

Tool<InferToolInput<S>, R>