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...Content copied to clipboard
Inheritors
Constructors
Properties
Link copied to clipboard
The kotlinx.serialization KSerializer for the ARGS type. Used to generate the JSON schema for the tool's parameters.
Link copied to clipboard
A human-readable description of what the tool does.
Link copied to clipboard
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
open suspend fun executeRaw(argsJson: String, json: Json = Json { ignoreUnknownKeys = true }): String
Executes the tool from raw JSON arguments.