Generative AIby Dhruv Narang

Same Job, Two Ways

Take the blog post job again: write it, review it, show it. Let us build it as a chain, and then as a graph.

A CHAIN: ONE WAY ONLYWriteReviewShowno way backA GRAPH: IT CAN GO BACKWriteReviewShowneeds a fix: go back
In a chain
write, then review, then show. One pass. If the review fails, there is nowhere to go.
In a graph
write, then review. If the review fails, an arrow leads back to write. If it passes, we show the result.

Three Things a Chain Cannot Do

The chain works for a straight line. It fails the moment the job needs more.

The job needs…A chainA graph
Another try after a mistakecannot go backan edge can lead back to an earlier step
Shared notes between stepseach step only gets the output of the one beforeone shared state that every step reads and writes
Waiting for a humancannot stop in the middlethe graph can pause, and continue later with the saved state

Head to Head

The same comparison, one row at a time.

LangChain chainLangGraph graph
Shapea line that moves forwardany shape, with loops allowed
Next stepfixed by the pipe |chosen by edges, including conditions
Data between stepsthe output of the last stepone shared state
Memory across messagesyou add it by handbuilt in: the graph saves its state (a checkpointer)
Human approvalhard to addbuilt in: interrupt() pauses the graph

Which One Should I Use?

A graph is not always better. It is more work, so use it only when you need it.

Use a chain when
The steps are always in the same order.It is a single question and a single answer, like simple RAG or a summary.Nobody needs to approve anything in the middle.It finishes in one pass.
Use LangGraph when
The work must be checked and repeated.The model must keep choosing tools until it is done.A person must approve a risky step.Several specialised steps work as a team.

Quick Revision

The whole lesson on one page.

Chain
A line
Prompt, model, parser. It only moves forward.
Graph
Steps and arrows
Nodes do the work, edges join them, and the state is shared. It can loop and pause.
Choosing
Start simple
Use a chain for a straight line. Use LangGraph when the job needs loops, memory or approval.