Skip to content
Home/Resources/AI & ML/LangChain and LangGraph
AI explained ยท AI & ML

What Is LangChain and LangGraph? What Each Is For, Install Lines From the Docs, a Graph Explained With Runnable Code and When You Need Neither

Younus FardeenBy Younus FardeenUpdated 1 Dec 20266 min read
Short answer

LangChain is an open-source framework for building agents and apps on language models, with integrations for model providers and tools. LangGraph is a lower-level orchestration runtime where you define stateful workflows as graphs of nodes and edges. Its docs say LangGraph does not require LangChain. You can also build simple agents with neither.

On this pageLangChain vs LangGraph: what each is forInstall lines as documented on 1 December 2026A minimal graph, explainedAlternatives, and when you need no frameworkFrequently asked questions

This page is for a developer or student who has seen the names LangChain and LangGraph in job posts and tutorials and wants to know what each does before installing anything. The descriptions, package names and install lines were read in the official documentation on 1 December 2026. The older address langchain-ai.github.io/langgraph now redirects to docs.langchain.com, so tutorials that link to it may be out of date.

The pure-Python example below runs offline with no key and mirrors the graph idea, so you can see state, nodes and edges before using the library. For the agent loop itself, see what is an AI agent; for the wider field, generative AI vs agentic AI.

LangChain vs LangGraph: what each is for

LangChain is the agent framework: abstractions and integrations for models, tools and agent loops. The LangChain overview page describes create_agent as a minimal, highly configurable agent harness, and gives the formula Agent = Model + Harness, where the harness is everything around the model loop: the prompt, the tools and any middleware that shapes behaviour. It lists support for model providers including OpenAI, Anthropic and Google.

LangGraph is the orchestration runtime. Its overview calls it a low-level orchestration framework and runtime for long-running, stateful agents. You define workflows as graphs of shared state, nodes and edges and can mix deterministic steps with model-driven steps in one graph. It focuses on durable execution, streaming and human-in-the-loop, and it does not prescribe prompts or agent architecture.

LangChainLangGraph
LevelHigher: ready agent loop and integrationsLower: you design the control flow
Choose it whenYou want a working agent quickly with your tools and a model providerYou need explicit control over state, branching, pauses for human approval or resuming after failure
Documented extrasTracing and evaluation through the separate LangSmith platformPersistence, human-in-the-loop, memory, streaming
Needs the other?Built on LangGraph for some products, such as Deep AgentsDocs say it does not require LangChain

The docs also describe Deep Agents, an agent harness for planning, subagents, filesystem tools and context management built on LangGraph, and LangSmith for tracing and evaluation. The documentation on 1 December 2026 presents the stack as LangChain agents on top, LangGraph underneath.

Install lines as documented on 1 December 2026

PackageInstall line from the docsNote from the docs
LangChainpip install -U langchainRequires Python 3.10+
Provider integrationpip install -U langchain-openai or pip install -U langchain-anthropicProvider integrations live in separate packages
LangGraphpip install -U langgraphThe docs also show a uv equivalent
LangGraph quickstartpip install -U langgraph langchain langchain-anthropicQuickstart needs a model provider key; set it as an environment variable

Use a virtual environment so versions do not clash. Package names and docs layout have changed before, so confirm against the LangChain install page and the LangGraph overview when you install. Running the library examples needs a provider key, which is why the runnable code on this page does not.

A minimal graph, explained

A graph here is a way to write control flow. Three ideas cover it. State is a shared record that every step reads and updates. A node is a function that takes the state and returns changes to it. An edge says which node runs next, and a conditional edge lets the state decide. The LangGraph overview shows the smallest example, copied here so you can read the pieces:

from langgraph.graph import StateGraph, MessagesState, START, END

def mock_llm(state: MessagesState):
    return {"messages": [{"role": "ai", "content": "hello world"}]}

graph = StateGraph(MessagesState)
graph.add_node(mock_llm)
graph.add_edge(START, "mock_llm")
graph.add_edge("mock_llm", END)
graph = graph.compile()
graph.invoke({"messages": [{"role": "user", "content": "hi!"}]})

The function named in add_node stands in for a model call. START and END mark the entry and exit. After compile, calling invoke runs the graph from START to END with your input as the initial state. The offline analogue below does the same job in plain Python, with a conditional edge that picks the next node from the state:

