llm_tool_calling library
Annotate Dart functions with @Tool() and get LLM tool definitions:
JSON schema, argument validation and type-safe dispatch.
Add llm_tool_calling_generator and build_runner as dev dependencies
to generate a ToolDefinition for every Tool function.
Classes
- Param
- Describes one parameter of a Tool function to the LLM.
- Tool
- Marks a top-level function as a tool an LLM can call.
- ToolDefinition
- A tool an LLM can call: its name, description, JSON schema and code.
- ToolResult
- What happened when a tool was invoked, ready to send back to the model: a value on success, or an error written for the model to read.
Extensions
- ToolDefinitionFormats on ToolDefinition
-
A tool in each provider's JSON format, to pass to that provider's SDK
(e.g. its
Tool.fromJson) or REST API. No SDK is needed. -
ToolListFormats
on Iterable<
ToolDefinition> -
The same formats for a list of tools, e.g. the generated
allTools, and running a model's call by the tool name it sent.
Functions
-
validateArguments(
Map< String, Object?> schema, Map<String, Object?> args) → List<String> -
Checks
argsagainst a JSON Schemaschema. Returns a list of problems; an empty list means the arguments are valid. -
withoutAdditionalProperties(
Map< String, Object?> schema) → Map<String, Object?> -
A copy of
schemawithoutadditionalProperties, at every level.
Typedefs
-
ToolConfirmation
= FutureOr<
bool> Function(ToolDefinition tool, Map<String, Object?> args) -
Asks the user whether
toolmay run withargs. Returntrueto run it.
Exceptions / Errors
- ToolArgumentException
- Thrown when the AI sends arguments that don't match a tool's schema.