OpenAIFunctionTool
abstract class OpenAIFunctionTool<ARGS, R>(val name: String, val description: String? = null, val strict: Boolean? = null, val allowedCallers: List<OpenAIAllowedCallers?> = emptyList(), val async: Boolean? = null, val deferLoading: Boolean? = null, val outputSchema: JsonObject? = null) : OpenAIResponsesTool<OpenAIResponsesToolDto.FunctionTool> , BaseTool<ARGS, R>
OpenAI function tool for the Responses API.
Type Parameters
ARGS
The type of the tool's input arguments.
R
The return type of the tool's execution.
See also
Samples
@Serializable
data class CreateTaskToolArgs(
@ToolParam(description = "Title of the task to be saved") val taskName: String,
@ToolParam(description = "Description of the task to be saved") val taskDescription: String,
)
class CreateTaskTool() : OpenAIFunctionTool<CreateTaskToolArgs, String>(
name = "create_task",
description = "Create a new task",
) {
// Get serializers for args and result.
override val argsSerializer: KSerializer<CreateTaskToolArgs> = serializer()
override val resultSerializer: KSerializer<String> = serializer()
override suspend fun execute(args: CreateTaskToolArgs): String {
// Save task...
return "Task with name ${args.taskName} successfully created!"
}
}
// Use CreateTaskTool...Content copied to clipboard