agentleFS
sordi-aisordi-ai/skill-everything/skills/langchain/SKILL.md

langchain

Skill20 starsChanged 7 months agoMITView on GitHub

Apply when building LangChain pipelines, LCEL chains, agents, or retrieval-augmented generation systems.

8 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

22 rules. 0 are common, 2 are distinctive, and 20 are very specific to this project.

  • 0

    Common

    Most of the 5 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 20

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use LCEL pipe syntax: Always use the LCEL pipe operator (|) to compose runnables instead of deprecated constructor-based chain classes …

    line 25
  2. Very specific:

    Avoid legacy chain imports: Never import from langchain.chains.llm or langchain.chains.sequential.

    line 26
  3. Very specific:

    Prefer RunnablePassthrough for identity steps: Use RunnablePassthrough to thread context through a chain without mutation rather than …

    line 27
  4. Very specific:

    Use RunnableParallel for fan-out: Prefer RunnableParallel over manually calling multiple chains and merging dicts.

    line 28
  5. Very specific:

    Use typed output parsers: Always attach an output parser (PydanticOutputParser, JsonOutputParser, StrOutputParser) to chains that produce …

    line 32
  6. Very specific:

    Inject format instructions via partial: Use prompt.partial(format_instructions=parser.get_format_instructions()) to bind parser …

    line 33
  7. Very specific:

    Separate system and human messages: Use ChatPromptTemplate.from_messages([("system", ...), ("human", ...)]) instead of a single …

    line 34
  8. Very specific:

    Prefer ChatModel over LLM: Always use ChatOpenAI, ChatAnthropic, or equivalent chat-model classes for new code.

    line 38
  9. Very specific:

    Pin model name explicitly: Never rely on the default model name in a chat model constructor.

    line 39
  10. Very specific:

    Use RunnableWithMessageHistory for stateful chains: Prefer RunnableWithMessageHistory over manual history management or deprecated …

    line 43
  11. Very specific:

    Scope memory by session ID: Always pass a session_id key when constructing RunnableWithMessageHistory to prevent cross-user memory leakage …

    line 44
  12. Very specific:

    Define tools with @tool decorator: Use the @tool decorator (or StructuredTool.from_function) with a typed signature and docstring.

    line 48
  13. Very specific:

    Use create_tool_calling_agent for modern agents: Prefer create_tool_calling_agent + AgentExecutor over deprecated initialize_agent.

    line 49
  14. Very specific:

    Cap agent iterations: Always set max_iterations and max_execution_time on AgentExecutor to prevent runaway loops.

    line 50
  15. Very specific:

    Ensure document loaders are lazy: Prefer .lazy_load() over .load() for large corpora to avoid loading all documents into memory at once.

    line 55
  16. Very specific:

    Wrap LLM calls with retry: Use .with_retry(stop_after_attempt=3, wait_exponential_jitter=True) on any runnable that calls an external API.

    line 59
  17. Very specific:

    Set request timeout: Always pass request_timeout (or timeout) to chat model constructors.

    line 60
  18. Very specific:

    Attach callbacks for observability: Use callbacks=[LangSmithTracer()] or equivalent on chains in production.

    line 61
  19. Very specific:

    Count tokens before sending: Before sending large contexts, use llm.get_num_tokens(text) or a tiktoken counter to verify the payload fits …

    line 62
  20. Distinctive:

    Sanitize user input before prompt injection: Never interpolate raw user strings directly into system prompts.

    line 66
  21. Distinctive:

    Disable dangerous tools in untrusted contexts: Avoid giving agents tools with filesystem or shell access when processing untrusted input.

    line 67
  22. Very specific:

    Enable semantic caching in dev: Use set_llm_cache(InMemoryCache()) during development and SQLiteCache in staging to avoid redundant API …

    line 71

“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Sub-Skill: LangChain / Agent Framework Conventions

Purpose: Prevent common LangChain mistakes — deprecated chain classes, missing retry/timeout guards, unsafe prompt handling, and unobservable pipelines.


Rules

