SimpleTool

abstract class SimpleTool<TArgs>(argsType: TypeToken, name: String, description: String) : Tool<TArgs, String> (source)

Represents a simplified tool base class that processes specific arguments and produces a textual result.

Parameters

TArgs

The type of arguments the tool accepts.

Constructors

Link copied to clipboard
constructor(argsType: TypeToken, name: String, description: String)
constructor(argsSerializer: KSerializer<TArgs>, name: String, description: String)

Properties

Link copied to clipboard
val argsType: TypeToken

Type token representing arguments type TArgs.

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.

Functions

Link copied to clipboard
open fun decodeArgs(rawArgs: JSONObject, serializer: JSONSerializer): TArgs

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

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

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

Link copied to clipboard
open fun encodeArgs(args: TArgs, serializer: JSONSerializer): JSONObject

Encodes the given arguments into a JSON representation.

Link copied to clipboard
fun encodeArgsToString(args: TArgs, 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 fun encodeResult(result: String, serializer: JSONSerializer): JSONElement

Encodes the given result into a JSON representation.

Link copied to clipboard
open override fun encodeResultToString(result: String, 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
abstract suspend fun execute(args: TArgs): String

Executes the tool's logic with the provided arguments.

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

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