Skip to main content

Overview

Tool Calling enables on-device LLMs to invoke registered functions — such as fetching weather, performing calculations, or querying APIs — and incorporate the results into their responses. The SDK handles the full orchestration loop: generate → parse tool call → execute → feed result back → generate final response.
Tool calling uses the RunAnywhereToolCalling class, not the RunAnywhere singleton. Make sure to import from the correct package.

Package Imports

Or import the entire LLM extensions package:

Basic Usage

API Reference

RunAnywhereToolCalling

ToolDefinition

ToolParameter

ToolParameterType

ToolCallingOptions

ToolCallingResult

ToolCall

ToolResult

ToolValue

Factory methods for creating typed values: Accessors for reading values:

Examples

Weather Tool

Calculator Tool

Current Time Tool

Multiple Tools Together

Jetpack Compose UI

A complete tool calling chat interface:

Error Handling

Tool executors run synchronously in the generation loop. Avoid long-running operations (network calls, heavy I/O) inside tool executors — they will block inference until complete.

Best Practices

  • Write clear descriptions — the LLM uses description fields to decide when and how to call tools. Be specific about inputs and outputs. - Keep tool responses small — return only the data the LLM needs to formulate a response. Large payloads waste context window tokens. - Set maxToolCalls conservatively — prevents runaway loops where the model repeatedly calls tools. - Validate arguments — always handle missing or malformed arguments with defaults or error values rather than throwing exceptions. - Use categories — grouping tools by category helps organize related functionality.

LLM Generation

Text generation

VLM

Vision Language Models

System Prompts

Control AI behavior

Error Handling

Error handling patterns