首页龙虾技能列表 › LangChain — 避免常见 LangChain 错误

🦜 LangChain — 避免常见 LangChain 错误

v1.0.0

本技能提供 LangChain 最佳实践指南,帮助您避免常见错误,如 LCEL 陷阱、内存持久性、RAG 分块和输出解析器陷阱。它是一份读取指南,不要求任何敏感信息,指导与其声明目的一致。

2· 1,300·16 当前·17 累计
by @ivangdavila (Iván)·MIT-0
下载技能包
License
MIT-0
最后更新
2026/2/26
安全扫描
VirusTotal
无害
查看报告
OpenClaw
安全
high confidence
此技能仅提供指令,专注于 LangChain 最佳实践,不请求任何敏感信息,其指导与目的完全一致。
评估建议
该技能是一份关于 LangChain 最佳实践的读取指南,表现出低风险的特性:不请求敏感信息,仅包含建议性文本。安装前,请确认信任技能来源(来源/主页未知)。由于其为指令式技能,目前无需执行代码,但如果后续更新包含安装步骤或代码文件,请再次检查下载、所需凭据或运行任意命令的指令。如果计划使用代理执行 LangChain 代码,请确保代理的执行环境(python3、安装的包)和对数据/凭据的访问被控制,仅限于预期的权限。...
详细分析 ▾
用途与能力
Name/description (LangChain gotchas and best practices) matches the content of SKILL.md. The only declared runtime requirement is python3, which is reasonable for LangChain-related advice; no unexpected credentials, binaries, or config paths are requested.
指令范围
SKILL.md contains high-level usage guidance and warnings only — it does not instruct the agent to read files, call external endpoints, or access credentials. Note: instructions are advisory; they could be used to guide actions if an agent is later asked to execute code, but the skill itself does not command execution or data collection.
安装机制
No install spec and no code files are present, so nothing is written to disk or downloaded. This is the lowest-risk install profile (instruction-only).
凭证需求
The skill declares no required environment variables, credentials, or config paths. There is no disproportionate request for secrets or unrelated service tokens.
持久化与权限
always is false and the skill is user-invocable; it does not request permanent presence or elevated platform privileges. Autonomous model invocation remains enabled by platform default but is not a special property of this skill.
安全有层次,运行前请审查代码。

License

MIT-0

可自由使用、修改和再分发,无需署名。

运行时依赖

🖥️ OSLinux · macOS · Windows

版本

latestv1.0.02026/2/10

初始发布

● 无害

安装命令 点击复制

官方npx clawhub@latest install langchain
镜像加速npx clawhub@latest install langchain --registry https://cn.clawhub-mirror.com

技能文档

LangChain — 避免常见 LangChain 错误

元数据


name: LangChain description: 避免常见 LangChain 错误 — LCEL 陷阱、内存持久性、RAG 分块和输出解析器陷阱 metadata: {"clawdbot":{"emoji":"🦜","requires":{"bins":["python3"]},"os":["linux","darwin","win32"]}}

LCEL 基础

  • | 管道输出到下一个 — prompt | llm | parser
  • RunnablePassthrough() 转发输入不变 — 用于并行分支
  • RunnableParallel 并行运行分支 — {"a": chain1, "b": chain2}
  • .invoke() 用于单个,.batch() 用于多个,.stream() 用于令牌
  • 输入必须匹配预期键 — {"question": x} 而非仅 x 如果提示预期 {question}

内存陷阱

  • 内存不自动在会话之间持久 — 显式保存/加载
  • ConversationBufferMemory 无界增长 — 对于长聊使用 ConversationSummaryMemory
  • 内存键必须匹配提示变量 — memory_key="chat_history" 需要提示中的 {chat_history}
  • 对话模型使用 return_messages=True — 完成模型使用 False 返回字符串

RAG 分块

  • 分块大小影响检索质量 — 太小失去上下文,太大稀释相关性
  • 分块重叠防止在句子中间切割 — 典型的 10-20% 重叠
  • RecursiveCharacterTextSplitter 保留结构 — 按段落然后按句子分割
  • 嵌入维度必须与向量存储匹配 — 混合模型导致沉默失败

输出解析器

  • PydanticOutputParser 需要提示中的格式指令 — 调用 .get_format_instructions()
  • 解析器故障不总是明显 — 错误的 JSON 可能部分解析
  • OutputFixingParser 使用 LLM 重试 — 包裹另一个解析器,修复错误
  • 聊天模型使用 with_structured_output() — 对支持的模型比手动解析更清晰

检索

  • similarity_search 返回文档 — .page_content 用于文本
  • k 参数控制结果计数 — 更多不总是更好,噪音增加
  • 元数据过滤在相似度之前 — 大多数向量存储中使用 filter={"source": "docs"}
  • max_marginal_relevance_search 用于多样性 — 避免冗余相似块

代理

  • 代理动态决定工具顺序 — 链是固定序列
  • 工具描述很重要 — 代理使用它们来决定何时调用
  • handle_parsing_errors=True — 防止代理输出解析错误崩溃
  • 最大迭代次数防止无限循环 — 默认 max_iterations=10 可能太低

常见错误

  • 提示模板变量区分大小写 — {Question}{question}
  • 聊天模型需要消息格式 — 使用 ChatPromptTemplate 而非 PromptTemplate
  • 回调不传播 — 通过链传递 config={"callbacks": [...]}
  • 率限可能静默崩溃 — 用重试逻辑包裹
  • 令牌计数超过上下文 — 对于长历史使用 trim_messages 或摘要
数据来源:ClawHub ↗ · 中文优化:龙虾技能库
OpenClaw 技能定制 / 插件定制 / 私有工作流定制

免费技能或插件可能存在安全风险,如需更匹配、更安全的方案,建议联系付费定制

了解定制服务