run

suspend override fun run(context: ToolContext, args: Map<String, Any?>): Any

Executes the tool and returns its result.

The result must be JSON-native: a Map, List, String, number, Boolean, or null; a non-Map result is wrapped under RESULT_KEY, with a regular tool's Unit (no result) sent as null. Returning a non-JSON type such as a Kotlin data class throws when the resulting event is persisted. To return structured data, return a Map, or expose the function via com.google.adk.kt.annotations.Tool, which converts data classes (and enums, lists, and nested structures) into Maps automatically.

In a live run, a returned kotlinx.coroutines.flow.Flow streams: the call is answered as pending at once, each value then reaches the model as it arrives, and each emitted com.google.adk.kt.events.Event goes to the caller only; the model stops the stream by calling a stop_streaming(function_name) or stopStreaming(functionName) tool you declare, whose body never runs. If the model makes a new call with the same arguments while the first flow is still streaming, that call is answered as already running and starts no second stream.