用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/evanfang0054/cc-system-creator-scripts --skill langgraph-streaming命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
Mac 系统深度清理和优化工具。使用 Mole (mo 命令) 执行系统清理、磁盘分析、应用卸载、系统优化等任务。 触发场景(当用户提到以下任一内容时使用此 skill): - 清理 Mac、清理磁盘、释放空间、清理缓存、清理系统 - 卸载应用、删除应用、移除应用及其残留 - 磁盘分析、查看磁盘占用、大文件查找、空间分析 - 系统优化、系统维护、刷新系统、重建缓存 - 系统状态、系统监控、CPU/内存/磁盘监控 - 清理 node_modules、清理构建产物、清理项目依赖 - 清理安装包、删除 dmg/pkg 文件 - Mac 清理工具、类似 CleanMyMac 的功能 - "我的 Mac 太慢了"、"磁盘空间不足"、"电脑卡顿" - 即使没有明确说 "Mole",只要涉及上述场景就应使用
构建 CLI / command-line 工具时使用,支持两种模式。模式 A 人类 CLI(终端 UX、彩色、交互式提示、进度条、Shell 自动补全),关键词包括 commander / yargs / oclif / typer / click / cobra。模式 B agent-native CLI(JSON envelope / schema 自省 / dry-run 写入安全 / 契约驱动),关键词包括 agent-native CLI、JSON envelope、friction signal。混合场景默认走 B(agent 约束更严格)。只要用户提到 CLI、command-line、命令行工具、agent-native、envelope、schema、friction signal,或要给 agent 提供可调用的 CLI 工具,就应主动使用此 skill。
快速搭建和配置 pnpm monorepo 项目结构,包含 TypeScript、tsup 构建、私有 npm registry 配置。当用户需要"创建 monorepo"、"初始化 monorepo 项目"、"配置 pnpm workspace"、"设置 monorepo 构建"、"monorepo setup"时使用。特别适合需要统一管理多个包、配置构建工具、处理 TypeScript 路径问题的场景。即使用户只是说"帮我搭建项目结构"或"配置构建",如果涉及多包管理也应该使用此 skill。
| name | langgraph-streaming |
| description | 从 LangGraph 流式传输实时更新:流式模式(values、updates、messages、custom、debug)用于响应式 UX |
| language | js |
LangGraph 的流式系统在图执行期间输出实时更新,对于响应式 LLM 应用程序至关重要。可以在生成时流式传输图状态、LLM 令牌或自定义数据。
| 模式 | 流式传输的内容 | 使用场景 |
|---|---|---|
values | 每步后的完整状态 | 监控完整状态变化 |
updates | 每步后的状态增量 | 跟踪增量更新 |
messages | LLM 令牌 + 元数据 | 聊天 UI、令牌流式传输 |
custom | 用户定义的数据 | 进度指示器、日志 |
debug | 所有执行详情 | 调试、详细跟踪 |
import { StateGraph, START, END } from "@langchain/langgraph";
const process = async (state) => ({ count: state.count + 1 });
const graph = new StateGraph(State)
.addNode("process", process)
.addEdge(START, "process")
.addEdge("process", END)
.compile();
// 每步后流式传输完整状态
for await (const chunk of await graph.stream(
{ count: 0 },
{ streamMode: "values" }
)) {
console.log(chunk); // { count: 0 }, 然后 { count: 1 }
}
// 只流式传输变化
for await (const chunk of await graph.stream(
{ count: 0 },
{ streamMode: "updates" }
)) {
console.log(chunk); // { process: { count: 1 } }
}
import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage } from "@langchain/core/messages";
const model = new ChatOpenAI({ model: "gpt-4" });
const llmNode = async (state) => {
const response = await model.invoke(state.messages);
return { messages: [response] };
};
const graph = new StateGraph(State)
.addNode("llm", llmNode)
.compile();
// 在生成时流式传输 LLM 令牌
for await (const chunk of await graph.stream(
{ messages: [new HumanMessage("Hello")] },
{ streamMode: "messages" }
)) {
const [token, metadata] = chunk;
if (token.content) {
process.stdout.write(token.content);
}
}
import { LangGraphRunnableConfig } from "@langchain/langgraph";
const myNode = async (state, config: LangGraphRunnableConfig) => {
const writer = config.writer;
// 输出自定义更新
writer?.("Processing step 1...");
// 执行工作
writer?.("Processing step 2...");
// 更多工作
writer?.("Complete!");
return { result: "done" };
};
const graph = new StateGraph(State)
.addNode("work", myNode)
.compile();
for await (const chunk of await graph.stream(
{ data: "test" },
{ streamMode: "custom" }
)) {
console.log(chunk); // "Processing step 1...", 等
}
// 同时流式传输多种模式
for await (const [mode, chunk] of await graph.stream(
{ messages: [new HumanMessage("Hi")] },
{ streamMode: ["updates", "messages", "custom"] }
)) {
console.log(`${mode}:`, chunk);
}
// 包含子图输出
for await (const chunk of await graph.stream(
{ data: "test" },
{
streamMode: "updates",
subgraphs: true // 也从嵌套图流式传输
}
)) {
console.log(chunk);
}
const config = {
configurable: { thread_id: "1" },
streamMode: ["messages", "updates"] as const,
subgraphs: true
};
for await (const [metadata, mode, chunk] of await graph.stream(
{ query: "test" },
config
)) {
if (mode === "messages") {
// 处理流式传输的 LLM 内容
const [msg, _] = chunk;
if (msg.content) {
process.stdout.write(msg.content);
}
} else if (mode === "updates") {
// 检查中断
if ("__interrupt__" in chunk) {
// 处理中断
const interruptInfo = chunk.__interrupt__[0].value;
// 获取用户输入并恢复
break;
}
}
}
✅ 选择流式模式 ✅ 同时流式传输多种模式 ✅ 从节点输出自定义数据 ✅ 从子图流式传输 ✅ 将流式传输与中断结合
❌ 修改流式传输协议 ❌ 更改创建检查点的时机 ❌ 更改令牌流式传输格式
// ❌ 错误 - 没有调用 LLM,没有流式传输
const node = async (state) => ({ output: "static text" });
for await (const chunk of await graph.stream({}, { streamMode: "messages" })) {
console.log(chunk); // 什么都没有!
}
// ✅ 正确 - 调用 LLM
const node = async (state) => {
const response = await model.invoke(state.messages); // LLM 调用
return { messages: [response] };
};
// ❌ 错误 - 没有 writer,没有流式传输
const node = async (state) => {
console.log("Processing..."); // 没有流式传输!
return { data: "done" };
};
// ✅ 正确
import { LangGraphRunnableConfig } from "@langchain/langgraph";
const node = async (state, config: LangGraphRunnableConfig) => {
config.writer?.("Processing..."); // 流式传输!
return { data: "done" };
};
// ❌ 错误 - 单个字符串带逗号
await graph.stream({}, { streamMode: "updates, messages" });
// ✅ 正确 - 数组
await graph.stream({}, { streamMode: ["updates", "messages"] });
// ❌ 错误 - 缺少 await
const stream = graph.stream({});
for await (const chunk of stream) { // 错误!
console.log(chunk);
}
// ✅ 正确
for await (const chunk of await graph.stream({})) {
console.log(chunk);
}