LangChain has become one of the most widely used frameworks for building LLM-powered applications. If you're working with large language models in Python or JavaScript, you'll keep running into it across tutorials, GitHub repos, and production AI stacks. The library suite covers the parts most projects end up needing: prompt composition, retrieval, agents, observability, and deployment.
This guide walks through what LangChain is, how its components fit together, where it stacks up against lighter alternatives, and how to deploy it on Vercel with the AI SDK.
Copy link to headingWhat is LangChain?
LangChain is an open-source framework for building applications powered by large language models. Harrison Chase started the project in October 2022, and it has since grown into a suite spanning LangChain core, LangGraph, and LangSmith, with first-class support in Python and JavaScript/TypeScript. The v1.0 release made create_agent the primary way to build agents, and LangChain Expression Language (LCEL) lets you compose chains with a pipe operator (|) that should feel familiar if you've spent any time in a Unix shell.
The whole point is to give you one shape for working with LLMs no matter what's underneath. You can swap OpenAI for Anthropic without rewriting your prompts, pull context from a Postgres table or vector store through the same retriever interface, and stitch together multi-step workflows where one model's output feeds the next call. Without a framework, you'd be writing that glue code yourself for every new integration.
Copy link to headingHow LangChain works
A LangChain application moves your data through a sequence of components, with each one handling a specific job before passing its output to the next. Prompts, models, retrievers, and parsers all share the same interface, so you can swap pieces in and out without breaking the rest of your pipeline. A typical run flows like this:
Input formatting: A prompt template formats your user's input into structured messages that the model can read.
Model invocation: The language model receives the prompt and generates a response.
Tool and data access: Retrievers, tools, or external APIs feed extra context into the prompt as needed.
Output parsing: A parser converts the model's raw response into a structured type your code can use.
LCEL is what wires those pieces together. With the pipe operator, a working chain can be as short as chain = prompt | llm | output_parser, and every component implements the Runnable interface, so you get .invoke(), .stream(), and .batch() on the whole chain for free.
For agents, the model runs inside a reasoning loop instead of a fixed pipeline. It reads the input, decides whether to call a tool or answer directly, reads the tool result, and loops again until it can respond. The create_agent() API ties this loop into LangGraph, which handles state, checkpoints, and execution behind the scenes.
Copy link to headingCore components of LangChain
LangChain is built from a small set of components that compose into almost any LLM application you'd want to build. The shared interface lets them slot together cleanly, which keeps the integration work small.
Copy link to headingModels and the LLM interface
Models are the reasoning engine of any LangChain app, and ChatModel is the current standard. It handles tool calling, structured output, and multimodal input across providers like OpenAI, Anthropic, and Google. Since every chat model exposes the same methods, swapping ChatOpenAI for ChatAnthropic comes down to a one-line change.
Copy link to headingPrompts and prompt templates
Prompt templates format your user's input into the structured messages a chat model expects. They support plain text, chat message lists with system, human, and AI roles, and MessagesPlaceholder for injecting conversation history at runtime. You can reuse the same template across models, test it in isolation, and version-control it alongside the rest of your code, which is what you'd want anyway.
Copy link to headingChains and LCEL
LCEL connects components with the pipe operator, giving you a declarative way to express flow from input to output. The simplest useful chain is prompt | llm | output_parser, and you keep composing from there. LCEL handles sequential and parallel execution, so you can fan out to several retrievers at once and merge their results before the model sees them.
Copy link to headingMemory and retrievers
Short-term memory is the list of messages passed to the model within a single run, injected through MessagesPlaceholder. For anything longer-lived, LangGraph's persistence layer stores checkpoints so your agent can pick up a conversation hours or days later.
Retrievers fetch relevant documents from a vector store at query time. LangChain ships integrations for FAISS, Pinecone, ChromaDB, and others, and calling vectorstore.as_retriever() returns a VectorStoreRetriever that drops straight into an LCEL chain.
Copy link to headingAgents and tools
Agents use an LLM to decide, at runtime, which tool to call next. Tools are Python or JavaScript functions you register with the agent, and the model picks among them based on the user's request and whatever results have come back from earlier calls. The create_agent() API binds your tool schemas to the model and wires the whole thing into LangGraph, so the agent chooses actions based on reasoning and the tool results it sees as it goes.
Copy link to headingThe LangChain ecosystem
LangChain ships alongside a small set of companion projects that cover the parts a chain can't handle on its own: stateful execution, tracing, and deployment. You'll bump into each of them once your prototype starts handling real workloads.
Copy link to headingLangGraph for stateful, multi-step agents
LangGraph models your agent workflows as graphs, with nodes for processing steps, edges between them, and shared state passing through. Cycles, conditional branching, parallel execution, and checkpointing all come built in, so you can pause a run, inspect it, and pick up from the last checkpoint without rerunning earlier work. For agents that make decisions and keep state intact across runs, you'll spend most of your time inside LangGraph.
Copy link to headingLangSmith for observability and evaluation
LangSmith is the tracing and observability platform from the same team. Setting LANGSMITH_TRACING=true in your environment routes traces from any LangChain or LangGraph app into a dashboard where you can step through each call, inspect inputs and outputs, and replay runs against test datasets.
It's framework-agnostic too, with OpenTelemetry support for the OpenAI SDK, Anthropic SDK, AI SDK, and LlamaIndex, so a lot of teams use it as a general-purpose LLM observability layer.
Copy link to headingCommon LangChain use cases
Most LangChain applications fall into one of four patterns. Retrieval-augmented generation, chatbots, document workflows, and agents account for the bulk of what gets shipped, and all four run on the same underlying primitives: chains, tools, memory, and retrievers.
Copy link to headingRetrieval-augmented generation (RAG)
RAG is one of the most common reasons developers pick up LangChain in the first place. The basic version is a two-step chain that retrieves relevant chunks from a vector store and then passes them to the model as context for an answer, which fits FAQ-style queries where retrieval is always needed.
An agentic RAG setup turns retrieval into a tool the model can call when it decides context is needed, alongside others like web search or database lookups. The chain version is cheaper and more deterministic, while the agent version handles open-ended questions where the model might need to pull information from several sources before answering.
Copy link to headingChatbots and conversational assistants
Calling chain.stream() instead of chain.invoke() returns tokens as the model produces them, which keeps your chat UI responsive and makes streaming the baseline for any conversational interface you ship.
LangGraph adds the rest of what a real assistant needs, including persistent memory across sessions, human-in-the-loop approval gates, and structured multi-turn context. Tool calls coming back from a LangGraph agent can also map to custom UI components, so a query about sales data renders as a chart rather than a wall of plain text.
Copy link to headingDocument analysis and summarization
For long documents, you can implement a map-reduce summarization pattern by summarizing chunks and then combining those summaries; legacy map-reduce chain implementations now live in langchain-classic. Source metadata flows alongside the content, so your output can include citations pointing back to the original passages.
The same chunk-then-synthesize pattern shows up across several document workflows:
Long-form summarization: Condensing reports, contracts, or transcripts that exceed context limits into a coherent summary.
Multi-document question answering: Pulling answers from a corpus where the evidence sits in different files.
Structured extraction: Pulling fields like dates, parties, or amounts out of contracts or filings into a typed schema.
Cited summaries: Generating answers with inline source references so reviewers can verify each claim.
Whatever shape your output takes, the underlying flow stays the same.
Copy link to headingAutonomous AI agents
Agent workflows are what LangGraph's graph-based architecture was built for, with multi-step decisions, external API calls, and state that survives across interactions, all mapping onto graph primitives without much custom code on your end. Routing comes from the agent's current state rather than hard-coded if-statements, so one agent definition can handle a range of inputs without rewrites.
The graph model covers chat assistants, LLM agents, RAG systems, and structured output pipelines through the same primitives, so swapping between a deterministic chain and an open-ended agent loop comes down to changing how the edges are wired.
Copy link to headingLangChain vs other AI frameworks
LangChain isn't the only framework in this space, and the right pick depends on what you're building.
Copy link to headingLangChain vs LlamaIndex
LangChain is a general-purpose orchestration framework that covers model interaction, tool use, retrieval, and multi-step workflows. LlamaIndex centers on retrieval-augmented generation and data indexing, with query strategies tuned for searching across document collections. The two libraries overlap on retrieval, but their defaults pull you in different directions.
If your application is mostly question-answering over a corpus of PDFs, internal docs, or knowledge bases, LlamaIndex fits closer to the work. If you're combining retrieval with tool calling, agent loops, and stateful interactions, LangChain maps better. Our LlamaIndex vs LangChain guide goes deeper if you want a side-by-side comparison.
Copy link to headingLangChain vs direct LLM SDKs
Provider SDKs from OpenAI and Anthropic give you the thinnest abstraction over the model. If you're building a single-provider chatbot, doing a one-shot completion call, or running a small script that hits one API, a direct SDK is the simpler choice and you skip the framework overhead entirely.
LangChain starts to pull ahead once you need to swap providers without rewriting your code, compose multi-step retrieval and generation pipelines, manage agent loops that persist state across runs, or get framework-level observability. For thinner use cases, the abstraction adds cost without much in return.
Copy link to headingDeploying LangChain applications on Vercel
Vercel maintains an @ai-sdk/langchain adapter, rewritten for AI SDK 6, that connects LangChain.js, LangGraph.js, and Next.js. It converts AI SDK message types into LangChain's BaseMessage format and turns LangGraph event streams into the AI SDK's streaming response format, so you can run a LangGraph agent in a server-side route handler and stream results to the browser through the useChat hook from @ai-sdk/react. The adapter covers the patterns you'd want from a production agent runtime:
Tool calling with partial input streaming: Tool arguments stream to your UI as the model generates them, so users see calls forming in real time.
Reasoning blocks: Content from providers like Anthropic surfaces alongside the main response.
Human-in-the-loop workflows: LangGraph interrupts pause execution for human approval before continuing.
Step events: Progress signals from each node let you track where your agent is in its run.
The LangChain starter template gives you a working starting point with a basic chain, a chain with a vector store, and RAG using both chains and agents. For long-running agents, Vercel Functions on Fluid compute run up to 800 seconds on Pro and Enterprise, and setting LANGCHAIN_CALLBACKS_BACKGROUND=false in your environment keeps LangSmith traces flushing before the function exits.
Copy link to headingShip reliable LLM applications with LangChain
LangChain gives you a single interface across model providers, composable chains through LCEL, graph-based runtimes for stateful agents in LangGraph, and tracing through LangSmith. The pieces fit together, so you can prototype with one provider, swap to another, and add memory or tool use without rebuilding the rest of your application.
If you're building on Next.js, the AI SDK's LangChain adapter wires LangGraph output into the streaming primitives your UI already speaks, so token streams, tool calls, and intermediate steps render without any custom plumbing on your side. Clone the LangChain starter template to skip the boilerplate, or start a new project and add the pieces you need as you go.
Copy link to headingFrequently asked questions about LangChain
Copy link to headingIs LangChain free to use?
The core LangChain packages are open source and free to use. LangSmith has a free tier for tracing and paid plans for team features or higher volume, and LLM API costs from providers like OpenAI and Anthropic bill separately. You can deploy your app on Vercel's Hobby tier at no cost while you're prototyping.
Copy link to headingWhat programming languages does LangChain support?
LangChain has first-class packages in both Python and JavaScript/TypeScript. The JavaScript version is written in TypeScript and runs anywhere Node.js does, including Vercel Functions and Next.js apps. LangSmith's tracing SDKs also cover a few additional languages for services outside that core pair.
Copy link to headingWhat is the difference between LangChain and LangGraph?
LangChain handles the building blocks like model calls, prompt templates, retrieval, and output parsing, while LangGraph is a separate runtime for stateful, multi-step agents that adds nodes, edges, shared state, checkpointing, cycles, and human-in-the-loop interrupts on top. They solve different layers and run together, with the AI SDK adapter wiring either one into a Next.js app on Vercel. Our LangChain vs LangGraph guide walks through the differences in more detail.
Copy link to headingDo I need machine learning experience to use LangChain?
No ML background is required. If you're comfortable with Python or JavaScript, REST APIs, and the basics of how LLMs behave, you have enough to be productive. The framework hides the model internals, so your day-to-day work is prompts, tools, retrievers, and chains, and the LangChain starter template on Vercel is the fastest way to get started.