LangGraph Overview
🎯 Introduction
When an AI application handles related tasks such as generating an article, reviewing it, and revising it when needed, relying on model decisions alone makes it difficult to enforce business requirements. LangGraph lets developers control execution order, branches, and loops, with support for state management, pausing, and resuming. This article introduces its core concepts and execution model, explains how it differs from LangChain, and helps you decide when to use it.
🧱 Why Use LangGraph?
Suppose we are building a writing assistant. The user provides a topic, and the assistant generates an article and reviews it against writing guidelines. If it finds issues, it must revise the article and review it again.
With the LangChain agents covered earlier, we could provide writing, review, and revision tools and let the model choose how to call them. However, when every article must be reviewed before delivery, we want the program to enforce these steps rather than relying solely on prompts.
The following diagram compares these approaches:
In a predefined workflow, a successful generation step always leads to review. An article that passes is delivered; otherwise, it is revised and reviewed again. In practice, you can also cap revisions to prevent an endless loop. Developers define the rules, and execution results determine which path runs.
LangGraph is a framework for building and running stateful workflows and agents. It coordinates task execution and manages shared data such as article text and review feedback.
Why Not Use JavaScript Directly?
A simple writing and review process can use JavaScript functions, if, and while. It does not necessarily need LangGraph.
But if the assistant also needs human review, pauses, and recovery after a service restart, you must manage execution as well as implement business logic.
| Requirement | Plain JavaScript | LangGraph |
|---|---|---|
| Execution order and branching | Functions, conditionals, and loops | Define connections between tasks |
| Data shared across steps | Manage data passing and updates yourself | Centralized state and update rules |
| Wait for human review | Record the waiting state and handle continuation yourself | Built-in interrupt and resume mechanisms |
| Resume after a service restart | Save progress and implement recovery yourself | Configure persistent checkpoints and resume from saved progress |
For example, after AI review, an article may need user approval before publication. LangGraph can pause the workflow and save its state and progress in a checkpoint. If checkpoint storage survives restarts, the task can resume after approval even if the service restarted while waiting, without generating the article again.
LangGraph therefore provides a consistent workflow execution model that reduces the state management, pause, and resume logic you need to implement for complex tasks.
🧱 Core Concepts
LangGraph uses a graph to describe how tasks execute. This is a set of nodes and connections defined in the program, rather than a chart displayed on a page.
For article generation and review:
| Concept | Purpose | Article example |
|---|---|---|
| State | Holds data shared during execution | Topic, article text, and review feedback |
| Node | Performs a specific task | Generate or review an article |
| Edge | Defines execution relationships between nodes | Review after generation |
| Graph | Organizes state, nodes, and edges | The complete article workflow |
A node is typically a JavaScript function that reads the current state, performs a task, and returns updates. LangGraph merges these updates according to the state rules, then runs subsequent nodes according to the graph connections.
State changes during generation and review look like this:
| Stage | Topic | Article text | Review feedback |
|---|---|---|---|
| Task starts | LangGraph | — | — |
| After generation | LangGraph | Initial draft | — |
| After review | LangGraph | Initial draft | Missing an example |
The writing node only returns article text, and the review node only returns feedback. Fields they do not update remain available. Nodes therefore do not need to manually pass each function's return value through the entire chain.
⚖️ How LangChain and LangGraph Relate
In the previous course, we used createAgent() to create agents whose model requests, tool execution, and loops were handled by the framework. These execution capabilities are built on LangGraph.
| Aspect | LangChain agent | LangGraph |
|---|---|---|
| Execution path | Framework-provided agent loop | Developer-defined nodes and connections |
| Main use | Quickly build assistants that call tools | Customize workflows and execution control |
| State | Built-in agent state, with extensions | State structure defined for your application |
| Setup effort | Lower | Requires workflow and state design |
The two can work together. You can orchestrate writing and review with LangGraph and call a LangChain agent inside a review node, letting it choose when to query the guidelines tool.
💡 When Should You Use LangGraph?
| Scenario | Suggested approach |
|---|---|
| Basic model questions and answers | Call a model API or AI SDK directly |
| Customer support assistant that chooses its own tools | Start with a LangChain agent |
| Simple article generation, review, and revision | Use JavaScript directly |
| AI tasks requiring multiple steps, human review, or interrupt and resume support | Use LangGraph |
The rest of this course focuses on article generation and review. We will first simulate writing and review with local functions so execution is easy to inspect, then integrate real models and agents.
❓ Questions and Answers
Q1: Does LangGraph require a large language model?
No. Nodes can run ordinary business functions, access databases, or call models. The framework primarily coordinates task execution.
🧪 Exercise
Design an article translation workflow with translation, terminology checking, revision, and delivery. Specify the state to save, each node's responsibilities, and which node runs when the check passes or fails.
🎉 Congratulations! You now understand LangGraph's purpose and basic building blocks.
