ToolFromCallable

class ToolFromCallable<TResult>(val callable: KCallable<TResult>, val thisRef: Any? = null, name: String? = null, description: String? = null) : Tool<ToolFromCallable.Args, TResult> (source)

A tool implementation that wraps a Kotlin callable (function, method, etc.).

Parameters

callable

The Kotlin callable (KFunction or KProperty) to be wrapped and executed by this tool.

thisRef

An optional instance reference required if the callable is non-static.

name

The name of the tool. If not provided, the name of the callable will be used.

description

The description of the tool. If not provided, the description from the ai.koog.agents.core.tools.annotations.LLMDescription annotation on the callable will be used.

Constructors

Link copied to clipboard
constructor(callable: KCallable<TResult>, thisRef: Any? = null, name: String? = null, description: String? = null)

Types

Link copied to clipboard
class Args(val parameters: Map<ERROR CLASS: Symbol not found for KParameter, Any?>)

Arguments for ToolFromCallable.

Properties

Link copied to clipboard
val argsType: ai/koog/serialization/TypeToken

Type token representing arguments type TArgs.

Link copied to clipboard
Link copied to clipboard

A ToolDescriptor representing the tool's schema, including its name, description, and parameters.

Link copied to clipboard

A map of static metadata associated with the tool. Distinct from the per-call ToolCallMetadata threaded into execute; this field describes the tool, not the invocation.

Link copied to clipboard

The name of the tool from the descriptor.

Link copied to clipboard
val resultType: ai/koog/serialization/TypeToken

Type token representing result type TResult.

Link copied to clipboard
val thisRef: Any?

Functions

Link copied to clipboard
open fun decodeArgs(rawArgs: ai/koog/serialization/JSONObject, serializer: ai/koog/serialization/JSONSerializer): ToolFromCallable.Args

Decodes the provided raw JSON arguments into an instance of the specified arguments type.

open override fun decodeArgs(rawArgs: ERROR CLASS: Symbol not found for JSONObject, serializer: ERROR CLASS: Symbol not found for JSONSerializer): ToolFromCallable.Args
Link copied to clipboard
open fun decodeResult(rawResult: ai/koog/serialization/JSONElement, serializer: ai/koog/serialization/JSONSerializer): TResult

Decodes the provided raw JSON element into an instance of the specified result type.

open override fun decodeResult(rawResult: ERROR CLASS: Symbol not found for JSONElement, serializer: ERROR CLASS: Symbol not found for JSONSerializer): TResult
Link copied to clipboard
open fun encodeArgs(args: ToolFromCallable.Args, serializer: ai/koog/serialization/JSONSerializer): ai/koog/serialization/JSONObject

Encodes the given arguments into a JSON representation.

open override fun encodeArgs(args: ToolFromCallable.Args, serializer: ERROR CLASS: Symbol not found for JSONSerializer): ERROR CLASS: Symbol not found for JSONObject
Link copied to clipboard
fun encodeArgsToString(args: ToolFromCallable.Args, serializer: ai/koog/serialization/JSONSerializer): String

Encodes the provided arguments into a JSON string representation.

Link copied to clipboard
fun encodeArgsToStringUnsafe(args: Any?, serializer: ai/koog/serialization/JSONSerializer): String

Encodes the provided arguments into a JSON string representation without type safety checks.

Link copied to clipboard
fun encodeArgsUnsafe(args: Any?, serializer: ai/koog/serialization/JSONSerializer): ai/koog/serialization/JSONObject

Encodes the given arguments into a JSON representation without type safety checks.

Link copied to clipboard
open fun encodeResult(result: TResult, serializer: ai/koog/serialization/JSONSerializer): ai/koog/serialization/JSONElement

Encodes the given result into a JSON representation.

open override fun encodeResult(result: TResult, serializer: ERROR CLASS: Symbol not found for JSONSerializer): ERROR CLASS: Symbol not found for JSONElement
Link copied to clipboard
open fun encodeResultToString(result: TResult, serializer: ai/koog/serialization/JSONSerializer): String

Encodes the given result of type TResult to its string representation. This is used to provide the LLM with the result of the tool execution. It can be overridden to customize the string representation the LLM will see.

Link copied to clipboard
fun encodeResultToStringUnsafe(result: Any?, serializer: ai/koog/serialization/JSONSerializer): String

Encodes the provided result object into a JSON string representation without type safety checks.

Link copied to clipboard
fun encodeResultUnsafe(result: Any?, serializer: ai/koog/serialization/JSONSerializer): ai/koog/serialization/JSONElement

Encodes the given result object into a JSON representation without type safety checks.

Link copied to clipboard
suspend override fun execute(args: ToolFromCallable.Args, metadata: ToolCallMetadata): TResult

Executes the tool's logic with the provided arguments and per-call metadata.

open suspend override fun execute(args: ToolFromCallable.Args): TResult

Executes the tool's logic with the provided arguments.

Link copied to clipboard
suspend fun executeUnsafe(args: Any?): TResult

Executes the tool with the provided arguments without type safety checks.

suspend fun executeUnsafe(args: Any?, metadata: ToolCallMetadata): TResult

Executes the tool with the provided arguments and metadata without type safety checks.