Tool

@Target(allowedTargets = [AnnotationTarget.FUNCTION])
annotation class Tool(val name: String = "", val description: String = "", val requireConfirmation: Boolean = false, val isLongRunning: Boolean = false, val behavior: Behavior = Behavior.UNSPECIFIED, val responseScheduling: FunctionResponseScheduling = FunctionResponseScheduling.SCHEDULING_UNSPECIFIED)

Annotates a function to be exposed as an executable tool by the Google ADK Kotlin. KSP will generate a corresponding com.google.adk.kt.tools.FunctionTool wrapper for annotated functions.

The generated wrapper converts the function's return value into a JSON-native Map: data classes, enums, lists, maps, and nested structures are translated at compile time. A function may therefore return a data class directly, unlike a hand-written com.google.adk.kt.tools.BaseTool, whose result must already be JSON-native. It may also return a kotlinx.coroutines.flow.Flow or a Reactive Streams Publisher; a Flow or Publisher of Event, FunctionResponse (whose scheduling, when set, overrides responseScheduling for that value) or Any passes its values through unconverted. A connected live run streams each value to the model, except an Event, which goes to the caller; anywhere else, the call fails (see com.google.adk.kt.tools.BaseTool.run), so return a value instead.

A streaming tool may take one experimental Publisher<LiveRequest> for the run's input. The input is set only while the returned stream runs, so subscribe to it from inside that stream; outside it, the input is empty. A Publisher return or input needs kotlinx-coroutines-reactive on the classpath.

Note: this annotation shares its simple name with com.google.adk.kt.types.Tool, the GenAI tool definition data class. Files that need to reference both should use an import alias.

Retained at runtime so the JVM-only ReflectiveTools can read it via reflection to build tools from Java methods, which the KSP path cannot process without the Kotlin compiler.

Properties

Link copied to clipboard

How a live run declares the tool to the model: Behavior.NON_BLOCKING lets the model keep the conversation going while a call is pending, and Behavior.BLOCKING makes it wait for the response. Only live runs use it. A function that returns a Flow is always declared non-blocking, and one that doesn't still runs to completion before the live run reads the model's next message.

Link copied to clipboard

An optional explicit description. If not provided, the KDoc summary is used.

Link copied to clipboard
val isLongRunning: Boolean = false

If true, indicates the tool returns a Pending state and resumes later.

Link copied to clipboard

An optional explicit name for the tool. If not provided, the function name is used.

Link copied to clipboard

If true, the tool execution requires user confirmation.

Link copied to clipboard

Controls when a live model reacts to the tool's responses: FunctionResponseScheduling.SILENT only adds them to the model's context, FunctionResponseScheduling.WHEN_IDLE waits until the model is idle to react, and FunctionResponseScheduling.INTERRUPT reacts immediately. Setting any of these declares the tool non-blocking unless behavior specifies otherwise. The default, FunctionResponseScheduling.SCHEDULING_UNSPECIFIED, sets no scheduling.