Cancel an order with confirmation
A destructive tool call pauses the turn, shows a confirm block, and only runs after the user taps Yes.
Goal
“Cancel my order ORD-2201” → the assistant asks “Cancel order ORD-2201? You will be refunded ₹3,198.” with Yes, cancel and Keep it → on Yes the API is called and the assistant confirms.
Pieces
- Tool
cancel_order:POST https://api.kletso.ai/demo/acme/orders/{{ input.orderId }}/cancel, Requires confirmation on, Has side effects on. Replace with your endpoint. - Agent → Tools: attach with confirm first ticked (inherits from the tool).
- Nothing to build in the app: the built-in
confirmblock handles the tap.
What happens
- The model calls
cancel_order. The runtime seesrequireConfirmation, emitstool.startedandtool.confirmation_requiredwith a confirm surface, saves the pending call, and completes the message withfinishReason: "tool_calls". - The SDK renders the confirm block. Yes sends a
confirmaction{ toolCallId, approve: true }; No sendsapprove: false. - Approved: the tool runs and the model continues in a new turn (“Done. ₹3,198 will be back on your card in 5–7 days”). Declined: the model is told the user declined and answers accordingly.
Verify
- Preview “cancel my order ORD-2201” → inspector shows
tool.confirmation_requiredand the message completes withtool_calls. Click Yes in the schematic →tool.completed→ newmessage.completed. - Try
ORD-2187(already delivered): the demo API answers 409 and the model explains a refund is the right path.
Notes
- Confirmation text comes from the runtime’s confirm surface (tool name and arguments). To phrase it in your own words, give the tool a clear description and let the model summarise before it calls.
- Keep destructive tools separate from read tools so the confirmation only appears where it matters.