Free to read. Sign up to save your progress and take knowledge-check quizzes.

Sign up free
6 min read·Updated March 24, 2026

LangChain

LangChain logoBy LangChain

LangChain is the most widely used open-source framework for building LLM-powered applications — providing composable building blocks for chains, agents, RAG pipelines, tool use, and memory that let developers build sophisticated AI workflows in Python or JavaScript.

Listen to this lesson

Free preview · first 0:30
0:00 / 0:30

Audio & video lessons are paid features

Plus unlocks audio streaming. Pro adds downloadable audio, video, certificates, and more.

Plus adds:
  • Audio streaming
  • Downloadable PDFs
  • All AI Playbooks
  • Personalized content
Pro also adds:
  • Certificates of completion
  • Audio MP3 downloads
  • Video lessonssoon
  • & More…soon

Watch this lesson

Video coming soon

Learning Objectives

  • Understand what LangChain is and what problem it solves for AI application developers
  • Identify the core components: chains, agents, RAG pipelines, tool integrations, and LangChain Expression Language
  • Evaluate when to use LangChain vs. raw API calls vs. alternative frameworks

What Is LangChain?

LangChain is an open-source framework for building applications powered by large language models, created by Harrison Chase in 2022 and now maintained by LangChain AI. With over 90,000 GitHub stars and hundreds of thousands of active users, LangChain is by far the most widely adopted framework for LLM application development.

LangChain's core insight is that most LLM-powered applications share common patterns — call a model, process the output, call another model or tool, maintain some state — and that standardizing these patterns with composable components lets developers build faster, avoid repetitive code, and benefit from a large ecosystem of community-built integrations.

Tip

Try LangChain: Open source at langchain.com; install with pip install langchain langchain-openai langchain-community; LangSmith (observability) free tier available; no API key required for the framework itself

Core Components

Chains — Composable Sequences

A chain is a sequence of LLM calls and processing steps executed in order:

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

prompt = ChatPromptTemplate.from_template("Summarize this text: {text}")
model = ChatOpenAI(model="gpt-4o")
parser = StrOutputParser()

chain = prompt | model | parser

result = chain.invoke({"text": "Long document here..."})

LangChain Expression Language (LCEL) uses the | pipe operator to compose chains — similar to Unix pipes. This makes chain construction readable and modular.

Retrieval-Augmented Generation (RAG)

LangChain's most widely used pattern — building a system that retrieves relevant documents before generating:

from langchain_community.vectorstores import Chroma
from langchain_openai import OpenAIEmbeddings, ChatOpenAI
from langchain.chains import RetrievalQA

# Create vector store from documents
vectorstore = Chroma.from_documents(documents, OpenAIEmbeddings())
retriever = vectorstore.as_retriever()

# Build RAG chain
qa_chain = RetrievalQA.from_chain_type(
    llm=ChatOpenAI(),
    retriever=retriever
)
answer = qa_chain.invoke("What does the policy say about vacation days?")

LangChain handles document loading (PDF, web, databases), text splitting, embedding, vector storage, and retrieval — with integrations for every major vector store (Chroma, Pinecone, Weaviate, Supabase).

💡Key Concept

The LangChain ecosystem: LangChain's value is partly the framework itself and partly the ecosystem — 800+ document loaders, 50+ vector stores, 100+ LLM providers, and hundreds of community-built tools are all directly importable from langchain-community. Building a RAG pipeline over a Confluence wiki, with Pinecone as the vector store, grounded by OpenAI embeddings, and served via FastAPI — every component has a native LangChain integration.

Agents — Tool-Using LLMs

LangChain agents implement the ReAct (Reason + Act) pattern — an LLM that decides which tools to use and in what order to accomplish a goal:

from langchain.agents import create_react_agent, AgentExecutor
from langchain_community.tools.tavily_search import TavilySearchResults
from langchain_openai import ChatOpenAI

tools = [TavilySearchResults(max_results=5)]
llm = ChatOpenAI(model="gpt-4o")

agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools)

result = agent_executor.invoke({"input": "What are the latest AI safety guidelines from Anthropic?"})

LangGraph — Stateful Agent Workflows

LangGraph is LangChain's production-grade framework for building complex, stateful agent workflows as directed graphs. Both LangChain and LangGraph reached their v1.0 milestones in early 2026, with production adoption at companies like Uber, LinkedIn, and Klarna.

  • Define agent workflow as nodes and edges
  • Durable execution — agents persist through failures and resume automatically
  • Supports cycles (agents that can loop back based on results)
  • Human-in-the-loop checkpoints for review at critical decision points
  • Multi-agent orchestration with both short-term working memory and long-term persistent memory
  • Deep Agents — a newer harness for agents that can plan, spawn subagents, and use file systems for complex multi-step tasks

