# FunctionTool

abstract class FunctionTool(val name: String, val description: String, val isLongRunning: Boolean = false, val customMetadata: Map<String, Any> = emptyMap(), requiresConfirmation: (Map<String, Any>) -> Boolean = { false }) : BaseTool

Represents a compile-time generated tool that wraps a function annotated with com.google.adk.kt.annotations.Tool.

The optional confirmation gate (set via the `requiresConfirmation` constructor parameter) makes an invocation pause for human approval before the underlying function runs:

- On the first call the tool records a confirmation request via ToolContext.requestConfirmation and returns a placeholder error response without invoking the underlying function.

- Once the user supplies a com.google.adk.kt.events.ToolConfirmation, the tool is re-executed: if the user confirmed it runs normally; otherwise it returns a rejection error response.

The gate has two forms:

- Per-call predicate (the primary constructor): a `(args) -> Boolean` is invoked on every call with the function's `args` and decides whether to gate this invocation, e.g. `requiresConfirmation = { args -> (args["amount"] as Int) > 1000 }`. The default value `{ false }` disables the gate entirely.

- Boolean (the secondary constructor): a constant flag that gates either every invocation (`true`) or none (`false`). It is a thin wrapper that lifts the Boolean into a constant predicate `{ value }`.

## Constructors

FunctionTool
Link copied to clipboard
constructor(name: String, description: String, isLongRunning: Boolean = false, customMetadata: Map<String, Any> = emptyMap(), requiresConfirmation: Boolean)

Boolean convenience constructor: pass `true` to gate every invocation, `false` to skip the gate entirely. Equivalent to passing `{ requiresConfirmation }` to the primary constructor.

constructor(name: String, description: String, isLongRunning: Boolean = false, customMetadata: Map<String, Any> = emptyMap(), requiresConfirmation: (Map<String, Any>) -> Boolean = { false })

## Types

Companion
Link copied to clipboard
object Companion

## Properties

customMetadata
Link copied to clipboard
val customMetadata: Map<String, Any>

The custom metadata of the tool.

description
Link copied to clipboard
val description: String

The description of the tool.

isLongRunning
Link copied to clipboard
val isLongRunning: Boolean = false

Whether the tool's final result will be delivered out-of-band. When `true`, the framework marks the call as long-running and uses the tool's return value as the function-response payload (or suppresses the response entirely if the tool returns `Unit`).

name
Link copied to clipboard
val name: String

The name of the tool.

## Functions

close
Link copied to clipboard
open override fun close()
declaration
Link copied to clipboard
abstract fun declaration(): FunctionDeclaration?

Returns the underlying function declaration.

execute
Link copied to clipboard
abstract suspend fun execute(context: ToolContext, args: Map<String, Any>): Any

Executes the function with the provided args, optionally utilizing the context.

processLlmRequest
Link copied to clipboard
open suspend fun processLlmRequest(toolContext: ToolContext, llmRequest: LlmRequest): LlmRequest

Processes the LLM request before it is sent.

run
Link copied to clipboard
suspend override fun run(context: ToolContext, args: Map<String, Any>): Any

Executes the tool. This overrides the generic base method to apply the optional confirmation gate before delegating to execute.