代理代码
- 作者仓库星标 0
- 作者仓库 skills-registry
- 领域
- 人工智能
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @tomevault-io · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 需简单配置
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- macOS · Linux · Windows
- 运行环境要求
- Node.js · Python
- 检测到的文件与系统行为
-
- 只读
- 命令执行
- 网络行为
- 允许外网请求
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
# LangGraph: editorial guidance
For API reference (signatures, imports, exhaustive method lists), use the **`mcpdoc` MCP tools**: `fetch_docs("https://docs.langchain.com/oss/python/langgraph/...")`. This skill is the *opinions* layer; the docs are the *facts* layer.
## When to drop down to raw `StateGraph`
Most agents do NOT need this. Use `create_agent(...)` + middleware first (see the `langchain-agents-middleware` skill). Drop down to `StateGraph` only when:
- Multiple LLM calls in a single graph with custom routing between them.
- Branches that run in parallel and merge.
- Non-message state (custom dataclasses, dicts, dataframes flowing through nodes).
- Multi-graph workflows where one graph calls another as a subgraph.
If your problem fits "one model, some tools, in a loop" — even if the loop is complex — `create_agent` is the right tool. Don't reach for `StateGraph` out of habit.
## Things the docs won't warn you about
- A node returning `{}` is a no-op; return `None` to signal "no state change" cleanly.
- `add_conditional_edges` mappings must include `END` if any branch terminates — leaving it out is a silent bug, not an error.
- `compile()` is not idempotent across `bind_tools` — rebind tools, then re-compile.
- `langgraph dev` reloads on file change; if it stops reloading, the graph likely failed to import — check the terminal for the exception.
- A graph with `interrupt()` calls but no checkpointer will throw at *invoke time*, not at *compile time*. Always pair `interrupt()` with `compile(checkpointer=...)`.
## Production essentials (rules of thumb)
- **Always pass a `thread_id`** in `config={"configurable": {"thread_id": ...}}` for any agent with persistent state. A missing `thread_id` silently starts a fresh thread.
- **`InMemorySaver` is for dev only.** Production = `PostgresSaver` (multi-instance safe) or `SqliteSaver` (single-node, low-volume). State dies with the process for `InMemorySaver`.
- **Resume an interrupted thread by passing `None` as input** with the same `thread_id`. The runtime picks up where the interrupt fired.
- **Custom state schemas need reducers.** `Annotated[list, add_messages]` appends; without the reducer, each node *replaces* the field instead of accumulating.
- **For node-level retries on raw `StateGraph`, use `RetryPolicy`.** For `create_agent` agents, prefer `ToolRetryMiddleware` / `ModelRetryMiddleware` — same effect, cleaner composition.
## Doc URLs to fetch with mcpdoc
- `https://docs.langchain.com/oss/python/langgraph/graph-api.md` — `StateGraph`, nodes, edges
- `https://docs.langchain.com/oss/python/langgraph/durable-execution.md` — checkpointers + `thread_id`
- `https://docs.langchain.com/oss/python/langgraph/streaming.md` — `stream_mode` modes
- `https://docs.langchain.com/oss/python/langgraph/persistence.md` — Postgres / Sqlite checkpointers
- `https://docs.langchain.com/oss/python/langgraph/subgraphs.md` — multi-graph composition
When the user is mid-task and you need a method signature or import path, fetch from these URLs. Don't guess.
---
> Source: [cwijayasundara/agent_cli_langchain](https://github.com/cwijayasundara/agent_cli_langchain) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-05-23 -->
章节与文件索引
按说明文件中的顺序排列。
何时下拉至原始 StateGraph
文档不会警告您的事情
生产要点(经验法则)
使用 mcpdoc 获取的文档 URL
文件/命令 -> mcpdoc · fetch_docs("https://docs.langchain.com/oss/python/langgraph/...") · StateGraph · create_agent(...) · langchain-agents-middleware · create_agent · None · add_conditional_edges
内容校验值 -> 37cd5df31a65
当前原文的自动摘译,尚未人工审校。
何时下拉至原始 StateGraph
大多数代理不需要这个。首先使用
create_agent(...)+ 中间件(参见langchain-agents-middleware技巧)。仅在以下情况下才下拉至StateGraph:单个图表中存在多个 LLM 调用,并且它们之间具有自定义路由。并行运行和合并的分支。非消息状态(自定义数据类、字典、流经节点的数据帧)。多图工作流程,其中一个图将另一个图调用为子图。文档不会警告您的事情
返回
{}的节点是一个空操作;返回None以明确地表示“没有状态改变”。如果任何分支终止,add_conditional_edges映射必须包含END——忽略它是一个无声的错误,而不是错误。compile()与bind_tools不是幂等的 — 重新绑定工具,然后重新编译。langgraph dev文件更改时重新加载;如果它停止重新加载,图表可能无法导入 - 检查终端是否有异常。生产要点(经验法则)
对于任何具有持久状态的代理,始终在
config={"configurable": {"thread_id": ...}}中传递thread_id。缺失的thread_id会默默地启动一个新线程。InMemorySaver仅供开发者使用。生产 =PostgresSaver(多实例安全)或SqliteSaver(单节点,小批量)。国家随着InMemorySaver的进程而消亡。通过传递None作为具有相同thread_id的输入来恢复中断的线程。运行时从中断触发的地方开始。使用 mcpdoc 获取的文档 URL
https://docs.langchain.com/oss/python/langgraph/graph-api.md—StateGraph,节点,边https://docs.langchain.com/oss/python/langgraph/durable-execution.md— 检查指针 +thread_idhttps://docs.langchain.com/oss/python/langgraph/streaming.md—stream_mode模式https://docs.langchain.com/oss/python/langgraph/persistence.md— Postgres / Sqlite 检查指针https://docs.langchain.com/oss/python/langgraph/subgraphs.md— 多图组合