LangGraph Overview

Understand LangGraph's core concepts, execution model, and use cases.

🎯 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:

Agent chooses the path
User requests an article
Model selects tools
WriteReviewRevise
The model decides the call order
Model returns a response
Program controls the workflow
User requests an article
Write article
Review articlePassFailDeliver articleRevise article
An agent lets the model choose the path. A workflow lets the program enforce key steps.

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.

RequirementPlain JavaScriptLangGraph
Execution order and branchingFunctions, conditionals, and loopsDefine connections between tasks
Data shared across stepsManage data passing and updates yourselfCentralized state and update rules
Wait for human reviewRecord the waiting state and handle continuation yourselfBuilt-in interrupt and resume mechanisms
Resume after a service restartSave progress and implement recovery yourselfConfigure 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:

ConceptPurposeArticle example
StateHolds data shared during executionTopic, article text, and review feedback
NodePerforms a specific taskGenerate or review an article
EdgeDefines execution relationships between nodesReview after generation
GraphOrganizes state, nodes, and edgesThe 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:

StageTopicArticle textReview feedback
Task startsLangGraph——
After generationLangGraphInitial draft—
After reviewLangGraphInitial draftMissing 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.

AspectLangChain agentLangGraph
Execution pathFramework-provided agent loopDeveloper-defined nodes and connections
Main useQuickly build assistants that call toolsCustomize workflows and execution control
StateBuilt-in agent state, with extensionsState structure defined for your application
Setup effortLowerRequires 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?

ScenarioSuggested approach
Basic model questions and answersCall a model API or AI SDK directly
Customer support assistant that chooses its own toolsStart with a LangChain agent
Simple article generation, review, and revisionUse JavaScript directly
AI tasks requiring multiple steps, human review, or interrupt and resume supportUse 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.