ToolFromCallable

class ToolFromCallable(callable: KCallable<*>, thisRef: Any? = null, val descriptor: ToolDescriptor, json: Json = Json) : Tool<ToolFromCallable.VarArgs, ToolFromCallable.Result> (source)

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

See also

Constructors

Link copied to clipboard
constructor(callable: KCallable<*>, thisRef: Any? = null, descriptor: ToolDescriptor, json: Json = Json)

Types

Link copied to clipboard
class Result(val result: Any?, val type: KType, val json: Json) : ToolResult
Link copied to clipboard
data class VarArgs(val args: Map<KParameter, Any?>) : Tool.Args
Link copied to clipboard
class VarArgsSerializer(val kCallable: KCallable<*>) : KSerializer<ToolFromCallable.VarArgs>

Properties

Link copied to clipboard
open override val argsSerializer: KSerializer<ToolFromCallable.VarArgs>

Serializer responsible for encoding and decoding the arguments required for the tool execution. This abstract property is used to define the specific KSerializer corresponding to the type of arguments expected by the tool.

Link copied to clipboard
open override val descriptor: ToolDescriptor

Metadata about the tool including its name, description, and parameters.

Link copied to clipboard

Represents the name property of the tool, derived from the tool's descriptor. This property provides an immutable reference to the tool's unique name, which is used for identification within tool registries.

Functions

Link copied to clipboard
fun decodeArgs(rawArgs: JsonObject): ToolFromCallable.VarArgs

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

Link copied to clipboard

Decodes a raw string representation of arguments into the corresponding object of type TArgs.

Link copied to clipboard
fun encodeArgs(args: ToolFromCallable.VarArgs): JsonObject

Encodes the given arguments into a JSON representation.

Link copied to clipboard

Encodes the provided arguments into a JSON string representation using the configured serializer.

Link copied to clipboard

Encodes the given result of type TResult to its string representation for the LLM.s

Link copied to clipboard

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