def classify(state):
    state["label"] = "refund" if "refund" in state["text"] else "other"
    return state

def refund_flow(state):
    state["reply"] = "Checking refund policy"
    return state

def other_flow(state):
    state["reply"] = "Routing to a human"
    return state

def review(state):
    state["approved"] = len(state["reply"]) < 40
    return state

nodes = {"classify": classify, "refund": refund_flow, "other": other_flow, "review": review}
edges = {
    "classify": lambda s: s["label"],        # conditional edge: the state picks the next node
    "refund": lambda s: "review",
    "other": lambda s: "review",
    "review": lambda s: "END",
}

def run(state, start="classify"):
    node = start
    while node != "END":
        state = nodes[node](state)
        print(f"ran {node:9s} state={state}")
        node = edges[node](state)
    return state

run({"text": "I want a refund"})
ran classify  state={'text': 'I want a refund', 'label': 'refund'}
ran refund    state={'text': 'I want a refund', 'label': 'refund', 'reply': 'Checking refund policy'}
ran review    state={'text': 'I want a refund', 'label': 'refund', 'reply': 'Checking refund policy', 'approved': True}

What the library adds on top of this loop is what is hard to write yourself: saving state between steps so a run can resume after a failure, pausing for a person to approve, streaming partial results and tracing each step. If your program has none of those needs, the plain loop is enough.

Alternatives, and when you need no framework

Other frameworks and kits for agents and retrieval include LlamaIndex, CrewAI, Haystack, AutoGen and the OpenAI Agents SDK. Their documentation sites were reachable on 1 December 2026; this page does not compare them, so read each one's own docs before choosing.

  • A single model call with a good prompt needs only the provider's own SDK.
  • A fixed pipeline such as extract, validate, store is a normal function with tests. A graph adds nothing.
  • A small agent with two or three tools can be the twenty-line loop in generative AI vs agentic AI.
  • Learning: write the loop by hand once. You will understand what any framework hides, and debugging gets easier.

Adopt LangGraph or a similar runtime when you need saved state, human approval steps, long-running jobs or step-by-step tracing. For free tools to try agents, see free agentic AI tools; for how tools are exposed to models in a standard way, see what is MCP.

Frequently asked questions

What is LangChain used for?

LangChain is used to build applications and agents on language models. Its docs describe create_agent, a configurable agent harness that combines a model, tools, a prompt and middleware, plus integrations with many model providers. Teams use it to avoid writing provider-specific code for each model and tool.

What is LangGraph?

LangGraph is a low-level orchestration framework and runtime for stateful, long-running agents. You describe a workflow as a graph of shared state, nodes and edges and can mix fixed steps with model-driven steps. Its documented strengths are durable execution, streaming, memory and human-in-the-loop pauses.

What is the difference between LangChain and LangGraph?

LangChain gives you a higher-level agent with ready integrations. LangGraph gives you lower-level control over state and flow: branches, loops, pauses and resuming. The docs say you can use LangGraph without LangChain, and LangChain's newer agent features are built on LangGraph.

Do I need LangChain to build an AI agent?

No. An agent is a loop that asks a model for an action, runs a tool and repeats until a stop condition. You can write it with a provider's SDK and plain Python. Use a framework when you need saved state, retries, tracing or many integrations.

How do I install LangChain and LangGraph?

As documented on 1 December 2026: pip install -U langchain for LangChain, which requires Python 3.10 or newer, and pip install -U langgraph for LangGraph. Provider integrations are separate packages such as langchain-openai or langchain-anthropic. Check the official install pages, since package layout can change.

Is LangChain still worth learning in 2027?

Learn the ideas first: tools, state, loops, retrieval and tracing. They carry over to any framework. LangChain and LangGraph appear in job posts, so a small project with one of them is reasonable, but the vendor docs change often, so build from the current official pages.

Continue learning

AI explained

What is an AI agent?

The agent loop, agent vs chatbot, real agents to try and a demo

8 min read
AI explained

Generative AI vs agentic AI

Generative vs agentic AI: table, runnable agent loop, when not to use agents

5 min read
AI explained

What is MCP?

MCP in plain terms: servers, tools, how it differs from plugins, and risks.

10 min read