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 confirm block handles the tap.

What happens

  1. The model calls cancel_order. The runtime sees requireConfirmation, emits tool.started and tool.confirmation_required with a confirm surface, saves the pending call, and completes the message with finishReason: "tool_calls".
  2. The SDK renders the confirm block. Yes sends a confirm action { toolCallId, approve: true }; No sends approve: false.
  3. 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_required and the message completes with tool_calls. Click Yes in the schematic → tool.completed → new message.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.

Last updated 2026-09-28 · Report an issue with this page