What Is LangChain? When to Use It and When to Write Your Own Code
A practical guide to LangChain as it stands in late 2026: what the framework does, what moved to langchain-classic in 1.0, how create_agent and checkpointers work, and how to decide between LangChain, LangGraph and a small amount of your own code.

This guide is for developers who keep hearing about LangChain and want to know two things: what it is today, and whether to use it or write the orchestration code yourself. It covers the 1.x line, checked against the official documentation on October 30, 2026. It has no benchmarks and no project stories; where a choice depends on your workload, it gives a rule of thumb and says so.
Key takeaways
- LangChain 1.x is mainly a standard model interface plus
create_agent, a small agent harness that runs on LangGraph. - Legacy chains, memory classes and
AgentExecutormoved tolangchain-classic. Memory is now a checkpointer keyed by athread_id. - Use LangChain when you need tools, multi-turn state, streaming or provider portability. For one call or a fixed pipeline, plain code is simpler.
This is part 1 of the LLM & LangChain Fundamentals series.
What LangChain is today
LangChain is an open-source Python and JavaScript framework for building applications and agents on top of large language models. In the 1.x line it is mostly two things. The first is a standard interface for talking to models from different providers. The second is a small, configurable agent harness called create_agent that runs a model in a loop with your tools. The overview page says LangChain's agents are built on top of LangGraph, which gives them persistence, streaming and human-in-the-loop support.
The overview page sums the design up as "Agent = Model + Harness". The model is whichever chat model you pick. The harness is create_agent: it sends the conversation to the model, runs any tool the model asks for, feeds the result back, and stops when the model gives a final answer.
Around that core you get:
- A standard model interface.
init_chat_modeltakes a model name, or a"provider:model"string such as"openai:gpt-6-luna". It returns a chat model with the sameinvoke,streamandbatchmethods whatever the provider. Timeouts, retries (max_retries, default 6), temperature andmax_tokensare ordinary parameters. - Tools. Plain Python functions with a docstring and type hints can be passed straight to
create_agent. - Middleware. Hooks such as
before_model,after_model,wrap_model_callandwrap_tool_calllet you change what happens around each model or tool call. Built-in middleware covers jobs like summarising long conversations. - Integrations. Provider packages (
langchain-openai,langchain-anthropicand many more) for models, embeddings, vector stores and caches.
LangGraph sits one level lower. If you need an explicit graph of steps, branches and loops, you write it in LangGraph directly. If a model-plus-tools loop is enough, create_agent builds that graph for you.
What changed in LangChain 1.0
If you learned LangChain from older tutorials, a lot of what you saw has moved. According to the v1 migration guide:
- Legacy chains (
LLMChain,ConversationChainand friends), the old retrievers, the indexing API, thehubmodule and thelangchain-communityre-exports now live in a separate package,langchain-classic. - The legacy memory classes went with them. Short-term memory is now LangGraph state saved by a checkpointer and keyed by a
thread_id. create_react_agentfromlanggraph.prebuiltis deprecated in favour offrom langchain.agents import create_agent, and itsprompt=argument is nowsystem_prompt=.- Pre-model and post-model hooks are now middleware, with
before_modelandafter_modelmethods. - Every LangChain package now needs Python 3.10 or newer.
So code that imports ConversationTokenBufferMemory, ConversationChain or AgentExecutor from langchain is old code. It can keep running on langchain-classic, but new projects are better started on the current API.
A minimal LangChain agent with memory
Here is the shape of a current agent, close to the examples in the docs. Install the package with the provider extra you need (for example pip install -U langchain "langchain[openai]"), then save this as agent_memory.py:
import os
from langchain.agents import create_agent
from langgraph.checkpoint.memory import InMemorySaver
def get_order_status(order_id: str) -> str:
"""Look up the shipping status of one order by its ID."""
# Replace with a real lookup (database, ERP, Salesforce).
return f"Order {order_id} has shipped."
agent = create_agent(
model=os.getenv("AGENT_MODEL", "openai:gpt-6-luna"),
tools=[get_order_status],
system_prompt="You are a support assistant. Use tools for order data; never guess.",
checkpointer=InMemorySaver(),
)
if __name__ == "__main__":
config = {"configurable": {"thread_id": "customer-42"}}
result = agent.invoke(
{"messages": [{"role": "user", "content": "Where is order A-1001?"}]},
config,
)
print(result["messages"][-1].text)
Checked against langchain@1.4.7, langchain-openai@1.7.3 and langgraph@1.2.18, 2026-10-30.
Set the API key before you build the agent
The example was run on Python 3.13 against a local stand-in for the OpenAI API, with a placeholder key. create_agent builds the OpenAI client straight away, so OPENAI_API_KEY must be set even before the first call.
On the date above, OpenAI's models page calls gpt-6-luna its most efficient model for focused, high-volume tasks. Model ids change often, so check the provider's models page and set AGENT_MODEL (for example to anthropic:claude-sonnet-5-5 with langchain[anthropic] installed) instead of editing code.
Three things to notice:
- The tool is a normal function. Its docstring becomes the description the model sees.
- The checkpointer stores the conversation. The
thread_iddecides which conversation you are continuing, so a secondinvokewith the samethread_idremembers the first. InMemorySaveris for development only. The memory guide switches toPostgresSaverfromlanggraph-checkpoint-postgresfor production. The last part of this series, best practices for deploying LangChain apps to production, covers that and the other production concerns.
The last line prints .text, which joins the reply's text blocks into one string. In the test run, langchain-openai called OpenAI's Responses API for this model, and .content came back as a list of blocks instead of a plain string.
If you want to see what is happening inside, set LANGSMITH_TRACING=true and LANGSMITH_API_KEY in the environment. Every model call and tool call, with its inputs and outputs, then shows up as a trace in LangSmith.
What you would have to write yourself
The honest comparison is not "LangChain versus one API call". One API call is always simpler without a framework. The comparison is LangChain versus everything an agent needs once it leaves a notebook:
- The tool loop. Parse the model's tool calls, run the functions, send results back with the right message types, stop after a step limit.
- Conversation state. Store messages per user or session, load them on the next request, trim or summarise them before they outgrow the context window.
- Streaming. Send tokens and tool progress to the client as they arrive instead of after the whole run.
- Provider differences. Each SDK has its own message format, tool-call format and error types.
- Tracing. Some way to see the exact prompt, tool arguments and output of a failing run.
None of these is hard on its own. Writing them all, testing them and keeping them current as providers change their APIs is where the time goes. That is the work LangChain and LangGraph take off your plate. If you want to see what the loop looks like without a framework, building AI agents from scratch walks through it in plain Python.
When to use LangChain
A rule of thumb: reach for LangChain when two or more of these are true.
- The model needs to call tools and decide what to do next, not just answer once.
- Conversations span several turns and have to survive restarts or run on more than one server.
- You want to try more than one model provider, or keep the option to switch.
- You need streaming, human approval steps, or long-running work that can resume.
- You want tracing and evaluation from day one without wiring them yourself.
In those cases the framework replaces code you would otherwise write and maintain, and create_agent is a small enough surface that you can still read what it does.
When to write your own code
Skip the framework when the job is narrow:
- One call, one answer. Classify an email, summarise a document, extract fields into JSON. The provider's SDK and a schema for structured output are enough.
- A fixed pipeline. If the steps never change (fetch, prompt, validate, save), a few functions are clearer than any abstraction.
- An existing codebase with strong conventions. If you already have your own retry, logging and state handling, adding a second set can make things harder to follow.
- A team that will not learn the framework. A dependency nobody understands is a liability when it breaks.
There is also a middle path. Use init_chat_model and LangSmith tracing even in a hand-written pipeline, and adopt create_agent or LangGraph only when the logic really becomes an agent. You can also expose existing functions as tools without restructuring them.
LangChain, LangGraph or neither
| Option | What it gives you | Trade-off | Use it when |
|---|---|---|---|
Provider SDK or init_chat_model |
One model call with structured output | You write any loop, state and retries yourself | A single call or a fixed pipeline |
LangChain create_agent |
A model-plus-tools loop, middleware, checkpointer memory | One more dependency to pin and upgrade | The model picks tools and keeps state across turns |
| LangGraph directly | An explicit graph with branches, parallel steps and several agents | More code than create_agent |
You need to control every step |
For retrieval-heavy document search as the main job, compare LangChain with a retrieval-focused library first. The next part of the series, LangChain vs LlamaIndex vs a vanilla stack, goes through that choice.
Whatever you pick, pin your package versions and read the release notes before upgrading. The 1.0 move to langchain-classic is a good example of why: tutorials from a year ago no longer match the current imports.
Common mistakes to avoid
- Copying pre-1.0 tutorials. If a snippet imports
LLMChain,ConversationChain,AgentExecutoror a memory class fromlangchain, look for the current equivalent in the docs before using it. - Keeping memory in a global variable. In a web server that can leak one user's conversation into another's. Use a checkpointer and a per-user
thread_id. - Skipping timeouts. Set
timeoutandmax_retrieson the model so a slow provider does not hang a request forever. - Debugging without traces. Turn on tracing before the first bug, not after.
- Treating the framework as the product. The value is in your tools, prompts and data. Keep those in plain, testable functions so you could move them if you ever had to.
Frequently asked questions
What is LangChain used for?
Building applications on top of language models: agents that call tools, chat assistants with memory, retrieval over your documents, and pipelines that work with more than one model provider. The core pieces are a standard model interface and the create_agent harness, which runs on LangGraph.
Is LangChain still relevant in 2026?
Yes, but it looks different from older tutorials. LangChain 1.x is a smaller library centred on create_agent, middleware and the standard model interface, with legacy chains and memory moved to langchain-classic. Check the version a tutorial was written for before copying it.
What is the difference between LangChain and LangGraph?
LangGraph is the lower-level runtime for stateful, multi-step workflows: graphs, persistence, streaming and human-in-the-loop. LangChain's agents are built on top of it. Use create_agent when a model-plus-tools loop is enough, and LangGraph directly when you need to control every step.
Where did ConversationChain and AgentExecutor go?
They moved to the langchain-classic package in LangChain 1.0. The replacement for agents is create_agent from langchain.agents, and the replacement for memory classes is a LangGraph checkpointer with a thread_id.
Does LangChain add latency?
Any layer adds some overhead, but the model call usually takes most of the time of a request. Don't trust a general number from anyone; trace your own requests in LangSmith or your logging and see where the time goes.
Sources
Verified against the sources below on October 30, 2026. Products and docs change often: check the linked sources if something looks different.
All 14 parts in this series
- Part 01What Is LangChain? When to Use It and When to Write Your Own Code
- Part 02LangChain vs. LlamaIndex vs. Vanilla: The Builder's Stack Selection Matrix
- Part 03Structured JSON Output from LLMs: Schema Injection, Pydantic and Retry Loops
- Part 04Building Your First LLM Chain: A Developer's Guide to Sequential Logic
- Part 05Building Your First RAG Pipeline: A Developer’s Guide to Context-Aware AI
- Part 06Building Robust RAG Pipelines: A Deep Dive into LangChain Document Loaders
- Part 07Stop Overthinking Vector Databases: A Builder’s Decision Framework
- Part 08Building Long-Term Memory: Setting Up Vector Databases for Semantic Search in LangChain
- Part 09From Chatbot to Agent: The Engineer's Guide to LLM Memory Systems
- Part 10Building State: A Deep Dive into LangChain Memory for Conversational AI
- Part 11Beyond Built-ins: Architecting Custom Tools in LangChain
- Part 12Unmasking the Black Box: Mastering LangChain Callbacks for Debugging
- Part 13Architecting Autonomous Agents: A Builder’s Guide to Complex Workflows
- Part 14Best Practices for Deploying LangChain Apps to Production
AI Automation Engineer & Salesforce Developer
Salesforce developer since June 2018. I build AI agents, n8n workflows and Salesforce integrations, and write up what holds up in real use.



Comments
Loading comments...