Skip to main content
Enable on-device LLMs to invoke your Dart functions by registering typed tool definitions. The SDK handles argument parsing, execution, and result formatting automatically.
Tool calling uses the RunAnywhereTools class, not RunAnywhere. All tool registration and generation methods live on RunAnywhereTools.

Basic Usage

Setup

1. Import the SDK

2. Define Tool Executors

Every tool executor must match the signature Future<Map<String, ToolValue>> Function(Map<String, ToolValue>):

3. Register Tools

Always call RunAnywhereTools.clearTools() before registering tools to avoid duplicates when hot-reloading during development.

API Reference

RunAnywhereTools

ToolDefinition

ToolParameter

ToolCallingOptions

ToolCallingResult

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. Access any value as a string via the .stringValue getter:

Pattern Matching (Dart 3)

Use exhaustive switch 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

Wrap generateWithTools 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

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