-
public final class AIClientToolRunnerRuns 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
viewModelScopeorrememberCoroutineScope().val runner = AIClientToolRunner(userId, AIClientIdentity.installId(context), listOf(LocationTool()), scope) runner.run(parts) { call, result -> backend.send(result, call, message) }
-
-
Constructor Summary
Constructors Constructor Description AIClientToolRunner(String userId, String clientId, List<AIClientTool> tools, CoroutineScope scope)
-
Method Summary
Modifier and Type Method Description final IntegergetMaxAttempts()How many times a result is offered to sendbefore the runner gives up on it.final UnitsetMaxAttempts(Integer maxAttempts)final List<String>getToolNames()final StringgetUserId()final StringgetClientId()final Unitrun(List<AIMessagePart> parts, SuspendFunction2<AIToolCallPart, AIClientToolResult, Unit> send)Runs the calls among parts that await this device, and sends their results. -
-
Constructor Detail
-
AIClientToolRunner
AIClientToolRunner(String userId, String clientId, List<AIClientTool> tools, CoroutineScope scope)
- Parameters:
userId- The person signed in on this device.clientId- This install, from AIClientIdentity.installId.tools- The tools this device can run.scope- Where tools run and results are sent.
-
-
Method Detail
-
getMaxAttempts
final Integer getMaxAttempts()
How many times a result is offered to
sendbefore the runner gives up on it. At least 1.
-
setMaxAttempts
final Unit setMaxAttempts(Integer maxAttempts)
-
getToolNames
final List<String> getToolNames()
-
getClientId
final String getClientId()
-
run
final Unit run(List<AIMessagePart> parts, SuspendFunction2<AIToolCallPart, AIClientToolResult, Unit> send)
Runs the calls among parts that await this device, and sends their results.
- Parameters:
parts- A reply's steps.send- Sends a call's result to your backend.
-
-
-
-