Latency-Tolerant Suggested Replies
Learn to build latency-tolerant suggested replies in AI chat UIs by managing draft ownership and suggestion states separately. Discover techniques to debounce requests, ignore stale responses, and insert suggestions without overwriting user input. This lesson helps you implement stable, user-friendly suggestion interactions despite network delays and concurrency challenges.
Stop and Regenerate handle one assistant message that the user asked for directly. A second, quieter kind of generation runs alongside typing itself, and it needs the same ownership discipline. A smallest working suggested-reply composer has one text area, a row of suggestion chips below it, and one strict rule. Clicking a chip inserts text at the cursor, but it never replaces the entire draft and it never moves focus away from the text area.
That behavior only holds when the draft and the suggestions live in separate state channels. When a late suggestion result writes into the same draft state the user is editing, a slow network response can replace the draft with a suggestion and the user loses work. The invariant that prevents this is simple. Draft ownership stays with the user, while the model only proposes adjacent text.
Use the following state sketch to track how draft and suggestions[] evolve independently under typing and late arrivals.
With that invariant in place, the UI wiring becomes straightforward. The composer renders draft in the text area, renders suggestions[] below as chips, and the chip click handler computes a new ...