Homestead
LGLangGraph Story Demo
Blog260812 · English Learning Note

Node · State · Edge

Published: 2026.08.12Reading Time: 10 minLangGraph / 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.

StateStores story, attempts, review feedback, and approval status.
Nodewriter generates, reviewer checks.
EdgeDecides whether to continue, retry, or stop.
Story Graph Loop

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.

Generatewriter_node calls the local model.
Reviewreviewer_node checks quality.
Decideshould_continue reads State.
RetryFeedback drives another generation.
StopEnd after approval or max attempts.
01

The project is small, but responsibilities are clear

langgraph_story_demo/
├── main.py
├── state.py
├── nodes.py
├── router.py
└── graph.py
state.pyDefines the shared workflow state, StoryState.
nodes.pyDefines writer_node and reviewer_node.
router.pyDefines should_continue to decide whether to stop or retry.
graph.pyUses StateGraph to assemble the workflow.
main.pyInitializes state, runs the graph, and prints results.
OverallState, nodes, routing, graph assembly, and entry point stay separate.
02

How 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 ]
03

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
FieldMeaning
storyThe current generated story.
attemptsHow many generation attempts have been made.
reviewReview feedback from the reviewer node.
approvedWhether the story passed review.
Without State, nodes cannot easily share context. If the first story is too short, the review feedback can be stored and used by writer_node in the next prompt.
04

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.

writer_nodeCalls the local Ollama model and updates story and attempts.
reviewer_nodeReads the story and checks it with Python rules.
Design principleIf deterministic code can solve it, do not send everything to the LLM.
05

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,
    },
)
06

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.

First call

Prompt length: 134 characters Story length: 76 characters Review result: failed Reason: too short and lacking clearer plot or quality keywords.

Second call

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 ends
07

LangChain 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.

08

Generalizing the story demo into an agent pattern

Generate
-> Evaluate
-> Decide
-> Revise
-> Stop
Scenariowriter_nodereviewer_node
Email writingGenerate an email draftCheck tone, length, and recipient details
Report writingGenerate report contentCheck structure, data, and conclusions
Code generationGenerate codeRun tests and lint checks
Customer supportGenerate a replyCheck policy compliance and factual accuracy
Document summaryGenerate a summaryCheck whether key points are covered
09

Three sentences to remember

State is memoryStores inputs, outputs, intermediate results, review feedback, and control variables.
Node is actionPerforms one clear step, such as generation, review, retrieval, tool calling, or file writing.
Edge is control flowDecides where to go next: continue, branch, loop, or stop.
Use State to keep context.
Use Node to perform tasks.
Use Edge to control the workflow.
10

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.

BranchIf the task is story writing, enter writer; if editing, enter editor; if only checking status, return current State.
LoopWhen reviewer finds the story too short, it writes feedback into State and returns to writer.
ReviewLength, keywords, and format can be checked with Python rules; complex style or safety checks can use another reviewer node.
RetryFailure does not mean the workflow failed. The system can try again with review feedback.
Stop conditionEnd when approved=True; also end when attempts >= MAX_ATTEMPTS to avoid infinite loops.
Business boundaryContract review, code generation, and support replies all need clear pass, return, retry, and stop rules.
if approved:
    goto END
elif attempts >= MAX_ATTEMPTS:
    goto END
else:
    goto writer_node

11. 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.
Blog260812 · LangGraph Workflow Basics · Node / State / Edge