LangChain 助手
- 作者仓库星标 0
- 作者仓库 skills-registry
LangChain (LCEL): editorial guidance
For API reference (full Runnable list, parser types, retriever interfaces), use the mcpdoc MCP tools: fetch_docs("https://docs.langchain.com/oss/python/langchain/..."). This skill is the opinions layer.
When to use LCEL vs create_agent
LCEL is for non-agentic flows: deterministic pipelines (RAG, summarization, classification, structured extraction). The pipeline runs once, end-to-end, no loop, no tool-calling LLM driving control flow.
If the task involves an LLM deciding which tools to call, don't use LCEL — use create_agent(...) + middleware. Trying to bolt agentic behavior onto an LCEL chain is the most common mistake here. The dividing line: does the LLM choose what happens next, or does the code? If LLM, agents. If code, LCEL.
Things the docs won't warn you about
chain.invoke(x)wherexis a string but the chain expects a dict will silently coerce in some configurations and fail in others — pass a dict explicitly.init_chat_modelreads provider creds from env (OPENAI_API_KEY,ANTHROPIC_API_KEY). It will not prompt; missing env raises at first call, not at construction.- Parsers are part of the chain.
chat_model.invoke(...)returns anAIMessage; pipe throughStrOutputParser()to get a plain string. - Middleware does NOT apply to LCEL chains. Middleware is
create_agent-only. For chains, use chain-levelchain.with_retry(...)andchain.with_fallbacks([...])instead. with_structured_outputdoes not stream — it accumulates the full response and returns the validated object. If you need streaming AND typed output, you can't have both via this API.
Production rules of thumb
- Always wrap production chains with
.with_retry(stop_after_attempt=3, wait_exponential_jitter=True)for resilience to transient model failures. - For provider redundancy, use
.with_fallbacks([cheaper_model_chain])— fallback chains run if the primary raises. The fallback is a full chain, not just a model. - For typed output, use
model.with_structured_output(PydanticModel)before composing into the chain. Validation is automatic; you get the Pydantic instance, not a dict. - For RAG, add a guardrail stage that returns "I don't know" when
len(context) == 0. Without it, the LLM hallucinates from empty context. - For RAG, consider a reranker between retriever and prompt. Recall@k improves substantially. The retriever's first 20 results passed through a reranker that picks the top 5 outperforms a retriever that fetches 5 directly.
When to reach for what
| Need | Tool |
|---|---|
| LLM + tools, deciding what to do next | create_agent (NOT LCEL) |
| Deterministic transformation (text → structured) | LCEL with with_structured_output |
| RAG over a vector store | LCEL with RunnableParallel of retriever + question |
| Multi-step pipeline with branches | LCEL with RunnableBranch or upgrade to StateGraph if branches need state |
| Streaming token output | LCEL chain (most parsers stream); NOT with_structured_output |
| Async at scale | LCEL .ainvoke / .astream |
Doc URLs to fetch with mcpdoc
https://docs.langchain.com/oss/python/langchain/lcel.md— LCEL primerhttps://docs.langchain.com/oss/python/langchain/structured-output.md—with_structured_outputhttps://docs.langchain.com/oss/python/langchain/runnables.md— Runnable types and methodshttps://docs.langchain.com/oss/python/langchain/retrievers.md— retriever interfaceshttps://docs.langchain.com/oss/python/langchain/chat-models.md—init_chat_modeland provider model names
When you need a specific class signature or kwarg, fetch from these. Don't guess at constructor args.
<!-- tomevault:4.0:skill_md:2026-05-23 -->Source: cwijayasundara/agent_cli_langchain — distributed by TomeVault.
- 流狐分类
- AI 智能
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 需简单配置
- 是否需要外部 API Key
- 需要 · OpenAI / Anthropic
- 检测到的系统要求
- 未声明
- 底层运行要求
- Python
- 检测到的文件与系统行为
-
- 只读
- 检测到的网络行为
- 允许外网请求
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
作者没有在当前 SKILL.md 中定义固定输出样例。 LCEL is for non-agentic flows: deterministic pipelines (RAG, summarization, classification, structured extraction). The pipeline runs once, end-to-end, no loop, no tool-calling LLM driving control flow. If the task involves an LLM deciding which tools to call,…
chain.invoke(x) where x is a string but the chain expects a dict will silently coerce in some configurations and fail in others — pass a dict explicitly. initchatmodel reads provider creds from env (OPENAIAPIKEY, ANTHROPICAPIKEY). It will not prompt; missing…
Always wrap production chains with .withretry(stopafterattempt=3, waitexponentialjitter=True) for resilience to transient model failures. For provider redundancy, use .withfallbacks([cheapermodelchain]) — fallback chains run if the primary raises. The fallback…
Need · Tool LLM + tools, deciding what to do next · createagent (NOT LCEL) Deterministic transformation (text → structured) · LCEL with withstructuredoutput
https://docs.langchain.com/oss/python/langchain/lcel.md — LCEL primer https://docs.langchain.com/oss/python/langchain/structured-output.md — withstructuredoutput https://docs.langchain.com/oss/python/langchain/runnables.md — Runnable types and methods
# LangChain (LCEL): editorial guidance
For API reference (full Runnable list, parser types, retriever interfaces), use the **`mcpdoc` MCP tools**: `fetch_docs("https://docs.langchain.com/oss/python/langchain/...")`. This skill is the *opinions* layer.
## When to use LCEL vs `create_agent`
LCEL is for **non-agentic flows**: deterministic pipelines (RAG, summarization, classification, structured extraction). The pipeline runs once, end-to-end, no loop, no tool-calling LLM driving control flow.
If the task involves an LLM deciding which tools to call, **don't use LCEL** — use `create_agent(...)` + middleware. Trying to bolt agentic behavior onto an LCEL chain is the most common mistake here. The dividing line: *does the LLM choose what happens next, or does the code?* If LLM, agents. If code, LCEL.
## Things the docs won't warn you about
- `chain.invoke(x)` where `x` is a string but the chain expects a dict will silently coerce in some configurations and fail in others — pass a dict explicitly.
- `init_chat_model` reads provider creds from env (`OPENAI_API_KEY`, `ANTHROPIC_API_KEY`). It will not prompt; missing env raises at first call, not at construction.
- Parsers are part of the chain. `chat_model.invoke(...)` returns an `AIMessage`; pipe through `StrOutputParser()` to get a plain string.
- **Middleware does NOT apply to LCEL chains.** Middleware is `create_agent`-only. For chains, use chain-level `chain.with_retry(...)` and `chain.with_fallbacks([...])` instead.
- `with_structured_output` does **not** stream — it accumulates the full response and returns the validated object. If you need streaming AND typed output, you can't have both via this API.
## Production rules of thumb
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> When to use LCEL vs createagent → Things the docs won't warn you about → Production rules of thumb → When to reach for what → Doc URLs to fetch with mcpdoc
要点 -> mcpdoc MCP tools · non-agentic flows · don't use LCEL · Middleware does NOT apply to LCEL chains. · not · For provider redundancy, use .withfallbacks([cheapermodelchain]) · For typed output, use model.withstructuredoutput(PydanticModel) · For RAG, add a guardrail stage
文件/命令 -> mcpdoc · fetchdocs("https://docs.langchain.com/oss/python/langchain/...") · createagent · createagent(...) · chain.invoke(x) · initchatmodel · OPENAIAPIKEY · ANTHROPICAPIKEY
内容 SHA-256 -> 11b6388719e7
原文结构
适用与边界
原文中的明确线索
mcpdoc、fetchdocs("https://docs.langchain.com/oss/python/langchain/...")、createagent、createagent(...)、chain.invoke(x)、initchatmodel、OPENAIAPIKEY、ANTHROPICAPIKEY