Tool

inline fun <Input> Tool(name: String, description: String, noinline execute: suspend (Input) -> String): Tool

Creates a Tool whose input is the @Serializable type Input. The input schema is built from the type, with the text of Description annotations as the description of each property.

A property is required unless it has a default value or is nullable. Supported property types are strings, numbers, booleans, enums, lists, maps with string keys, value classes and other @Serializable classes. Use Tool<Unit> for a tool that takes no input.

Parameters

name

how the model refers to the tool: 1 to 64 letters, digits, _ or -.

description

tells the model what the tool does and when to use it.

execute

runs the tool and returns the text the model gets back.

Throws

if name is not valid, or Input is not a class or has a property of a type that cannot be described.


fun <Input> Tool(name: String, description: String, serializer: KSerializer<Input>, execute: suspend (Input) -> String): Tool

Creates a Tool whose input is read with serializer. See the overload with a reified type.