Skip to main content
Tools allow models to interact with external systems or perform specific computations during generation.

defineTool()

Defines a tool that can be passed to models for automatic execution.

Parameters

Registry
required
The Genkit registry instance
ToolConfig
required
Tool configuration object
ToolFn<I, O>
Implementation function for the toolFunction signature:

Returns

ToolAction
A tool action that can be passed to model generation requests

tool()

Defines a dynamic tool that is not registered in the Genkit registry.

Parameters

Same as defineTool() except without the registry parameter.

Returns

ToolAction
A dynamic tool action (not registered)

Tool Interrupts (Beta)

Tools can interrupt execution to request user confirmation or additional input.

interrupt()

Creates an interrupt tool that pauses execution.

ToolAction.respond()

Responds to a tool interrupt with output data.
Parameters:
ToolRequestPart
required
The interrupt tool request to respond to
z.infer<O>
required
Response data matching the tool’s output schema
object
Record<string, any>
Additional metadata for the response
Returns: ToolResponsePart

ToolAction.restart()

Restarts a tool request after an interrupt.
Parameters:
ToolRequestPart
required
The interrupt tool request to restart
any
Metadata to pass to the tool on restart (defaults to true)
object
z.infer<I>
New input to replace the original tool input
Returns: ToolRequestPart

Types

ToolAction

ToolFnOptions

ToolRunOptions

Example: Complete Tool Definition