LangChain Explained: Chains, Agents and RAG in Plain Terms

LangChain Explained: Chains, Agents and RAG in Plain Terms

LangChain explained in one sentence: it is a free, open-source framework that gives developers standard building blocks for applications powered by large language models. LangChain turns the pieces of an AI application, prompts, models, tools, memory and documents, into components that snap together instead of being hand-wired for every project. The central question is when to use it, and the short answer is to use it when your application needs more than a single model call: retrieval, memory, tool use or a multi-step workflow.

LangChain was first released in October 2022 by Harrison Chase, and it quickly became the default starting point for building with language models. It reached its 1.0 release in October 2025, which settled the API with a commitment to no breaking changes until version 2.0. The framework is available for Python and JavaScript or TypeScript, and it is licensed under the MIT licence, so any team can use it without paying for the library itself.

Key takeaways

  • LangChain explained: an open-source, MIT-licensed framework for building LLM applications from composable building blocks.
  • LCEL, the LangChain Expression Language, is the modern way to compose chains, using a pipe operator to connect steps.
  • LangChain 1.0, released in October 2025, introduced a unified agent abstraction and moved legacy code into a separate package.
  • Retrieval-augmented generation is the most common use case, built from document loaders, retrievers and vector stores.
  • LangGraph handles stateful, looping agents, while LangSmith adds tracing, evaluation and deployment for production.

What LangChain is

LangChain is a framework, not an application. It is a library you write code against, with no graphical interface to install and no hosted service required to use the core. Instead of writing raw API calls to a model provider by hand, you use pre-built components for prompts, models, output parsing, retrieval, memory and agents, and you connect them into a pipeline that fits your product.

The framework’s central idea is the runnable: every component exposes the same interface, with methods to invoke, stream and run in batches. That consistency means a prompt template, a model and an output parser can be joined into one chain, and that chain can be swapped, tested or replaced piece by piece. Swapping from one model provider to another is often a one-line change, because the model interface is the same across providers.

Best for: teams building chatbots, retrieval systems, document assistants or agents in Python or TypeScript.

LCEL: the language for composing chains

LCEL, the LangChain Expression Language, is the declarative way to define chains, and it has been the standard since late 2023. It uses a pipe operator, borrowed from Unix, to connect steps: a prompt template feeds a model, and the model feeds an output parser. Each step’s output flows automatically into the next, and the whole chain behaves as a single runnable that can be invoked, streamed or run in batches.

LCEL also handles the practical details that hand-written code gets wrong. Streaming propagates through every component that supports it, so a chat interface can show tokens as they arrive. Structured output uses a model’s native function calling to return a typed object instead of raw text, which is useful when the result feeds another system.

Older chain classes from early tutorials are now deprecated, so new code should use LCEL throughout. For the wider landscape of application frameworks, see our guide to LLM application frameworks. Best for: any multi-step LLM pipeline where steps can be expressed as a fixed sequence.

Retrieval-augmented generation with LangChain

Retrieval-augmented generation, or RAG, is the most common LangChain use case. A RAG pipeline loads documents, splits them into chunks, stores the chunks in a vector store, and retrieves the relevant ones at query time to ground the model’s answer in your own data. LangChain supplies standard interfaces for each stage: document loaders for PDF, web, Notion and other sources, text splitters for chunking, and retrievers that work with any supported vector store.

The value of the abstraction is that the pieces are interchangeable. You can change the vector store, the embedding model or the chunking strategy without rewriting the pipeline, and you can test each part in isolation. That matters because retrieval quality decides answer quality: a pipeline that retrieves the wrong chunks will produce confident, well-written wrong answers.

For the retrieval patterns themselves, see our guide to RAG architecture and our guide to RAG chunking strategies. Best for: question-answering over your own documents, knowledge bases and internal data.

Agents, tools and memory

An agent is a system where the model decides which tool to call and when, rather than following a fixed sequence. LangChain’s 1.0 release unified the agent interface around a single create agent abstraction, built on top of LangGraph, with middleware for customising behaviour such as retries, human approval and prompt handling. That change made agents simpler to build and easier to reason about, because the same runtime powers both simple agents and complex graphs.

Tools are functions the agent can invoke, such as searching a database, fetching a web page or running a calculation. Memory stores conversation history so the model does not forget what was said earlier, and LangChain’s built-in memory options cover the common cases, from a simple message buffer to a summary of the conversation so far. The danger is giving an agent tools it does not need: every tool is a new way for the model to go wrong, so keep the toolset small and each tool narrow.

