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: 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 arbitrary metadata associated with the tool.

Link copied to clipboard

The name of the tool from the descriptor

Link copied to clipboard
val resultType: TypeToken

Type token representing result type TResult.

Link copied to clipboard
val thisRef: Any?

Functions

Link copied to clipboard
open override fun decodeArgs(rawArgs: JSONObject, serializer: JSONSerializer): ToolFromCallable.Args

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

Link copied to clipboard
open override fun decodeResult(rawResult: JSONElement, serializer: JSONSerializer): TResult

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

Link copied to clipboard
open override fun encodeArgs(args: ToolFromCallable.Args, serializer: JSONSerializer): JSONObject

Encodes the given arguments into a JSON representation.

Link copied to clipboard
fun encodeArgsToString(args: ToolFromCallable.Args, serializer: JSONSerializer): String

Encodes the provided arguments into a JSON string representation.

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

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

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

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

Link copied to clipboard
open override fun encodeResult(result: TResult, serializer: JSONSerializer): JSONElement

Encodes the given result into a JSON representation.

Link copied to clipboard
open fun encodeResultToString(result: TResult, serializer: 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: 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: JSONSerializer): JSONElement

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

Link copied to clipboard
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.