KoryTool

abstract class KoryTool<ARGS, R>(val name: String, val description: String? = null) : BaseTool<ARGS, R>

Provider-agnostic tool definition.

Type Parameters

ARGS

The type of the tool's input arguments.

R

The return type of the tool's execution.

See also

Samples

@Serializable // @Serializable from kotlinx.serialization for serialization custom data class.
data class TestWeatherToolArgs(
    @ToolParam(description = "Location for which weather information is needed") // Description about `location` field for AI.
    val location: String
)

class TestWeatherTool : KoryTool<TestWeatherToolArgs, String>(
    name = "get_weather", // Name for tool.
    description = "Get weather for the selected location" // Description for tool.
) {


    override val argsSerializer: KSerializer<TestWeatherToolArgs> = TestWeatherToolArgs.serializer() // Use serializer from your Args data class or add your custom KSerializer.
    override val resultSerializer: KSerializer<String> = String.serializer() //  Use serializer from Result data class or add your custom KSerializer.

    override suspend fun execute(args: TestWeatherToolArgs): String { // Execute tool code here.
        return "Current weather in ${args.location} is sunny, 27°C"
    }
}

// Use TestWeatherTool...

Inheritors

Constructors

Link copied to clipboard
constructor(name: String, description: String? = null)

Properties

Link copied to clipboard
abstract override val argsSerializer: KSerializer<ARGS>

The kotlinx.serialization KSerializer for the ARGS type. Used to generate the JSON schema for the tool's parameters.

Link copied to clipboard
open override val description: String?

A human-readable description of what the tool does.

Link copied to clipboard
open override val name: String

The tool's name (used by the model to reference it).

Link copied to clipboard
abstract override val resultSerializer: KSerializer<R>

The kotlinx.serialization KSerializer for the R type. Used to generate the JSON schema for the tool's results.

Functions

Link copied to clipboard
Link copied to clipboard
abstract suspend override fun execute(args: ARGS): R

Executes the tool with the given parsed arguments.

Link copied to clipboard
open suspend fun executeRaw(argsJson: String, json: Json = Json { ignoreUnknownKeys = true }): String

Executes the tool from raw JSON arguments.