How to Stream Custom Data Through LangGraph
AI summary
A Juejin technical guide explains how to send custom backend data and state updates through LangGraph's custom channel rather than the messages channel. It describes registering CustomTransformer, writing payloads with get_stream_writer(), subscribing with useChannel(['custom']), and tuning replay and bufferSize settings. The guide also notes that custom writes reach the frontend only during v2 streaming runs, not local graph.invoke() calls.
In-depth insight
The guide provides a concrete implementation pattern for LangGraph applications that need to transmit progress, status, or other custom data to the frontend.
有些自定义数据和状态流转,不能走messages通道,要走custom通道
一、整体流程图
Python 节点(search_node)
│ get_stream_writer()({ type, ... }) ← 写入
▼
LangGraph Runtime (stream_mode="custom")
│ 产生 protocol event,method = "custom"
▼
CustomTransformer(required_stream_modes=("custom",))
│ 把 custom 事件原样保留 / 转发
▼
langgraph dev → 协议 v2 SSE
│ event: custom
│ data: { name?, payload }
▼
前端 useStream / useChannel(['custom'])
│ event.params.data
▼
渲染 / 总结