AI Assistant: Progressive SSE Streaming (word-by-word response rendering) #32
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Current State
The AI assistant (Shrimp) returns responses via Server-Sent Events (SSE). The current implementation reads the stream incrementally and waits for the
event: doneevent before displaying the response.What works now:
doneevent arrives)What's missing:
The Enhancement
Show the AI response progressively as it's generated, word by word — like ChatGPT, Claude web, etc.
Shrimp already sends intermediate SSE events during generation:
event: token— partial content as the LLM generates tokensevent: tool_call— when the agent uses a toolevent: tool_result— tool execution resultevent: done— final complete responseWe currently ignore
tokenevents and only processdone. Progressive streaming would rendertokenevents in real-time.Implementation
1. Service layer (
ai_service.rs)Change
send_messageto accept a callback for streaming updates:Or return a
Streamthat yields partial updates.2. UI component (
island.rs/ chat view)Update the message state model:
Pending→CompletePending→Streaming(partial_content)→Complete(full_content)The chat bubble renders
Streamingstate with a blinking cursor and growing text.3. Token event parsing
Process
event: tokenin the SSE reader loop:4. Agent tool use visualization (stretch goal)
When Shrimp uses tools (web search, file operations, etc.), show status:
This requires parsing
event: tool_callandevent: tool_resultevents.Files
hero_archipelagos/archipelagos/intelligence/ai/src/services/ai_service.rshero_archipelagos/archipelagos/intelligence/ai/src/island.rshero_archipelagos/archipelagos/intelligence/ai/src/views/Priority
Medium — the current fix prevents infinite spin. This enhancement improves UX but is not blocking.
mik-tf referenced this issue2026-03-18 20:13:52 +00:00
mik-tf referenced this issue2026-03-18 22:06:25 +00:00
mik-tf referenced this issue2026-03-18 22:37:34 +00:00
mik-tf referenced this issue2026-03-18 22:52:15 +00:00
mik-tf referenced this issue2026-03-18 22:55:28 +00:00
mik-tf referenced this issue2026-03-18 22:58:45 +00:00
Implemented and deployed to herodev
Changes (4 files in
hero_archipelagos/archipelagos/intelligence/ai/src/):ai_service.rs: Added
process_sse_chunk()to parseevent: tokenSSE events incrementally. Addedon_tokencallback parameter tosend_message()(WASM only).island.rs: Creates a placeholder AI message before the request. Token callback updates the message content in real-time as tokens arrive. Error case removes the placeholder. Added
@keyframes blinkCSS animation.message_list.rs: Typing dots (bounce animation) only show when no streaming content has arrived yet. Once first token comes in, the growing message bubble replaces the dots. Passes
is_streamingto last AI message bubble.message_bubble.rs: Added
is_streamingprop. Shows a blinking cursor after content during streaming.Architecture:
Verify: Open herodev AI chat, send a message, response should appear word-by-word.
Commit: hero_archipelagos@7571357 on
developmentmik-tf referenced this issue2026-03-18 23:16:26 +00:00
Reopening — backend streaming not yet implemented
Investigated the actual SSE events from Shrimp:
Shrimp sends only one
partialevent (execution plan) then onedoneevent (full response). There are no per-token events. The LLM call in Shrimp is non-streaming — it waits for the complete response.Frontend work done (hero_archipelagos@bbd1f75):
event: partialandevent: tokenformatsBackend work needed (hero_shrimp):
llm_client.tsmust use streaming LLM API calls (stream: true)event: token/data: {"token": "word"}SSE eventsevent: doneas final responseThis is a Shrimp-side change in
src/core/llm_client.tsandsrc/core/agent.ts.mik-tf referenced this issue2026-03-18 23:28:29 +00:00
mik-tf referenced this issue2026-03-18 23:33:28 +00:00
mik-tf referenced this issue2026-03-19 00:06:50 +00:00
mik-tf referenced this issue2026-03-19 00:17:18 +00:00
mik-tf referenced this issue2026-03-19 00:26:50 +00:00
mik-tf referenced this issue2026-03-19 02:54:39 +00:00
SSE streaming working with hero_agent
hero_agent (which replaced hero_shrimp in #72) has native SSE streaming:
POST /api/chatreturns SSE stream with events:token,tool_call,tool_result,done,errorThis is functionally complete — the AI Assistant tab shows responses word-by-word.
Signed-off-by: mik-tf