Search⌘ K
AI Features

Resumability and Idempotency

Explore how to handle multi-turn AI interactions by implementing resumability and idempotency. Understand how to persist stable identifiers and cache tool results to avoid duplicate executions. Learn to classify turn states and design safe UI flows that prevent unintended retries after refreshes, ensuring reliable and consistent tool call behavior.

A refresh at the wrong moment can turn a single user intent into two tool executions. The sequence is mechanical. The app receives a tool intent, the user confirms, the app starts the tool call, the page refreshes mid-flight, persisted state rehydrates on load, and the app sees a tool is needed, so it runs the tool again. Nothing crashes, but the side effect duplicates.

This lesson implements a resume policy that makes tool execution at-most-once from the UI’s perspective by using persisted identifiers and a cached tool result. The core idea is that rehydration must replay facts, not re-trigger actions.

To compare the failure path with the corrected path, step through the sequence diagram and note where the idempotency key gates execution.

An idempotency key lets a repeated confirm reuse the cached result instead of running the tool again.
An idempotency key lets a repeated confirm reuse the cached result instead of running the tool again.

With the failure made explicit, the fix is to treat tool execution like a state transition that can be resumed, not a function that can be re-called safely.

Persisted identifiers that make

...