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
how the model refers to the tool: 1 to 64 letters, digits, _ or -.
tells the model what the tool does and when to use it.
runs the tool and returns the text the model gets back.
Throws
Creates a Tool whose input is read with serializer. See the overload with a reified type.
Creates a Tool whose input is the @Serializable type Input, for a tool that does something that must not happen twice, such as a payment.
toolLoop saves that a call of this tool started before it runs, with an id that effectId returns while the tool runs. Pass that id to the service as its idempotency key. When the step runs again and finds the call started but without a result, because the process stopped or another tool of the step failed, reconcile is asked first, with the same id from effectId: it returns the text for the model when the work was done, and null when it was not, and the tool runs again with the same id.
val charge = Tool<Charge>(
"charge_card",
"Charges the card of the customer.",
reconcile = { input -> payments.findByIdempotencyKey(effectId()!!)?.let { "Charged ${it.amount}." } },
) { input -> "Charged ${payments.charge(input.amount, idempotencyKey = effectId()!!).amount}." }For a service that takes idempotency keys, reconcile = { null } is enough: the tool runs again with the same key, and the service answers with what it did the first time. A reconcile that cannot tell throws: the run fails, and a person who checked resumes it with a ChatMessage.ToolResult for the call, which is then not run.
Parameters
how the model refers to the tool: 1 to 64 letters, digits, _ or -.
tells the model what the tool does and when to use it.
tells whether a call that started before did its work.
runs the tool and returns the text the model gets back.
Throws
Creates a Tool with a reconcile whose input is read with serializer. See the overload with a reified type.