StateTool

class StateTool<State>(val spec: ToolSpec, val execute: suspend (State, JsonObject) -> ToolOutcome<State>)

A function a model may call that reads the state of the run and changes it: add a line to an order, book a seat, move a piece. What it did is in the state, so a checkpoint holds it and the next node sees it.

@Serializable
data class NewLine(@Description("The item, for example \"margherita\"") val item: String)

val addLine = StateTool<Order, NewLine>("add_line", "Adds a line to the order.") { order, line ->
ToolOutcome(order.copy(lines = order.lines + line.item), "Added ${line.item}.")
}

Give it to toolLoop as one of its stateTools. A Tool is enough for a function that only needs its input, such as a lookup.

Use this constructor when you write the schema by hand.

Constructors

Link copied to clipboard
constructor(spec: ToolSpec, execute: suspend (State, JsonObject) -> ToolOutcome<State>)

Properties

Link copied to clipboard
val execute: suspend (State, JsonObject) -> ToolOutcome<State>

runs the tool with the state of the run and the input the model sent, and returns the state it leaves and the text the model gets back. An exception it throws reaches the model as an error result, and the state stays as it was.

Link copied to clipboard

what the model is told about the tool.