langchain-agents-langchain-code
- Repo stars 0
- Author repo 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.
- Fluxly category
- AI
- Author-declared agents
- No explicit declaration found; this is not inferred or tested compatibility
- Static check
- 88 / 100 · heuristic scan, not runtime safety proof
- Author / version / license
- @tomevault-io · no license declared
- Fluxly token estimate
- Lean
- Fluxly setup estimate
- Guided setup
- External API key
- Required · OpenAI / Anthropic
- Detected OS requirements
- Unspecified
- Runtime requirements
- Python
- Detected file/system behavior
-
- Read-only
- Detected network behavior
- External requests
- Install commands
- None (reference only)
Profile is derived at build time from SKILL.md and install vectors. Subject to drift from author intent.
Heads up: 未限定 allowed-tools,默认拥有全部工具权限。
The current SKILL.md does not define a fixed output example. 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
… Author text anchors workflow facts; Fluxly only indexes current sections, terms, files, and commands.
sections -> 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
terms -> 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
files/cmd -> mcpdoc · fetchdocs("https://docs.langchain.com/oss/python/langchain/...") · createagent · createagent(...) · chain.invoke(x) · initchatmodel · OPENAIAPIKEY · ANTHROPICAPIKEY
body sha256 -> 11b6388719e7
Decide Fit First
Design Intent
How To Use It
Boundaries And Review