ToolTemplate class
Formats tool definitions for model prompts and parses tool calls from model output.
This class bridges between developer ToolDefinition objects and
model-specific prompt formats. It does NOT format conversation messages
(that is ChatTemplate's job). Instead, it builds the tool-aware
system prompt that gets passed to ChatTemplate.format.
Example:
final toolPrompt = ToolTemplate.formatToolSystemPrompt(
format: ChatTemplateFormat.qwen3,
tools: [weatherTool, searchTool],
systemPrompt: 'You are a helpful assistant.',
);
// toolPrompt contains Hermes-style tool definitions + system prompt
// Pass to ChatTemplate.format() as the systemPrompt parameter
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
formatToolSystemPrompt(
{required ChatTemplateFormat format, required List< ToolDefinition> tools, String? systemPrompt}) → String - Format tool definitions into a model-specific system prompt.
-
looksLikeToolCall(
{required ChatTemplateFormat format, required String output}) → bool - Quick check whether output looks like it contains a tool call.
-
parseToolCalls(
{required ChatTemplateFormat format, required String output}) → List< ToolCall> ? - Parse tool calls from model output.