Skip to main content
Commons owns the tool-calling run loop. JavaScript owns a registry of executor callbacks and nothing else: the prompt formatting, parsing, iteration, and follow-up generation all happen in C++ through one native call.

The surface

Every one of these is async. There is no parseToolCall on the React Native surface. Types come from @runanywhere/proto-ts/tool_calling, not from @runanywhere/core. The one exception is ToolExecutor, which is a TypeScript-level type exported by @runanywhere/core.

Defining a tool

ToolDefinition and ToolParameter are proto messages. Build them with fromPartial and use the ToolParameterType enum for the parameter type.
Call await RunAnywhere.clearTools() before re-registering, for example when a component remounts, so you do not stack duplicates.

ToolValue

Executors receive and return Record<string, ToolValue>, not plain JSON. ToolValue is a typed oneof, so read the branch you expect and write the branch you mean. The SDK converts between this tree and the plain JSON the model emits, so args.count?.numberValue is how you read a numeric argument.

ToolParameter

The field is enumValues, not enum, and defaultValue is a ToolValue, not a string.

Generating

With no tools option the loop uses everything currently registered.

ToolCallingOptions

Passed as a Partial<ToolCallingOptions> second argument. The sampling defaults are the same ones generate() uses. There is no separate 0.7 or 256.

GenerateWithToolsOptions

The optional third argument. topP comes from llmOptions only and defaults to 1.0.

ToolCallingResult

ToolCall carries id, name, argumentsJson, type, createdAtMs, and rawText. ToolResult carries toolCallId, name, resultJson, error, success, startedAtMs, and completedAtMs.

Manual execution

Set autoExecute: false to inspect calls before running them, then execute the ones you approve.
executeTool never throws. An unknown tool, unparseable arguments, or a throwing executor all come back as a ToolResult with success: false and a populated error.

Multi-step chains

With maxToolCalls above 1 the model can chain calls inside one generation.

Error handling

Return an error object from an executor rather than throwing. A thrown error still becomes a failed ToolResult, but an explicit { error: { stringValue: '…' } } gives the model something to reason about.

LLM Generation

Options and defaults

Streaming

Token streaming

System Prompts

Control model behavior

Error Handling

SDKException reference