Skip to main content
Tools enable AI models to call functions in your code. ai-query provides the @tool decorator and Field helper for type-safe tool definitions.

The @tool Decorator

Decorator Parameters

str
Optional description of what the tool does. If omitted, ai-query uses the function docstring or a generated fallback.

The Field Helper

Field Parameters

str
required
Description of the parameter shown to the AI.
Any
Default value. If provided, the parameter becomes optional.
list[Any]
Optional fixed set of allowed values for the parameter.
float
Optional minimum numeric value.
float
Optional maximum numeric value.

Supported Types

Unrecognized annotations fall back to string inference. If you need full control, use the factory form and pass parameters explicitly.

Examples

Simple Tool

Async Tool

Optional Parameters

Nested Parameters

Manual Schema Override

Using Tools

ToolCall

Represents a tool invocation by the AI:

ToolResult

Result from tool execution:

Accessing Tool Calls