Node · State · Edge
LangGraph Workflow Basics: Understanding How AI Gets Work Done
Turn a single model call into a controllable flow of generation, review, decision, retry, and termination. This article explains LangGraph through a story demo instead of abstract definitions.
The model is not just answering once. It enters a workflow with rules, feedback, and a clear exit.
Large language models are good at generating content, but a useful AI application usually needs more than a single model call. In real work, we often need the model to perform a task, check the result, revise it if it does not pass, and stop only when the result is approved or a clear limit is reached.
LangGraph is designed for this kind of controllable AI workflow. It breaks an AI task into nodes, records progress in shared state, and uses edges to decide how the workflow should move.
The project is small, but responsibilities are clear
langgraph_story_demo/
├── main.py
├── state.py
├── nodes.py
├── router.py
└── graph.pyHow LangGraph works: a flowchart executor with memory
LangGraph is not simply running several functions in order. Its real value is state-driven workflow control.
[ Start / Input ]
│
▼
┌──────────────┐
│ State │ <─── state update (story / attempts / review / approved)
└──────────────┘
│
▼
[ writer_node ] ── generate story with local model
│
▼
[ reviewer_node ] ── review quality and write review / approved
│
▼
< conditional edge: should_continue >
│
├───────(not approved and attempts < MAX_ATTEMPTS)───────┐
│ │
│ ▼
│ back to writer_node
│
└───────(approved / max attempts reached)───────────────┐
│
▼
[ End / final output ]State is shared memory that enables correction
`State` is the shared memory of the graph while it is running. In this demo, `StoryState` stores the story, attempt count, review feedback, and approval status.
class StoryState(TypedDict):
story: str
attempts: int
review: str
approved: bool| Field | Meaning |
|---|---|
story | The current generated story. |
attempts | How many generation attempts have been made. |
review | Review feedback from the reviewer node. |
approved | Whether the story passed review. |
Node is action: each node does one step
`Node` is the unit that performs work in LangGraph. A node is usually a Python function: read State, perform one task, and return State fields to update.
Edge is control flow: where to go next
`Edge` defines how nodes connect. Normal edges represent fixed order; conditional edges choose the next path based on State.
Normal edge
graph.add_edge(START, "writer")
graph.add_edge("writer", "reviewer")Conditional edge
graph.add_conditional_edges(
"reviewer",
should_continue,
{
"writer": "writer",
"end": END,
},
)A real run: the system checks, decides, and retries
In one real run, the model was called twice. The first story was too short and failed review; the second generation used the feedback and passed.
Prompt length: 134 characters Story length: 76 characters Review result: failed Reason: too short and lacking clearer plot or quality keywords.
Prompt length: 174 characters Story length: 127 characters Review result: passed.
First generation fails
-> reviewer_node writes review feedback
-> State stores the failure reason
-> Edge decides to retry
-> writer_node generates again using the feedback
-> Second generation passes
-> Workflow endsLangChain vs. LangGraph: toolkit vs. workflow controller
LangChain is more like an LLM component toolkit.
LangGraph is more like an AI workflow controller.LangChain often connects Prompt, Model, Parser, Tool, Retriever, and Chain components. LangGraph focuses more on state management, multi-node workflows, conditional branches, retry loops, review, task orchestration, and controllable agent workflows.
In this demo, LangChain / langchain-ollama calls the local model, while LangGraph organizes writer -> reviewer -> decision -> retry or end.
Generalizing the story demo into an agent pattern
Generate
-> Evaluate
-> Decide
-> Revise
-> Stop| Scenario | writer_node | reviewer_node |
|---|---|---|
| Email writing | Generate an email draft | Check tone, length, and recipient details |
| Report writing | Generate report content | Check structure, data, and conclusions |
| Code generation | Generate code | Run tests and lint checks |
| Customer support | Generate a reply | Check policy compliance and factual accuracy |
| Document summary | Generate a summary | Check whether key points are covered |
Three sentences to remember
Use State to keep context.
Use Node to perform tasks.
Use Edge to control the workflow.AI applications can have branches, loops, reviews, retries, and stop conditions
This is where LangGraph becomes closer to real applications than a one-shot model call. An AI application does not have to move directly from input to output. Like ordinary software, it can make decisions based on state and take different paths.
if approved:
goto END
elif attempts >= MAX_ATTEMPTS:
goto END
else:
goto writer_node11. Summary
LangGraph_story_demo uses a small story-generation case to show the core way LangGraph works: generate content, record state, review results, branch on conditions, retry with feedback, stop after success, and stop after reaching a limit.
LangGraph is valuable not just because it connects nodes, but because it gives AI applications state, judgment, loops, and boundaries.
Plain LLM call: ask the model to answer once.
LangGraph workflow: let the model work inside a controllable process.