Guilds AI / AI Blog

,

What Is LangGraph? How It Works, Features and Use Cases

A directed network of workflow nodes with branching routes and a feedback loop on a dark background.

LangGraph is an open-source orchestration framework and runtime for building stateful AI agents and workflows. Our LangChain MIT license guide explains the licensing distinction between open-source frameworks and commercial services. Developed by LangChain, it lets developers express a multi-step application as a graph of processing steps and transitions, with shared state carrying information between those steps. For a comparison with visual integration platforms and durable workflow engines, see our guide to AI workflow orchestration tools. For frameworks that offer different approaches to workflow state and recovery, see our comparison of LangGraph alternatives.

Unlike an application that simply sends a prompt to a language model and returns its answer, a LangGraph workflow can branch, repeat a search, call tools, pause for human input, and resume from saved state when persistence is configured. Its main value is explicit control over how a workflow runs, not a new language model. For implementation details, see our LangChain memory guide covering checkpointers and stores. For a comparison with role-based agent teams and legacy messaging systems, see our LangGraph vs CrewAI vs AutoGen guide.

What is LangGraph?

LangGraph provides the execution layer for applications whose behavior cannot easily be represented as one model call or a short fixed sequence. Our Haystack vs. LangChain comparison explains how LangGraph and Haystack differ in pipeline and agent orchestration. A graph can combine conventional Python functions with model-driven decisions, and it can support a single agent or several coordinated components. It does not require every step to use AI. For a role-based alternative that separates agent teams from workflow control, see our CrewAI framework guide. For teams considering a different framework ecosystem, our LangChain alternatives guide compares LangGraph with other ways to implement agent and retrieval workflows. Our introduction to AI orchestration explains the broader role of this execution layer.

The graph describes the control flow of an application. It is not necessarily a knowledge graph, which represents facts and relationships between entities. A LangGraph application can use a knowledge graph as a data source, but that is a separate design choice.

How LangGraph works: state, nodes, and edges

Building blockPurposeExample
StateShared information available to relevant nodes.Request, extracted fields, search results, or decision status.
NodeA function or processing step that reads state and returns updates.Classify a message, retrieve a document, or validate a result.
EdgeA transition that determines what executes next.Move from validation to the review step.
Conditional edgeA transition selected according to a routing function.Send an ambiguous request to a reviewer; otherwise continue.
START and ENDSpecial graph entry and termination markers.Begin processing or finish the current run.

A node usually returns a partial state update rather than rewriting the entire state. State fields have update behavior: by default a new value replaces the old value, while a configured reducer can combine updates, such as appending entries to a list. Reducers matter when several nodes update the same field in parallel.

START โ†’ Classify request
โ†“ Conditional edge โ†“
Routine
General support queue
Review
Authorized reviewer
โ†“
END
A simplified graph that selects a branch based on shared state. The routing logic can be deterministic rather than model-driven.

Graphs can also contain cycles. For example, a retrieval node can return to a query-planning node when the current evidence is insufficient. A cycle should have a stopping condition, a maximum execution budget, and an explicit response when the task remains incomplete. See our agentic workflows guide for more examples of adaptive control flow. For repeatable read-only nodes, see our AI agent caching best practices to distinguish safe result reuse from workflow checkpointing.

Key LangGraph features

State management and conditional execution

A typed state schema makes the information that passes through a workflow explicit. Nodes can perform ordinary application logic, invoke a language model, or call an authorized tool. A routing function can inspect the current state to choose the next node. This makes it possible to keep business rules deterministic even when some inputs come from probabilistic model predictions.

Checkpointing and durable execution

LangGraph supports checkpointers that record graph state for a particular thread. With appropriate persistent storage, a workflow can resume after a pause or failure. In-memory checkpoint storage is useful for development, but it does not survive a process restart. A production application needs a suitable persistent checkpointer, a stable thread identifier, and appropriate retention and access controls.

Checkpointing is not the same as a guarantee that an external operation occurs exactly once. If a node changes an outside system and later needs to run again, the application must use appropriate idempotency, transaction reconciliation, and authorization checks.

Human-in-the-loop interruptions

A node can use an interrupt to suspend execution and request input from a person. The application can then resume the workflow using the same thread and the reviewer’s response. The graph should validate who approved the action, what was approved, and whether approval is still valid. The AI workflow automation governance guide covers these operational controls. Code before an interrupt may execute again when the node resumes, so avoid placing unprotected external side effects before the pause.

Streaming and observability

Applications can stream model output or graph execution events to a user interface or monitoring system. A trace can help developers understand which node ran, how state changed, and where an error occurred. Configure monitoring deliberately; graph state and traces can contain private messages, business records, or other sensitive information.

LangGraph and LangChain: how they fit together