LangChain agents are now built on LangGraph underneath — you can start with LangChain's high-level APIs and drop down to LangGraph when you need finer control. LangGraph is the recommended path for production agent systems.

Document Loaders

LangChain's 800+ document loaders cover every content source:

  • PDF, Word, PowerPoint, CSV, JSON, HTML, Markdown
  • Web: WebBaseLoader, PlaywrightURLLoader, FireCrawlLoader
  • Databases: SQL, MongoDB, Supabase
  • Cloud: S3, Google Drive, Notion, Confluence, GitHub
  • APIs: YouTube (transcripts), Wikipedia, ArXiv, PubMed

Memory

Different memory implementations for different use cases:

  • ConversationBufferMemory: Keep the full conversation in context
  • ConversationSummaryMemory: Summarize older messages when context window fills
  • VectorStoreRetrieverMemory: Retrieve relevant past conversations from vector store
  • Redis/PostgreSQL backed: Persistent memory across sessions

Pricing

LangChain the framework is completely free and open source (MIT license). Costs come from:

  • LLM API calls (OpenAI, Anthropic, Google — charged by those providers)
  • Vector store hosting (Pinecone, Weaviate — their pricing applies)
  • LangSmith (observability platform): free tier available; paid plans from $39/month

Strengths

  • Largest ecosystem: 800+ integrations; largest LLM framework community
  • Most documentation and examples: Extensive official docs and community tutorials
  • Composability: LCEL and functional design make complex chains readable and maintainable
  • LangGraph: Production-grade stateful agent framework for complex workflows
  • LangSmith: Excellent observability — trace every LLM call, debug prompts, evaluate output quality
  • Framework agnostic: Works with OpenAI, Anthropic, Google, Cohere, local models (Ollama), and 100+ other providers

Limitations & Considerations

  • Abstraction complexity: For very simple single-call applications, LangChain's abstractions can feel like over-engineering compared to direct API calls
  • Versioning and breaking changes: LangChain has changed its API significantly multiple times — tutorials from 2023 may use deprecated patterns
  • Performance overhead: Adding a framework layer introduces small but real overhead vs. raw API calls
  • Large dependency surface: langchain-community pulls in many optional dependencies; careful to install only what's needed
  • Competition from simpler alternatives: For straightforward use cases, newer minimal frameworks (LiteLLM, instructor) may be more appropriate

Best Use Cases

TaskWhy LangChain
RAG pipeline over documentsBest-in-class document loading, chunking, embedding, retrieval ecosystem
LLM-powered applicationsStructured way to organize complex multi-step AI workflows
Tool-using agentsReAct agents with 100+ built-in tools + any custom function
Multi-model applicationsAbstract away provider differences; switch models in one line
Production agent workflowsLangGraph for stateful, cyclic, multi-agent production systems
Rapid prototypingFastest path from idea to working LLM application

When to choose alternatives:

  • Simple single LLM call without chaining → direct OpenAI/Anthropic SDK
  • Multi-agent orchestration focus → AG2 or CrewAI
  • Python-only, minimum dependencies → LlamaIndex (more focused for RAG)
  • Structured output extraction → Instructor library
  • Full agentic coding platform → Claude Code or OpenAI Codex

Getting Started

pip install langchain langchain-openai langchain-community
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage

model = ChatOpenAI(model="gpt-4o")
response = model.invoke([HumanMessage(content="Explain LangChain in 2 sentences")])
print(response.content)

From here, explore the LangChain docs — the LCEL tutorial is the best starting point.

Tip

LangSmith for debugging: When LangChain applications produce unexpected results, the cause is often a prompt or context issue deep in a chain that's hard to inspect. LangSmith traces every LLM call, showing exactly what prompt was sent, what the model responded, and how long each step took. The free tier is sufficient for development and debugging — add LANGCHAIN_TRACING_V2=true and LANGCHAIN_API_KEY to your environment and every chain execution is automatically traced.

Key Takeaways

  • LangChain is the most widely used open-source framework for building LLM applications — chains, agents, RAG pipelines, and memory systems
  • LangChain Expression Language (LCEL) provides composable, readable chain construction using the pipe operator
  • 800+ document loaders, 50+ vector stores, and 100+ LLM providers make LangChain the most broadly integrated AI framework
  • LangGraph extends LangChain with stateful, cyclic agent workflows — the production-grade layer for complex multi-step AI applications
  • Free and open source; costs come from the underlying LLM API providers and vector databases you integrate with

Save your progress & take the quiz

Sign up free to bookmark lessons, track which modules you've completed, and lock in what you learned with a quick knowledge-check quiz at the end of each lesson.

🧭Recommended for you