Skip to main content
Tools allow models to call functions during generation.

DefineTool()

Defines and registers a tool.

Type Parameters

any
required
Input type (must have JSON tags for schema generation)
any
required
Output type (must have JSON tags for schema generation)

Parameters

*Genkit
required
Genkit instance
string
required
Unique tool name
string
required
Description of what the tool does (helps model understand when to use it)
ToolFunc[In, Out]
required
Tool implementation functionSignature:
...ToolOption
Optional tool configurationAvailable options:
  • ai.WithInputSchema(map[string]any) - Custom input JSON schema
  • ai.WithInputSchemaName(string) - Reference registered schema

Returns

*ToolDef[In, Out]
Tool definition that can be passed to WithTools()

DefineMultipartTool()

Defines a tool that returns content parts (text + media).

Type Parameters

any
required
Input type

Parameters

Same as DefineTool() except function returns *MultipartToolResponse.

Returns

*ToolDef[In, *MultipartToolResponse]
Multipart tool definition

DefineToolWithInputSchema()

Deprecated: Use DefineTool() with ai.WithInputSchema() instead.
Defines a tool with custom input schema.

Tool Context

ToolContext

The ToolContext provides access to runtime information during tool execution.

Types

Tool

ToolDefinition

MultipartToolResponse

ToolDef

Example: Complete Tool Usage