What it is

LangChain is an open-source framework for building LLM applications and agents, available for Python and JavaScript/TypeScript. The problem it addresses: a model by itself only takes text in and puts text out, while a real application also has to call tools, reach data, manage conversations and handle retries. Writing all of that from scratch every time is tedious and error-prone.

Its current philosophy fits in one line: Agent = Model + Harness. The harness is everything around the model loop: the prompt, the tools and any middleware that shapes behaviour. LangChain provides create_agent, a minimal and highly configurable entry point, so you start from primitives and compose exactly the agent you need. It supports OpenAI, Anthropic, Google and many other providers.

LangChain is now a family of products:

  • LangChain: the agent framework, with abstractions and integrations for models, tools and agent loops;
  • LangGraph: the low-level orchestration runtime, with durable execution, streaming, human-in-the-loop and persistence;
  • Deep Agents: a batteries-included agent on LangGraph with planning, sub-agents, a virtual filesystem and context compression;
  • LangSmith: a platform for tracing, debugging, evaluating and deploying agents built with any framework.

Key features

Standard model interface. One interface for chat models, embeddings and more across providers. Switching models takes minimal code changes, so your app is not tied to one vendor.

Highly configurable agents. Start with create_agent, pass a model, tools and a system prompt, and you have an agent that calls tools on its own. Add capabilities step by step through middleware.

Middleware. Middleware hooks into every step of agent execution. Uses listed in the docs include tracking behaviour with logging, analytics and debugging; transforming prompts, selecting tools and formatting output; adding retries, model fallbacks and early termination; and applying rate limits, guardrails and PII detection. Built-in middleware covers common needs such as summarisation and human approval.

Built on LangGraph. LangChain agents run on LangGraph, so they inherit durable execution, human-in-the-loop support and persistence.

Integrations. Packages for many model providers, vector stores, document loaders and tools, installed as needed.

Debugging with LangSmith. See traces, tool calls, state transitions and latency in one place to find failures and evaluate quality.

How it works

The agent loop. An agent from create_agent follows the classic reason-and-act loop. The model looks at the current messages and decides whether to answer or call a tool. If it calls a tool, the framework runs it, appends the result as a new message and hands control back to the model, repeating until the model gives a final answer. Tools are usually plain Python functions, and each function’s docstring becomes the tool description the model sees.

Middleware hooks. Middleware attaches at points in that loop, such as before and after model calls or tool calls. Combining middleware lets you add summarisation, retries, rate limiting or approvals without touching the core logic.

Graph orchestration in LangGraph. LangGraph is the lower-level framework and describes flows as state graphs: define a state schema, write each step as a node function, connect nodes with edges and compile the graph. A key strength is mixing deterministic steps and LLM-driven steps in one graph, using fixed logic where you need reliability and auditability and the model where you need flexibility. LangGraph credits Google’s Pregel and Apache Beam as inspirations.

How to use it

Install (Python with an Anthropic model as the example):

pip install -U langchain "langchain[anthropic]"

Create an agent with a tool:

from langchain.agents import create_agent

def get_weather(city: str) -> str:
    """Get weather for a given city."""
    return f"It's sunny in {city}."

agent = create_agent(
    model="claude-sonnet-4-6",
    tools=[get_weather],
    system_prompt="You are a helpful assistant",
)

result = agent.invoke(
    {"messages": [{"role": "user", "content": "What's the weather in Shanghai?"}]}
)
print(result["messages"][-1].content_blocks)

To use another provider, install its integration package and change model.

For finer control over the flow, use LangGraph directly:

pip install -U langgraph

Define nodes and edges with StateGraph, compile and invoke. The docs suggest starting with Deep Agents for a batteries-included agent, using LangChain’s create_agent for a highly customisable harness, and reaching for LangGraph when you need to combine deterministic workflows with agentic steps.

Use cases

  • Tool-using agents: let a model query databases, call internal APIs and run calculations.
  • RAG question answering: combine document loaders and vector stores to answer from private material.
  • Long-running, stateful automation: orchestrate approvals or support-ticket handling with persistence and human checkpoints in LangGraph.
  • Multi-model apps: switch between providers or fall back through the standard interface.
  • Agent quality evaluation: track production behaviour with LangSmith and keep improving.

FAQ

Should I use LangChain or LangGraph? Use LangChain when you are starting out with agents and want higher-level abstractions. Use LangGraph when you need fine control over the flow or want to mix deterministic logic with agent steps. They work together; LangChain agents already run on LangGraph.

Does LangGraph require LangChain? No. The docs say LangGraph can be used on its own, though the documentation often uses LangChain components for models and tools.

Is LangSmith required? No. It is an optional debugging and evaluation platform, but it helps a lot when investigating agent behaviour. Set LANGSMITH_TRACING=true and your API key to turn on tracing.

Why does code from older tutorials fail? LangChain moves quickly and older APIs change. Follow the latest examples in the official docs.