LangGraph Tutorial: Separating State and Control Flow
This tutorial explains how LangGraph separates state updates from graph routing: nodes return incremental dictionaries, while field-level reducers determine whether values are overwritten or appended. It also shows how routers and path_map implement conditional loops, and how checkpointer identity keys support persistence and human-in-the-loop workflows. The article highlights pitfalls including missing thread_id values and state replay during resume.
The tutorial gives LangGraph developers a practical model for understanding reducer-driven state updates, conditional routing, checkpointing, and human-in-the-loop behavior, along with several failure modes they may encounter.
两条线:LangGraph 如何把状态流和控制流拆开
一、一个字段被覆盖,一个字段留住了
lab_02 搭的是一张会绕圈的图:draft 先写个初稿,expand 每轮往里补一段,router 看长度够不够,不够就绕回去。我在 State 里定义了三个字段:
class State(TypedDict):
topic: str
result: str # 无 reducer
history: Annotated[list[str], operator.add] # 有 reducer
两个节点返回的东西长得一样,都是 dict:
return {"result": result, "history": [f"expand_node: 第 {round_no} 轮加工后, len(result)={len(result)}"]}