agentleFS
G1JoshiG1Joshi/Agent-Skills/skills/ai-ml/langchain/SKILL.md

langchain

Skill15 starsChanged 44 days agoMITView on GitHub

Expert LangChain and LangGraph assistance covering LCEL pipe syntax, tools, memory, retrievers, and cyclic multi-agent graphs. Use when orchestrating complex LLM chains and autonomous agents.

11 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use analytics-metrics, aws-account-management and 7 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • hoodiniSkill

    analytics-metrics

    Build data visualization and analytics dashboards. Use when creating charts, KPI displays, metrics dashboards, or data visualization components. Triggers on analytics, dashboard, charts, metrics, KPI, data visualization, Recharts.

    Also in 3 projects that use this

  • hoodiniSkill

    aws-account-management

    Manage AWS accounts, organizations, IAM, and billing. Use when setting up AWS Organizations, managing IAM policies, controlling costs, or implementing multi-account strategies. Triggers on AWS Organizations, AWS IAM, AWS billing, Cost Explorer, SCPs, multi-account, AWS SSO, Identity Center.

    Also in 3 projects that use this

  • +7 more from hoodini

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use LangGraph state graphs with message nodes and conditional edges:

    line 123
  2. Distinctive:

    Use LangGraph for multi-turn, stateful, cyclical agent architectures rather than legacy AgentExecutor.

    line 150
  3. Very specific:

    Use deprecated v0.1 import paths (langchain.chains or langchain.agents).

    line 156

“Common” is measured: kept by at least 6 in 10 of the 8 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

LangChain

LangChain is a composable framework for building applications with LLMs, featuring LangGraph for constructing robust, stateful, cyclic multi-agent architectures.

When to Use

  • Agentic Workflows & Multi-Turn Problem Solving: Building autonomous AI agents with LangGraph and tool calling.
  • Complex Retrieval-Augmented Generation (RAG): Orchestrating document chunking, embeddings, vector indexing, and reranking.
  • Declarative Chain Composition with LCEL: Composing streaming, async, and batchable chains via LangChain Expression Language.
  • Enterprise LLM Observability: Tracking token costs, latency, and step-by-step traces with LangSmith.

Quick Start

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

# Declarative LCEL Pipe Syntax
prompt = ChatPromptTemplate.from_template("Summarize this concept in 3 bullet points: {topic}")
model = ChatOpenAI(model="gpt-4o-mini")
parser = StrOutputParser()

chain = prompt | model | parser
result = chain.invoke({"topic": "Distributed Consensus"})
print(result)

Core Concepts

LangChain Expression Language (LCEL) & Streaming

Declarative pipe-based chain execution with type inference and streaming:

from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
from langchain_openai import ChatOpenAI
import os

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are an expert cloud architect. Answer concisely."),
    ("user", "Explain the difference between {topic_a} and {topic_b}.")
])

model = ChatOpenAI(model="gpt-4o-mini", temperature=0.2)
parser = StrOutputParser()

# LCEL Pipeline: prompt | model | parser
chain = prompt | model | parser

# Stream output tokens in real-time
for chunk in chain.stream({"topic_a": "Kubernetes", "topic_b": "Docker Swarm"}):
    print(chunk, end="", flush=True)

Retrieval-Augmented Generation (RAG) Pipeline

Querying vector stores and passing relevant context to LLMs:

from langchain_core.runnables import RunnablePassthrough
from langchain_core.prompts import ChatPromptTemplate
from langchain_community.vectorstores import FAISS
from langchain_openai import OpenAIEmbeddings, ChatOpenAI

# Mock vectorstore retriever
embeddings = OpenAIEmbeddings()
vectorstore = FAISS.from_texts(
    ["Antigravity IDE is an AI-first coding assistant.", "LangChain v0.3 introduces streamlined core abstractions."],
    embedding=embeddings
)
retriever = vectorstore.as_retriever(search_kwargs={"k": 2})

rag_prompt = ChatPromptTemplate.from_template(
    "Answer the question based only on context: {context}\nQuestion: {question}"
)

rag_chain = (
    {"context": retriever, "question": RunnablePassthrough()}
    | rag_prompt
    | ChatOpenAI(model="gpt-4o-mini")
    | StrOutputParser()
)

response = rag_chain.invoke("What does LangChain v0.3 introduce?")
print(response)

Agentic Workflows with Tool Calling

Binding custom Python functions as agent tools:

from langchain_core.tools import tool
from langchain_openai import ChatOpenAI

@tool
def calculate_shipping(weight_kg: float, destination: str) -> float:
    '''Calculate the shipping fee in USD for a parcel weight and destination.'''
    rate = 12.5 if destination.upper() == "US" else 28.0
    return round(weight_kg * rate, 2)

tools = [calculate_shipping]
llm = ChatOpenAI(model="gpt-4o-mini").bind_tools(tools)

result = llm.invoke("What is the shipping cost for a 4.5kg package to the US?")
print("Tool Calls:", result.tool_calls)

Common Patterns

Stateful Agent Workflow with LangGraph

Problem: Legacy AgentExecutor loops lack checkpointing and cannot recover from partial errors.

Solution: Use LangGraph state graphs with message nodes and conditional edges:

from typing import TypedDict, Annotated, Sequence
from langchain_core.messages import BaseMessage
from langgraph.graph import StateGraph, END
import operator

class AgentState(TypedDict):
    messages: Annotated[Sequence[BaseMessage], operator.add]

def call_model(state: AgentState):
    # Process messages with LLM
    return {"messages": [model.invoke(state["messages"])]}

workflow = StateGraph(AgentState)
workflow.add_node("agent", call_model)
workflow.set_entry_point("agent")
workflow.add_edge("agent", END)
app = workflow.compile()

Best Practices

Do:

  • Target LangChain v0.3+ and construct pipelines using LCEL (chain = prompt | model | parser).
  • Use LangGraph for multi-turn, stateful, cyclical agent architectures rather than legacy AgentExecutor.
  • Configure LangSmith (LANGCHAIN_TRACING_V2=true) to monitor latency, cost, and tool calls in development and production.
  • Bind tools explicitly with Pydantic type annotations and docstrings for reliable tool call generation.

Don't:

  • Use deprecated v0.1 import paths (langchain.chains or langchain.agents); import from langchain_core and langgraph.
  • Construct prompts using manual string formatting; use ChatPromptTemplate to properly handle roles and escapes.
  • Pass unvalidated user input directly to vectorstore retriever filters.

Troubleshooting

ErrorCauseSolution
OutputParserException: Failed to parseLLM response did not adhere to expected JSON schema format.Add retry parser OutputFixingParser or use native model structured outputs.
Recursion limit reached in LangGraphInfinite loop in graph conditional edge routing.Inspect routing logic and increase recursion_limit in config if expected.
RateLimitError in streaming chainsToo many simultaneous tokens per second requested across chains.Implement async concurrency throttler or use batching with .batch().

References

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.