Skip to main content
AIDevOps
  • Learn
  • Learning Paths
  • Practice
  • Open Source
  • Books
  • Engineering

    AI DevOpsThe full map of building and operating AI servicesLLMOpsLLM deployment Β· evaluation Β· observabilityHands-on ProjectsBuild AI Agent projects

    Knowledge

    DocsTechnical documentationBlogEngineering articlesPloggerDevelopment log feed

    Validate

    Certification3-level skills certification Β· coming soon
AI Models
LlamaTutorial|MistralTutorial|GemmaTutorial|DeepSeekTutorial|QwenTutorial
πŸ€– AI Applied Development
Applied AI Intro & RoadmapHugging FaceLangChainLlamaIndexLLMOps|LangGraphMCPMulti-AgentAgent Evaluation
🧠 AI Core
AI Intro & RoadmapML FundamentalsLLM Fundamentals|Python AIC++|PyTorchTensorFlowJAX
🧠 AI Agent Development
Finance AI AgentLLM API ServerStock Investing AgentAIOps AI AgentEducation AI AgentCoding AI Agent
🌱 Spring Cloud
Spring Intro & RoadmapSpring Cloud GatewaySpring BootJava|Spring AISpring SecuritySpring BatchSpring JPA
🐳 DevOps
DevOps Intro & RoadmapLinuxDockerCI/CD|Kubernetes BasicsK8s AdvancedPrometheusGrafana
🧱 Infrastructure
Infrastructure Intro & RoadmapNginxRedis
☁️ Cloud
Cloud Intro & RoadmapAWSGCPAzureNCPCloudflare
🎨 Frontend
Frontend Intro & RoadmapJavaScriptTypeScript|ReactNext.js|VueNuxt|Electron
πŸ“± Mobile
Mobile Intro & RoadmapKotlinAndroidFlutter
βš™οΈ Backend
Backend Intro & RoadmapPython BasicsFastAPIDjangoFlask|CGoGinNode.js
πŸ’Ύ Database
DB Intro & RoadmapCore SQLOracleMySQLPostgreSQL|MongoDBVector DB
πŸ§ͺ Testing
k6JMeternGrinder
AIDevOps

Engineering AI. From Code to Production.
An engineering learning platform for building and operating AI and AI Agents

Learn

  • All Guides
  • Learning Paths
  • AI Tutorial
  • Practice
  • Books

Resources

  • AI DevOps
  • LLMOps
  • Hands-on Projects
  • Docs
  • Blog
  • Plogger
  • Open Source
  • Certification (coming soon)

Start Here

  • AI Core Roadmap
  • AI Applied Development Roadmap
  • Spring Cloud Roadmap
  • DevOps Roadmap
  • Infrastructure Roadmap

Β 

  • Cloud Roadmap
  • Frontend Roadmap
  • Mobile Roadmap
  • Backend Roadmap
  • Database Roadmap
Β© 2026 AIDevOps. All rights reserved.
Terms of ServicePrivacy PolicySitemaptestforge.kr
  1. Home
  2. Learn
  3. AI Applied Development
  4. LangGraph
Guide to stateful Agent workflows

πŸ•ΈοΈ LangGraph Complete Guide

Visitors

Design stateful, multi-step Agent workflows as graphs with LangGraph. Conditional branching, loops, and Human-in-the-loop approval β€” build the complex Agent logic that plain chains struggle with.

  • Advanced
  • Updated Oct 1, 2026
  • ~3 min read
  • 6 sections
  • 4 code examples

Learning Paths that include this guide

This guide is one step in the paths below. Study it together with the steps before and after.

  • AI Agent Engineer β†’
Stateful Agent workflowsConditional branching and iterative reasoningHuman-in-the-loop approvalMulti-step pipelines

Contents

0 / 9
  1. How to use this guide
  2. Architecture diagrams
  3. Why LangGraph
  4. StateGraph basics
  5. Conditional branching
  6. Loops (ReAct)
  7. Human-in-the-loop
  8. Persisting state
  9. Frequently asked questions
Contents 9 sections
  1. How to use this guide
  2. Architecture diagrams
  3. Why LangGraph
  4. StateGraph basics
  5. Conditional branching
  6. Loops (ReAct)
  7. Human-in-the-loop
  8. Persisting state
  9. Frequently asked questions

How to use this guide

How to read it

Understanding LangGraph as a real-world workflow

Design stateful, multi-step Agent workflows as graphs with LangGraph. Conditional branching, loops, and Human-in-the-loop approval β€” build the complex Agent logic that plain chains struggle with. Rather than listing concepts, this guide is organized so you can follow the content in the order you have to make decisions on a real project.

Key perspective

AI / LLM systems

Look beyond the model and the prompt: connect the data flow, evaluation, and post-deployment operating metrics in one view.

Stateful Agent workflowsConditional branching and iterative reasoningHuman-in-the-loop approvalMulti-step pipelines

Architecture diagrams

To make what you read stick, it helps to capture the flow as a picture first. The two diagrams below are reference maps you can keep coming back to while learning LangGraph.

Learning flow

