@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
Injected Execution Context
ToolExecutionContext parameter is allowed. It exposes the
tool call identity, step, abort signal, optional agent/turn identity, immutable
metadata, and correlated progress emission.
Using Tools
Related Types
ToolCall
Represents a tool invocation by the AI:ToolResult
Result from tool execution:result to ToolOutput:
ToolOutput.content accepts only TextPart, ImagePart, and FilePart.
Provider adapters normalize these parts to supported upstream formats and raise
UnsupportedToolOutputError when lossless conversion is unavailable.