Tool

class Tool(val spec: ToolSpec, val reconcile: suspend (JsonObject) -> String??, val execute: suspend (JsonObject) -> String)

A function a model may call. The usual way to create one is from a @Serializable class that holds the input, which also gives the model the input's schema:

@Serializable
data class Forecast(
@Description("The city, for example \"Madrid\"") val city: String,
val days: Int = 1,
)

val forecast = Tool<Forecast>("forecast", "Returns the weather forecast of a city.") { input ->
weatherService.forecast(input.city, input.days)
}

A tool that charges, books or sends something can also say how to find out whether a call that started did its work, with a reconcile. See the overload that takes one.

Use these constructors when you write the schema by hand.

Constructors

Link copied to clipboard
constructor(spec: ToolSpec, reconcile: suspend (JsonObject) -> String??, execute: suspend (JsonObject) -> String)
constructor(spec: ToolSpec, execute: suspend (JsonObject) -> String)

Creates a tool without a reconcile.

Properties

Link copied to clipboard
val execute: suspend (JsonObject) -> String

runs the tool with the input the model sent and returns the text the model gets back. An exception it throws reaches the model as an error result; see List.execute.

Link copied to clipboard
val reconcile: suspend (JsonObject) -> String??

tells whether a call whose step stopped after the tool started did its work: the text the model gets back if it did, null if it did not. null for a tool without one.

Link copied to clipboard

what the model is told about the tool.