用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/evanfang0054/cc-system-creator-scripts --skill langgraph-workflows命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
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。
基于 SOC 职业分类
正在显示 SKILL.md
| name | langgraph-workflows |
| description | 理解工作流 vs Agent、预定义 vs 动态模式,以及使用 Send API 的编排器-工作器模式 |
| language | js |
LangGraph 同时支持工作流(预定义路径)和Agent(动态决策)。理解何时使用每种模式对于有效的 Agent 设计至关重要。
关键区别:
| 特征 | 工作流 | Agent | 混合 |
|---|---|---|---|
| 控制流 | 固定、预定义 | 动态、模型驱动 | 混合 |
| 可预测性 | 高 | 低 | 中 |
| 复杂性 | 简单 | 复杂 | 可变 |
| 使用场景 | 顺序任务 | 开放式问题 | 结构化灵活性 |
| 示例 | ETL、验证 | 研究、问答 | 审查批准 |
按固定路径顺序执行:
模型决定下一步:
一个协调器委托给多个工作器:
import { StateGraph, StateSchema, START, END } from "@langchain/langgraph";
import { z } from "zod";
const WorkflowState = new StateSchema({
data: z.string(),
validated: z.boolean(),
processed: z.boolean(),
});
const validate = async (state: typeof WorkflowState.State) => {
const isValid = state.data.length > 0;
return { validated: isValid };
};
const process = async (state: typeof WorkflowState.State) => {
return {
data: state.data.toUpperCase(),
processed: true,
};
};
// 固定工作流: validate → process
const workflow = new StateGraph(WorkflowState)
.(, validate)
.(, process)
.(, )
.(, )
.(, )
.();
result = workflow.({ : });
.(result);
import { ChatAnthropic } from "@langchain/anthropic";
import { tool } from "@langchain/core/tools";
import { AIMessage, ToolMessage } from "@langchain/core/messages";
import { StateGraph, StateSchema, MessagesValue, END, START } from "@langchain/langgraph";
import { z } from "zod";
const search = tool(async ({ query }) => `Results for: ${query}`, {
name: "search",
description: "Search for information",
schema: z.object({ query: z.string() }),
});
const calculate = tool(async ({ expression }) => eval(expression).toString(), {
name: "calculate",
description: "Calculate a mathematical expression",
schema: z.object({ expression: z.string() }),
});
const = ({
: ,
});
model = ({ : });
tools = [search, calculate];
modelWithTools = model.(tools);
= () => {
response = modelWithTools.(state.);
{ : [response] };
};
= () => {
lastMessage = state..(-);
(!lastMessage || !.(lastMessage)) {
{ : [] };
}
toolsByName = { [search.]: search, [calculate.]: calculate };
result = [];
( toolCall lastMessage. ?? []) {
tool = toolsByName[toolCall.];
observation = tool.(toolCall);
result.(observation);
}
{ : result };
};
= () => {
lastMessage = state..(-);
(lastMessage && .(lastMessage) && lastMessage.?.) {
;
}
;
};
agent = ()
.(, agentNode)
.(, toolNode)
.(, )
.(, shouldContinue, [, ])
.(, )
.();
import { StateGraph, StateSchema, Send, ReducedValue, START, END } from "@langchain/langgraph";
import { z } from "zod";
const OrchestratorState = new StateSchema({
tasks: z.array(z.string()),
results: new ReducedValue(
z.array(z.string()).default(() => []),
{ reducer: (current, update) => current.concat(update) }
),
summary: z.string().optional(),
});
const orchestrator = (state: typeof OrchestratorState.State) => {
// 将任务扩散到工作器
return state.tasks.map(task => new Send("worker", { task }));
};
const worker = async () => {
result = ;
{ : [result] };
};
= () => {
summary = ;
{ summary };
};
graph = ()
.(, worker)
.(, synthesize)
.(, orchestrator, [])
.(, )
.(, )
.();
result = graph.({
: [, , ],
});
.(result.);
import { StateGraph, StateSchema, START, END } from "@langchain/langgraph";
import { z } from "zod";
const HybridState = new StateSchema({
input: z.string(),
validated: z.boolean(),
agentResponse: z.string().optional(),
finalized: z.boolean(),
});
const validate = async (state: typeof HybridState.State) => {
return { validated: true };
};
const agentProcess = async (state: typeof HybridState.State) => {
// 动态 agent 逻辑在这里
const response = `Agent processed: ${state.input}`;
return { agentResponse: response };
};
const finalize = async (state: .) => {
{ : };
};
hybrid = ()
.(, validate)
.(, agentProcess)
.(, finalize)
.(, )
.(, )
.(, )
.(, )
.();
import { StateGraph, StateSchema, Send, ReducedValue, START, END } from "@langchain/langgraph";
import { z } from "zod";
const MapReduceState = new StateSchema({
documents: z.array(z.string()),
summaries: new ReducedValue(
z.array(z.string()).default(() => []),
{ reducer: (current, update) => current.concat(update) }
),
finalSummary: z.string().optional(),
});
const mapDocuments = (state: typeof MapReduceState.State) => {
return state.documents.map(doc => new Send("summarize", { doc }));
};
const summarize = async (: { doc: }) => {
summary = ;
{ : [summary] };
};
= () => {
finalSummary = state..();
{ finalSummary };
};
graph = ()
.(, summarize)
.(, reduce)
.(, mapDocuments, [])
.(, )
.(, )
.();
result = graph.({
: [, , ],
});
import { StateGraph, StateSchema, Send, ReducedValue, START, END } from "@langchain/langgraph";
import { z } from "zod";
const RouterState = new StateSchema({
query: z.string(),
sources: z.array(z.string()),
results: new ReducedValue(
z.array(z.string()).default(() => []),
{ reducer: (current, update) => current.concat(update) }
),
final: z.string().optional(),
});
const classify = async (state: typeof RouterState.State) => {
const query = state.query.toLowerCase();
const sources: string[] = [];
if (query.includes("code")) sources.();
(query.()) sources.();
(query.()) sources.();
{ sources };
};
= () => {
state..( (source, { : state. }));
};
= () => {
{ : [] };
};
= () => {
{ : [] };
};
= () => {
{ : [] };
};
= () => {
{ : state..() };
};
graph = ()
.(, classify)
.(, queryGithub)
.(, queryNotion)
.(, querySlack)
.(, synthesize)
.(, )
.(, routeToSources, [, , ])
.(, )
.(, )
.(, )
.(, )
.();
✅ 选择工作流 vs Agent 模式 ✅ 混合确定性和 Agent 步骤 ✅ 使用 Send API 进行并行执行 ✅ 定义自定义编排器逻辑 ✅ 控制工作器节点行为 ✅ 使用 reducer 聚合结果
❌ 更改 Send API 消息传递模型 ❌ 绕过工作器状态隔离 ❌ 修改并行执行机制 ❌ 在运行时覆盖 reducer 行为
// ❌ 错误 - 工作器共享状态,导致冲突
const State = new StateSchema({
sharedCounter: z.number(), // 所有工作器修改相同的计数器!
});
// ✅ 正确 - 每个工作器获得隔离的输入
const worker = async (state: { task: string }) => {
// state 对此工作器是隔离的
return { results: [process(state.task)] };
};
// ❌ 错误 - 最后一个工作器覆盖所有其他工作器
const State = new StateSchema({
results: z.array(z.string()), // 没有 reducer!
});
// ✅ 正确 - 使用 ReducedValue
import { ReducedValue } from "@langchain/langgraph";
const State = new StateSchema({
results: new ReducedValue(
z.array(z.string()).default(() => []),
{ reducer: (current, update) => current.concat(update) }
),
});
// ❌ 反模式 - 过于僵化的工作流
.addEdge("validate", "process") // 始终继续,没有错误处理
// ✅ 更好 - 添加条件逻辑
const routeAfterValidate = (state) => {
if (!state.validated) return "errorHandler";
return "process";
};
.addConditionalEdges("validate", routeAfterValidate, ["process", "errorHandler"]);
// ❌ 错误 - 忘记 await
const result = graph.invoke({ data: "test" });
console.log(result.output); // undefined!
// ✅ 正确
const result = await graph.invoke({ data: "test" });
console.log(result.output); // 可以工作!