Rendering diagram…

Architecture view

Rendering diagram…

Why LangGraph

When you first open LangGraph, the big picture matters more than individual commands. This section starts with the problems the concepts ahead were created to solve.

A LangChain chain is a linear structure that runs only in a fixed order such as A→B→C. A real Agent, though, has to decide for itself "whether to use a tool" and "how many more times to think". LangGraph expresses that flow as a graph of nodes (tasks) and edges (transition rules), which makes workflows with branching, loops, and pauses come naturally.
AspectLangChain chainLangGraph
Execution flowA fixed linear orderA graph that branches and loops on conditions
State managementPassed implicitly between chain callsShared through an explicit State schema
Pause/resumeDifficultCan stop at a specific point and resume with a checkpoint
Good fitSimple sequential pipelinesReAct loops, multi-agent, workflows that need approval

StateGraph basics

Here you look at StateGraph basics alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.

The heart of LangGraph is the StateGraph. You define a State schema shared by the whole graph, and each node is a function that reads and updates that state.
basic_graph.pyPYTHON
from typing import TypedDict, Annotated
from langgraph.graph import StateGraph, START, END
import operator

class AgentState(TypedDict):
    messages: Annotated[list, operator.add]   # each node appends to the list
    step_count: int

def call_model(state: AgentState) -> dict:
    # In reality an LLM call β€” only the concept is shown here
    return {"messages": ["model response"], "step_count": state["step_count"] + 1}

def call_tool(state: AgentState) -> dict:
    return {"messages": ["tool result"], "step_count": state["step_count"] + 1}

graph = StateGraph(AgentState)
graph.add_node("model", call_model)
graph.add_node("tool", call_tool)
graph.add_edge(START, "model")
graph.add_edge("model", "tool")
graph.add_edge("tool", END)

app = graph.compile()
result = app.invoke({"messages": [], "step_count": 0})
print(result["step_count"])

Conditional branching

Here you look at Conditional branching alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.

add_conditional_edges lets you choose the next node dynamically from the current state. This is how the pattern is implemented where the Agent decides for itself "whether to use another tool or give the final answer".
conditional_routing.pyPYTHON
def should_continue(state: AgentState) -> str:
    last_message = state["messages"][-1]
    if "final_answer" in last_message:
        return "end"
    if state["step_count"] >= 5:
        return "end"          # upper bound to prevent an infinite loop
    return "continue"

graph.add_conditional_edges(
    "model",
    should_continue,
    {"continue": "tool", "end": END},
)

Tip

A conditional branch must always include a stop condition such as a maximum number of steps β€” otherwise the model can keep calling tools and fall into an infinite loop.

Loops (ReAct)

Here you look at Loops (ReAct) alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.

Creating a cycle of model node β†’ tool node β†’ back to the model node expresses the ReAct pattern, which repeats "thought β†’ action β†’ observation", as a graph.
PYTHON
graph.add_edge("tool", "model")   # back to the model after the tool runs β€” forms the cycle

# model --(more needed)--> tool --> model --(done)--> END
#   ↑___________________________|

Human-in-the-loop

Here you look at Human-in-the-loop alongside real code. Rather than copying the example as-is, read it with an eye on the inputs, the outputs, and the parts most likely to change.

Actions that are hard to undo, such as payments, deployments, and deleting data, should go through human approval. With interrupt_before/interrupt_after, LangGraph can pause the graph before or after a specific node runs.
PYTHON
app = graph.compile(interrupt_before=["tool"])   # always stop before running a tool

state = app.invoke({"messages": [], "step_count": 0})
# The graph stops here β€” it resumes once a person reviews and approves
if input("Approve the tool run? (y/n) ") == "y":
    result = app.invoke(None)   # continue from where it stopped

Persisting state

This section covers Persisting state from a practical perspective. Instead of memorizing the concept, focus on the situations in which you would reach for it.

Attaching a Checkpointer saves the state of the graph to a DB, so even if the conversation is cut off it can continue from the same point later β€” essential for long-running Agents and multi-turn conversations.

Tip

  • MemorySaver stores only in process memory, so in production swap it for a SQLite/Postgres based checkpointer to keep state across restarts.
  • As the next step, learn in the mcp guide how an Agent connects to external tools and data in a standardized way.

LangGraph: frequently asked questions

What is LangGraph and when do I need it?

LangGraph is a library that defines an agent's execution flow as a stateful graph. You need it for flows that branch on conditions, repeat a step, or save intermediate state and resume later. A simple chain that runs in one direction does not need it.

What is State in LangGraph?

State is the shared data every node in the graph reads and updates. Each node receives the current state and returns only the part it changes, and the graph merges that and passes it to the next node. Conversation messages, intermediate results, and the values that decide the next path all live there.

How do I keep an agent from looping forever?

Set a maximum number of iterations on the graph run and add a node that checks a clear termination condition on every loop. Detecting repeated calls to the same tool with the same arguments and stopping is also effective. Adding cost and time limits bounds the damage when an unexpected loop does happen.

← Previous guideLlamaIndexNext guide β†’MCP