Chain Construction

  1. Use LCEL pipe syntax. Always use the LCEL pipe operator (|) to compose runnables instead of deprecated constructor-based chain classes (LLMChain, SequentialChain, TransformChain). Reference: ERR-2026-026
  2. Avoid legacy chain imports. Never import from langchain.chains.llm or langchain.chains.sequential; use langchain_core.runnables and langchain_core.prompts instead.
  3. Prefer RunnablePassthrough for identity steps. Use RunnablePassthrough to thread context through a chain without mutation rather than writing a lambda that returns its input unchanged.
  4. Use RunnableParallel for fan-out. Prefer RunnableParallel over manually calling multiple chains and merging dicts; it expresses intent and enables parallel execution.

Prompts & Output Parsers

  1. Use typed output parsers. Always attach an output parser (PydanticOutputParser, JsonOutputParser, StrOutputParser) to chains that produce structured data; never parse raw LLM strings manually downstream.
  2. Inject format instructions via partial. Use prompt.partial(format_instructions=parser.get_format_instructions()) to bind parser instructions into the prompt template rather than hard-coding them in the template string.
  3. Separate system and human messages. Use ChatPromptTemplate.from_messages([("system", ...), ("human", ...)]) instead of a single PromptTemplate for chat models; mixing roles in one string breaks structured output.

Chat Models vs LLMs

  1. Prefer ChatModel over LLM. Always use ChatOpenAI, ChatAnthropic, or equivalent chat-model classes for new code; the base OpenAI LLM class is deprecated for most use cases and lacks tool-calling support.
  2. Pin model name explicitly. Never rely on the default model name in a chat model constructor; always pass model="gpt-4o" (or equivalent) so upgrades are intentional.

Memory & State

  1. Use RunnableWithMessageHistory for stateful chains. Prefer RunnableWithMessageHistory over manual history management or deprecated ConversationChain; it integrates cleanly with LCEL and supports async.
  2. Scope memory by session ID. Always pass a session_id key when constructing RunnableWithMessageHistory to prevent cross-user memory leakage in multi-tenant services.

Tools & Agents

  1. Define tools with @tool decorator. Use the @tool decorator (or StructuredTool.from_function) with a typed signature and docstring; never pass raw callables to an agent without a schema.
  2. Use create_tool_calling_agent for modern agents. Prefer create_tool_calling_agent + AgentExecutor over deprecated initialize_agent; it uses native tool-calling APIs and avoids ReAct string parsing.
  3. Cap agent iterations. Always set max_iterations and max_execution_time on AgentExecutor to prevent runaway loops; default is unbounded.

Retrieval & Vector Stores

  1. Use retrieval chains via LCEL. Build RAG pipelines with retriever | format_docs | prompt | llm | parser rather than RetrievalQA.from_chain_type; the latter is deprecated and hides the retrieval step.
  2. Ensure document loaders are lazy. Prefer .lazy_load() over .load() for large corpora to avoid loading all documents into memory at once.

Reliability & Observability

  1. Wrap LLM calls with retry. Use .with_retry(stop_after_attempt=3, wait_exponential_jitter=True) on any runnable that calls an external API; never let transient rate-limit errors propagate uncaught.
  2. Set request timeout. Always pass request_timeout (or timeout) to chat model constructors; omitting it allows indefinitely hanging requests.
  3. Attach callbacks for observability. Use callbacks=[LangSmithTracer()] or equivalent on chains in production; never ship a pipeline with no tracing so failures are diagnosable.
  4. Count tokens before sending. Before sending large contexts, use llm.get_num_tokens(text) or a tiktoken counter to verify the payload fits within the model's context window.

Security

  1. Sanitize user input before prompt injection. Never interpolate raw user strings directly into system prompts; use a dedicated input variable in the prompt template and validate/strip control characters before binding.
  2. Disable dangerous tools in untrusted contexts. Avoid giving agents tools with filesystem or shell access when processing untrusted input; scope tool permissions to the minimum required.

Caching & Cost

  1. Enable semantic caching in dev. Use set_llm_cache(InMemoryCache()) during development and SQLiteCache in staging to avoid redundant API calls and reduce cost during iteration.

See also

  • skills/python/SKILL.md
  • skills/error-log/SKILL.md

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.