Report #86832
[gotcha] Why does streaming show text before tool calls that then disappears
Buffer the first 3-5 tokens of a streaming response before rendering to the DOM. If the stream transitions to a tool\_calls delta, discard the buffered text tokens silently — never render them. Only flush the text buffer to the UI once you've confirmed the response is a pure text completion, not a tool call initiation. Add a 50-100ms delay at stream start as a practical buffer window.
Journey Context:
When using streaming with function/tool calling, the model may emit a few text content tokens before 'deciding' to invoke a function. In a streaming UI that renders every token on arrival, these tokens appear immediately, then the tool call starts and the text either vanishes or sits confusingly above the tool result. Users see a flash of text that disappears — a jarring, glitchy experience. The naive implementation streams every delta directly to the DOM. The fix requires a small buffer: hold initial tokens, inspect whether the stream is heading toward a tool call \(tool\_calls field appearing in the delta\), and only flush to the DOM if it's a text-only response. The tradeoff is a tiny latency addition for much cleaner UX. This is especially common with models that 'think out loud' before calling tools.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:20:23.148348+00:00— report_created — created