用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/evanfang0054/cc-system-creator-scripts --skill langgraph-state命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
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-state |
| description | 在 LangGraph 中管理状态:模式、reducer、通道和消息传递,用于协调 Agent 执行 |
| language | js |
状态是 LangGraph 中的核心数据结构,在整个图执行期间持久存在。正确的状态管理对于构建可靠的 Agent 至关重要。
核心概念:
| 需求 | 解决方案 | 使用场景 |
|---|---|---|
| 覆盖值 | 普通 Zod 模式 | 简单字段如字符串 |
| 追加到列表 | ReducedValue 与 concat | 日志、累积数据 |
| 自定义逻辑 | 自定义 reducer 函数 | 复杂合并、验证 |
| 消息 | MessagesValue | 聊天应用程序 |
import { StateGraph, StateSchema, START, END } from "@langchain/langgraph";
import { z } from "zod";
const State = new StateSchema({
input: z.string(),
processed: z.string(),
count: z.number(),
});
const process = async (state: typeof State.State) => {
return {
processed: state.input.toUpperCase(),
count: state.count + 1,
};
};
const graph = new StateGraph(State)
.addNode("process", process)
.addEdge(START, "process")
.addEdge("process", END)
.compile();
const result = await graph.invoke({ input: "hello", count: 0 });
console.log(result); // { input: 'hello', processed: 'HELLO', count: 1 }
import { StateSchema, MessagesValue, StateGraph, START, END } from "@langchain/langgraph";
import { HumanMessage, AIMessage } from "@langchain/core/messages";
const MessagesState = new StateSchema({
messages: MessagesValue,
});
const addResponse = async (state: typeof MessagesState.State) => {
const lastMessage = state.messages.at(-1);
const userMsg = lastMessage?.content || "";
return {
messages: [new AIMessage({ content: `Response to: ${userMsg}` })],
};
};
const graph = new StateGraph(MessagesState)
.addNode("respond", addResponse)
.addEdge(START, "respond")
.addEdge(, )
.();
result = graph.({
: [ ({ : })],
});
.(result..);
import { StateSchema, ReducedValue, START, END, StateGraph } from "@langchain/langgraph";
import { z } from "zod";
const State = new StateSchema({
metadata: new ReducedValue(
z.record(z.string(), z.any()).default(() => ({})),
{
inputSchema: z.record(z.string(), z.any()),
reducer: (current, update) => ({ ...current, ...update }),
}
),
data: z.string(),
});
const updateMetadata = async (state: typeof State.State) => {
return { metadata: { timestamp: "2024-01-01" } };
};
const graph = new StateGraph(State)
.addNode("update", updateMetadata)
.addEdge(, )
.(, )
.();
result = graph.({
: { : },
: ,
});
import { StateSchema, ReducedValue } from "@langchain/langgraph";
import { z } from "zod";
const State = new StateSchema({
items: new ReducedValue(
z.array(z.string()).default(() => []),
{
inputSchema: z.array(z.string()),
reducer: (current, update) => current.concat(update),
}
),
});
const addItems = async (state: typeof State.State) => {
return { items: ["new_item"] };
};
const graph = new StateGraph(State)
.addNode("add", addItems)
.addEdge(START, "add")
.addEdge("add", END)
.compile();
const result = await graph.({ : [, ] });
.(result.);
import { StateGraph, LastValue, BinaryOperatorAggregate } from "@langchain/langgraph";
interface State {
counter: number;
logs: string[];
}
const graph = new StateGraph<State>({
channels: {
counter: new BinaryOperatorAggregate<number>(
(x, y) => x + y,
() => 0
),
logs: new BinaryOperatorAggregate<string[]>(
(x, y) => x.concat(y),
() => []
),
},
});
import { StateSchema, StateGraph, START, END } from "@langchain/langgraph";
import { z } from "zod";
const State = new StateSchema({
field1: z.string(),
field2: z.string(),
field3: z.string(),
});
const updateField1 = async (state: typeof State.State) => {
// 只更新 field1,其他不变
return { field1: "updated" };
};
const updateField2 = async (state: typeof State.State) => {
// 只更新 field2
return { field2: "also updated" };
};
const graph = new StateGraph(State)
.addNode("node1", updateField1)
.addNode("node2", updateField2)
.addEdge(, )
.(, )
.(, )
.();
result = graph.({
: ,
: ,
: ,
});
✅ 使用 Zod 定义自定义状态模式 ✅ 通过 ReducedValue 添加 reducer ✅ 创建自定义 reducer 函数 ✅ 使用内置通道 ✅ 使用 MessagesValue 进行聊天 ✅ 部分状态更新 ✅ 嵌套状态结构
❌ 编译后更改状态模式 ❌ 在节点函数外访问状态 ❌ 直接修改状态(必须返回更新) ❌ 在不同图之间共享状态
// ❌ 错误 - 数组将被覆盖
const State = new StateSchema({
items: z.array(z.string()), // 没有 reducer!
});
// 节点 1 返回: { items: ["A"] }
// 节点 2 返回: { items: ["B"] }
// 最终状态: { items: ["B"] } // A 丢失!
// ✅ 正确
import { ReducedValue } from "@langchain/langgraph";
const State = new StateSchema({
items: new ReducedValue(
z.array(z.string()).default(() => []),
{ reducer: (current, update) => current.concat(update) }
),
});
// 最终状态: { items: ["A", "B"] }
// ❌ 错误 - 返回整个状态对象
const myNode = async (state: typeof State.State) => {
state.field = "updated";
return state; // 不要这样做!
};
// ✅ 正确 - 返回部分更新
const myNode = async (state: typeof State.State) => {
return { field: "updated" };
};
// ❌ 有风险 - 没有默认处理
const State = new StateSchema({
count: z.number(), // 如果是 undefined 怎么办?
});
const increment = async (state: typeof State.State) => {
return { count: state.count + 1 }; // 如果 count undefined 可能出错
};
// ✅ 更好 - 在模式中使用默认值
const State = new StateSchema({
count: z.number().default(0),
});
// ❌ 错误 - 忘记 await
const result = graph.invoke({ input: "test" });
console.log(result.output); // undefined (Promise!)
// ✅ 正确
const result = await graph.invoke({ input: "test" });
console.log(result.output); // 可以工作!