TechnologyPrimary responsibility
LangChainHigher-level model and tool integrations and agent abstractions.
LangGraphLow-level graph orchestration, state, routing, persistence, and interruptions.
LangSmithSeparate tooling for observability, evaluation, and deployment capabilities.

LangGraph can run independently of LangChain’s higher-level agent abstractions. Developers can use both in the same application: a LangChain model or tool integration may run inside a LangGraph node. A higher-level agent abstraction is often the simpler starting point; move to explicit graph construction when the application requires finer control over execution.

Build a simple LangGraph workflow in Python

This small Python example routes a fictional support request based on a keyword. It demonstrates the Graph API without requiring an LLM provider or API key. It is deliberately not a production classifier, and the review branch returns a routing message rather than actually approving a refund. For a general introduction to tool-calling agents, see our agentic AI tutorial.

Install the LangGraph package in a supported Python environment: If you also need the high-level LangChain library, our LangChain installation guide explains Python environments and dependency checks.

pip install -U langgraph

Define the state, create the nodes, register the conditional transition, and compile the graph before invoking it.

from typing import TypedDict
from langgraph.graph import StateGraph, START, END

class State(TypedDict):
    request: str
    category: str
    response: str

def classify(state: State):
    text = state['request'].lower()
    category = 'review' if 'refund' in text else 'routine'
    return {'category': category}

def route(state: State):
    return state['category']

def review(state: State):
    return {'response': 'Send to an authorized reviewer.'}

def routine(state: State):
    return {'response': 'Send to the general support queue.'}

builder = StateGraph(State)
builder.add_node('classify', classify)
builder.add_node('review', review)
builder.add_node('routine', routine)
builder.add_edge(START, 'classify')
builder.add_conditional_edges(
    'classify', route,
    {'review': 'review', 'routine': 'routine'}
)
builder.add_edge('review', END)
builder.add_edge('routine', END)

graph = builder.compile()
result = graph.invoke({
    'request': 'Refund request',
    'category': '',
    'response': ''
})
print(result['response'])

The expected output for the example input is:

Send to an authorized reviewer.

Changing the request to an ordinary order-status inquiry should select the general support queue. The example uses the Graph API documented by LangGraph. Five isolated checks of the Python classification, routing, and response functions passed. The LangGraph package was not available in the local test environment, so the complete graph invocation was not executed. No live model request was made.

To add an LLM, replace the classification function with a model adapter that returns one of the permitted categories. Validate its output before routing and keep the final permission check in application code. Add tests for malformed outputs, missing state, ambiguous requests, and rejected actions.

LangGraph use cases

Use caseWhy a graph may help
Research assistantRepeat retrieval or clarify a question until enough evidence is available.
Customer supportRoute inquiries to different authorized tools and escalate exceptions.
Document processingSeparate extraction, verification, and review into testable stages.
Software developmentCoordinate planning, code changes, test results, and approval.
Long-running workflowsSave progress and resume after an authorized external input.

Retrieval-augmented generation is a common example of a workload that may benefit from branching and controlled repetition. Our guide to building RAG agents with LLMs explains how additional retrieval rounds can improve evidence coverage when the initial search is insufficient.

When should you use LangGraph?

LangGraph is worth considering when you need explicit branches, loops, reusable subgraphs, durable state, or human review at particular stages. It can make the workflow easier to inspect and test by isolating decisions from execution. However, the developer remains responsible for defining sensible state boundaries, selecting tools, validating outcomes, and implementing security.

  • Use a direct model call for a simple transformation or a one-step response.
  • Use an ordinary function pipeline when the sequence is fixed and short.
  • Use a higher-level agent abstraction when a standard tool-calling loop is sufficient.
  • Consider LangGraph when the application requires explicit state, conditional execution, recoverable long-running work, or coordinated review steps.

Adding graph orchestration does not automatically improve answer quality or throughput. Compare it with a simpler baseline, measure task completion and failure rates, and test termination, persistence, and recovery independently. Our agentic design patterns guide describes the building blocks that can be expressed within these workflows.

Frequently asked questions

Is LangGraph a language model?

No. LangGraph is an orchestration framework. A graph can call a language model from a node, but the framework itself does not generate language model predictions.

Is LangGraph open source?

Yes. The core LangGraph library is open source. Managed deployment and related services can have separate commercial terms and costs.

Do you need LangChain to use LangGraph?

You do not need to use LangChain’s agent abstractions. LangGraph can coordinate ordinary functions and other integrations, although many examples use LangChain components.

Can LangGraph run without an LLM?

Yes. A graph can execute deterministic functions and conditional transitions without calling a language model.

Does LangGraph automatically remember everything?

No. State and persistence depend on how the application is designed. Checkpointers track thread-scoped state when configured; cross-thread memory requires a suitable store or another application-managed persistence approach.