For the patterns that keep agents reliable, see our guide to agent design patterns. Best for: assistants that must act, such as looking up data, calling APIs or completing multi-step tasks.

Comparing LangChain with the alternatives

Approach What it does Strength Main weakness
LangChain Composable LLM building blocks Largest ecosystem, many integrations Large surface, learning curve
LangGraph Stateful graph-based agents Durable execution, loops, branching Lower level, more code to write
Raw provider SDKs Direct model API calls Full control, no dependency Everything must be built by hand
LlamaIndex Data-focused RAG framework Strong retrieval and indexing Narrower than LangChain for agents
CrewAI Role-based multi-agent teams Fast to build agent teams Less control over execution

The table shows that LangChain is the generalist: it covers more ground than the specialists, at the cost of a larger surface to learn. LangGraph is not a rival but a sibling, built by the same company, and LangChain’s own agents now run on top of it. For a fuller comparison of agent frameworks, see our guide to AI agent frameworks.

An open notebook with a hand-drawn chain of linked boxes and arrows beside a laptop on a wooden desk
LangChain’s core idea is simple: a chain is a sequence of steps where each step’s output becomes the next step’s input.

LangSmith: tracing, evaluation and deployment

LangSmith is the paid platform built on top of the LangChain ecosystem, and it is the part that makes production work visible. It traces every call an agent makes, storing the full input and output at each step, with latency and token counts. When a user reports a bad answer, the trace shows exactly which chunks the retriever returned, which arguments the model passed to a tool, and where the run went wrong.

LangSmith also provides evaluation tooling: you can build a dataset of real queries with expected answers and run automated scoring on every code change, including LLM-as-judge evaluators that score outputs on custom criteria. Enabling tracing takes only a few environment variables, with no other code changes. The Developer tier is free, and a Plus plan is available for teams that need more seats and features.

Best for: any team that ships a LangChain application to real users and needs to debug it when it misbehaves.

How to start: a decision framework

Start with the smallest thing that works. Install the library, which needs Python 3.10 or higher, and build a single LCEL chain: a prompt, a model and an output parser. Add retrieval only when the application needs your own data, add memory only when it needs conversation history, and add an agent only when the model must choose between tools.

Each layer adds a failure mode, so add them one at a time and test each one.

Choose the model provider separately from the framework, because LangChain’s interfaces make switching cheap. Prototype with one provider, measure quality and cost on your own test cases, and switch if another model does the same job for less. Add LangSmith tracing from the first day, because retrofitting observability after a production failure is painful.

For the orchestration side of the same decision, see our guide to AI orchestration architecture, which explains where LangChain fits among schedulers and durable execution engines.

LangChain checklist

  • New code uses LCEL chains, not the deprecated chain classes from old tutorials.
  • The application starts as one small chain, with retrieval, memory and agents added one at a time.
  • Each tool does one narrow job and returns short, structured results.
  • Retrieval quality is tested with real queries before the pipeline ships.
  • LangSmith tracing is enabled from the first day of development.
  • An evaluation dataset exists, so code changes are scored before they reach users.
  • Model choice is measured on real test cases, not assumed from benchmarks.

Frequently asked questions

What is LangChain used for?

LangChain is used to build applications on top of large language models: chatbots, retrieval-augmented generation over your own documents, agents that call tools, and multi-step workflows. It provides standard building blocks for prompts, models, retrieval, memory and agents, so developers do not hand-wire every integration.

Is LangChain free?

Yes. LangChain is free and open source under the MIT licence. The company behind it sells LangSmith, an optional paid platform for tracing, evaluation and deployment, but the framework itself costs nothing to use.

What changed in LangChain 1.0?

LangChain 1.0, released in October 2025, unified chains and agents around a single abstraction built on LangGraph, introduced middleware for customising agent behaviour, and standardised content blocks for model outputs. Legacy functionality moved to a separate package, and the release committed to no breaking changes until version 2.0.

What is the difference between LangChain and LangGraph?

LangChain is the general framework for LLM applications, while LangGraph is the lower-level library for stateful, graph-based agents with loops, branching and durable execution. LangChain’s agents now run on LangGraph, so the two are complementary: use LangChain for the building blocks and LangGraph when the workflow needs explicit state and control flow.

Do I need LangChain to call an LLM API?

No. You can call a provider’s API directly with its own SDK, and for a single model call that is often simpler. LangChain earns its place when the application needs retrieval, memory, tool use or a multi-step pipeline, because those are the parts it standardises.

Latest articles

Scroll to Top