The Frontend Agent Experience: Streaming Rendering, Visualizing Tool Calls, Interrupt/Retry, SSE Hooks
Write a React chat frontend for mini-koda: render the reply as it streams in, visualize the tool-calling process, and support interrupting and retrying.
Today's Goals
- Implement a chat interface that consumes SSE streaming output and renders it character by character
- Visualize the tool-calling process — which tool was called, with what arguments, and what result
- Implement both interrupting the current reply and retrying on failure
As of yesterday the backend triages, splits tasks, reviews itself, reaches out proactively, finds things accurately, and holds off attacks — and you have not once looked at it through a browser. Today it goes in front of human eyes.
Plain-Language Walkthrough
Simultaneous interpretation: speaking while listening, and stoppable
A simultaneous interpreter at an international conference does exactly what a streaming chat frontend does.
They do not wait for the speaker to finish. They render sentence by sentence, three to five seconds behind, and the audience hears it near-live. That is streaming: the backend pushes each fragment as it emerges rather than holding everything to the end. How big is the difference? A reply taking ten-odd seconds to generate leaves a full-response interface showing a spinner for all of them; a streaming interface has characters within the first second. The same total duration, an entirely different perception.
They also do not start speaking after half a word. "We will, in the next quarter..." is unfinished with no predicate yet, and rushing produces a wrong rendering. So an interpreter always keeps a small buffer, speaking once a complete unit of meaning has arrived. The frontend is the same: SSE messages travel as frames, one frame may arrive split in two by the network, and you must keep a buffer holding the half until the next chunk — D1 covered this thoroughly, and today reuses the same technique on the frontend.
During the thirty seconds the speaker spends looking something up, the interpreter says "he is checking the figures." Dead silence makes the audience assume the equipment failed. An agent's few seconds of tool calling is the same predicament: with nothing displayed, users assume it hung. So tool calls must be seen — which tool, which arguments, what result — as a card rather than a black box.
And the last thing, today's most important: an audience member raising a hand to say "skip this part" is not satisfied by the interpreter falling silent. The interpreter stopped and the speaker is still talking — what actually has to happen is the chair signaling the speaker to stop. The frontend's "interrupt" is likewise two things, not one. That gets its own section below and it is this chapter's core.
Interview questions
How does a frontend consume SSE to render a typewriter effect, and why do people usually avoid the built-in EventSource?前端怎么消费 SSE 并实现打字机效果?为什么一般不用浏览器自带的 EventSource?
Common in ChinaCommon overseasBasic#sse#streaming#frontend🔒 Unlock this chapter to see the answer keys.
The user hits Stop and the frontend calls AbortController.abort(). What is the backend doing at that moment?用户点了「停止生成」,前端调用 AbortController.abort() 之后,后端在做什么?
Common in ChinaCommon overseasDeep dive#streaming#cancellation#cost🔒 Unlock this chapter to see the answer keys.
What is different about frontend state management under streaming, and why not call setState on every token?流式场景下前端的状态管理要注意什么?为什么不能每个 token 都 setState?
Common in ChinaCommon overseasIntermediate#react#streaming#performance🔒 Unlock this chapter to see the answer keys.
How do you design retry so it does not duplicate side effects, and should the tool-call process be visible to the user?失败重试怎么设计才不会产生重复副作用?工具调用过程要不要暴露给用户?
Common in ChinaCommon overseasIntermediate#idempotency#retry#ux🔒 Unlock this chapter to see the answer keys.
