Principle:1Panel dev MaxKB SSE Streaming
| Knowledge Sources | |
|---|---|
| Domains | SSE, API |
| Last Updated | 2026-10-10 00:00 GMT |
Overview
A communication pattern that delivers server-generated events to clients incrementally over a persistent HTTP connection using the Server-Sent Events (SSE) protocol.
Description
SSE streaming is MaxKB's primary response delivery mechanism for chat. Instead of waiting for the full LLM response, the server sends incremental chunks as `data: <json>\n\n` frames. Each chunk contains content text, metadata (node_id, view_type, reasoning_content, node_status), and usage tokens. The BaseToResponse abstract class defines the contract, with SystemToResponse implementing MaxKB's native protocol. The NodeChunkManage class manages a queue of node chunks, popping them one at a time to produce the SSE stream. This enables real-time token-by-token streaming from the LLM to the user.
Usage
Use this principle when designing:
- Real-time chat streaming responses
- LLM token-by-token output delivery
- Progress reporting for long-running workflow nodes
Theoretical Basis
The SSE protocol uses HTTP with `Content-Type: text/event-stream` and frames delimited by `\n\n`:
# Abstract algorithm description (NOT real implementation)
def stream_response(llm_stream):
for chunk in llm_stream:
frame = json.dumps({
"content": chunk.text,
"is_end": False,
"reasoning_content": chunk.reasoning,
})
yield f"data: {frame}\n\n"
# Final end chunk
yield f"data: {json.dumps({'is_end': True, 'usage': {...}})}\n\n"
MaxKB adds an `operate: True` flag to distinguish content chunks from control messages, and a `node_is_end` flag to signal when a specific node has finished (before the overall stream ends).
Related Pages
Implemented By
- Implementation:1Panel_dev_MaxKB_SystemToResponse
- Implementation:1Panel_dev_MaxKB_WorkflowManage
- Implementation:1Panel_dev_MaxKB_BaseChatStep