Documentation Index
Fetch the complete documentation index at: https://nvd-54.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
构建实时可视化 LangGraph 流水线的前端。这些模式展示了如何渲染多步骤图执行,包括每个节点的状态和来自自定义 StateGraph 工作流的流式输出内容。
LangGraph 图由通过边连接的命名节点组成。每个节点执行一个步骤(分类、研究、分析、综合)并将输出写入特定的状态键。在前端,useStream 提供对节点输出、流式 Token 和图元数据的响应式访问,以便你可以将每个节点映射到一个 UI 卡片。
from langgraph.graph import StateGraph, MessagesState, START, END
class State(MessagesState):
classification: str
research: str
analysis: str
graph = StateGraph(State)
graph.add_node("classify", classify_node)
graph.add_node("research", research_node)
graph.add_node("analyze", analyze_node)
graph.add_edge(START, "classify")
graph.add_edge("classify", "research")
graph.add_edge("research", "analyze")
graph.add_edge("analyze", END)
app = graph.compile()
在前端,useStream 通过 stream.values 暴露已完成的节点输出,通过 getMessagesMetadata 识别哪个节点产生了每个流式 Token。
import { useStream } from "@langchain/react";
function Pipeline() {
const stream = useStream<typeof graph>({
apiUrl: "http://localhost:2024",
assistantId: "pipeline",
});
const classification = stream.values?.classification;
const research = stream.values?.research;
const analysis = stream.values?.analysis;
}
图执行
可视化多步骤图流水线,包括每个节点的状态和流式输出内容。
相关模式
LangChain 前端模式——Markdown 消息、工具调用、乐观更新等——可与任何 LangGraph 图配合使用。无论你使用 createAgent、createDeepAgent 还是自定义 StateGraph,useStream hook 都提供相同的核心 API。
将这些文档连接到 Claude、VSCode 等工具,通过 MCP 获取实时答案。