AIClientToolRunner

class AIClientToolRunner(val userId: String, val clientId: String, tools: List<AIClientTool>, scope: CoroutineScope)

Runs the client tool calls addressed to this device, each once.

Give it each AI reply's steps as they update. It runs a call when the call has its own id, awaits this person and this install, the runner has a tool of that name and the call has not run here before, then hands the result to send. A result that could not be sent is sent again on a later update, without running the tool again.

The runner is confined to the main thread: call run from it, and pass a scope that runs on it, such as a viewModelScope or rememberCoroutineScope().

val runner = AIClientToolRunner(userId, AIClientIdentity.installId(context), listOf(LocationTool()), scope)
runner.run(parts) { call, result -> backend.send(result, call, message) }

Parameters

userId

The person signed in on this device.

clientId

This install, from AIClientIdentity.installId.

tools

The tools this device can run. When two share a name, the first is used.

scope

Where tools run and results are sent.

Constructors

Link copied to clipboard
constructor(userId: String, clientId: String, tools: List<AIClientTool>, scope: CoroutineScope)

Properties

Link copied to clipboard
Link copied to clipboard

How many times a result is offered to send before the runner gives up on it. At least 1.

Link copied to clipboard

The names of the tools this device can run.

Link copied to clipboard

Functions

Link copied to clipboard
fun run(parts: List<AIMessagePart>, send: suspend (call: AIToolCallPart, result: AIClientToolResult) -> Unit)

Runs the calls among parts that await this device, and sends their results.