Enable on-device LLMs to invoke your Dart functions by registering typed tool definitions. The SDK handles argument parsing, execution, and result formatting automatically.Documentation Index
Fetch the complete documentation index at: https://docs.runanywhere.ai/llms.txt
Use this file to discover all available pages before exploring further.
Basic Usage
Setup
1. Import the SDK
2. Define Tool Executors
Every tool executor must match the signatureFuture<Map<String, ToolValue>> Function(Map<String, ToolValue>):
3. Register Tools
API Reference
RunAnywhereTools
| Method | Return Type | Description |
|---|---|---|
registerTool(definition, executor) | void | Register a tool with its definition and executor function |
clearTools() | void | Remove all registered tools |
generateWithTools(prompt, {options}) | Future<ToolCallingResult> | Run the full orchestration loop: generate → parse → execute → repeat |
ToolDefinition
| Property | Type | Required | Description |
|---|---|---|---|
name | String | Yes | Unique identifier for the tool |
description | String | Yes | Human-readable description the LLM uses to decide when to call the tool |
parameters | List<ToolParameter> | Yes | Typed parameter definitions |
category | String | No | Logical grouping (e.g. 'Utility', 'Data') |
ToolParameter
| Property | Type | Required | Description |
|---|---|---|---|
name | String | Yes | Parameter name |
type | ToolParameterType | Yes | One of string, number, boolean, object, array |
description | String | Yes | What this parameter represents |
ToolCallingOptions
| Property | Type | Default | Description |
|---|---|---|---|
maxToolCalls | int | 5 | Maximum tool invocations per generation |
autoExecute | bool | true | Automatically execute tool calls and feed results back to the LLM |
temperature | double | 0.8 | Sampling temperature (0.0–2.0) |
maxTokens | int | 256 | Maximum tokens in the final response |
ToolCallingResult
| Property | Type | Description |
|---|---|---|
text | String | Final text response after all tool calls complete |
toolCalls | List<ToolCall> | Every tool call the LLM requested; each has toolName (String) and arguments (Map<String, ToolValue>) |
toolResults | List<ToolResult> | Execution results; each has result (Map<String, ToolValue>?), error (String?), and success (bool) |
ToolValue Types
ToolValue is a Dart 3 sealed class. Create instances with the concrete subtypes and read values with the stringValue getter or pattern matching.
| Subtype | Constructor | Description |
|---|---|---|
StringToolValue | StringToolValue('hello') | String value |
NumberToolValue | NumberToolValue(42.0) | Numeric value (double) |
BoolToolValue | BoolToolValue(true) | Boolean value |
NullToolValue | NullToolValue() | Explicit null |
ArrayToolValue | ArrayToolValue() | Array / list value |
ObjectToolValue | ObjectToolValue() | Nested object value |
.stringValue getter:
Pattern Matching (Dart 3)
Use exhaustiveswitch expressions on the sealed class:
Examples
Weather Tool
Calculator Tool
Current Time Tool
Complete Flutter Widget
A full-screen widget that registers weather, calculator, and time tools, then runs a multi-tool conversation:Error Handling
WrapgenerateWithTools in a try-catch and inspect individual ToolResult entries for per-tool errors:
If a tool executor throws, the SDK catches the exception and records it in the corresponding
ToolResult.error field. The LLM receives the error message and can retry or respond gracefully.Common Errors
| Error | Cause | Fix |
|---|---|---|
ToolNotFound | LLM requested an unregistered tool | Verify tool names match exactly |
MaxToolCallsExceeded | Hit the maxToolCalls limit | Increase the limit or simplify the prompt |
ModelNotLoaded | No LLM model loaded | Call RunAnywhere.loadModel(...) before generating |
InvalidArguments | Argument types don’t match the definition | Check ToolParameterType in your ToolDefinition |
See Also
LLM Generation
Text generation with metrics
Streaming
Stream tokens in real-time
System Prompts
Control LLM behavior with system prompts
Error Handling
SDK-wide error handling patterns