詞彙表與資料
源码版本1.2.9
核心術語
| 術語 | 英文 | 說明 |
|---|---|---|
| 狀態圖 | StateGraph | 使用者建構入口,add_node / add_edge / add_conditional_edges / compile。libs/langgraph/langgraph/graph/state.py |
| 編譯圖 | CompiledGraph / Pregel | StateGraph.compile() 的產物,實作 PregelProtocol,承載 stream / invoke / astream 入口。libs/langgraph/langgraph/pregel/main.py |
| Pregel 執行體 | Pregel | 編譯後的可執行圖,繼承 PregelProtocol,持有 nodes / channels / checkpointer。libs/langgraph/langgraph/pregel/main.py |
| 超步 | superstep | Pregel 模型的執行單位,一個超步內並行執行被觸發的所有「節點 (node)」,步邊界同步「通道 (channel)」更新;借鑒自 Google Pregel 論文的 BSP 模型。 |
| 通道 | channel | 狀態更新原語,每個通道有版本號,reducer 決定如何合併寫入。libs/langgraph/langgraph/channels/ |
| 通道基底類別 | BaseChannel | 所有通道的抽象基底類別,定義 update / get / checkpoint 等介面。libs/langgraph/langgraph/channels/base.py |
| LastValue 通道 | LastValue | 只保留最新值的通道,常用於狀態欄位;LastValueAfterFinish 延遲到步結束才更新。libs/langgraph/langgraph/channels/last_value.py |
| 歸約器 | reducer | 通道合併寫入的函式,如 operator.add 用於列表追加;透過 Annotated[T, reducer] 在 state schema 裡宣告。 |
| 節點 | node / PregelNode | 圖的執行單元,持 bound / triggers / writers / subgraphs。libs/langgraph/langgraph/pregel/_read.py |
| 加節點 | add_node | StateGraph.add_node(name, action) 註冊節點函式或 Runnable,內部走 coerce_to_runnable。libs/langgraph/langgraph/graph/state.py |
| 條件邊 | add_conditional_edges | 按條件函式回傳值路由到下一節點,回傳 Send 列表實作扇出。libs/langgraph/langgraph/graph/state.py |
| 檢查點 | checkpoint | 執行緒 (thread) 級持久化快照,記錄通道版本、pending writes、metadata,支援斷點續跑。libs/langgraph/langgraph/pregel/_checkpoint.py |
| 檢查點保存器 | BaseCheckpointSaver | 檢查點持久化介面,put / get_tuple / list。libs/checkpoint/langgraph/checkpoint/base/__init__.py |
| 記憶體保存器 | InMemorySaver / MemorySaver | BaseCheckpointSaver 的記憶體實作,僅用於除錯;MemorySaver 是 InMemorySaver 的舊別名。libs/checkpoint/langgraph/checkpoint/memory/__init__.py |
| 狀態快照 | StateSnapshot | 步開始時的狀態視圖,含 values / next / tasks / interrupts。libs/langgraph/langgraph/types.py |
| 中斷 | interrupt / Interrupt | 節點內 interrupt(value) 拋 GraphInterrupt 暫停圖執行,客戶端用 Command(resume=...) 恢復。libs/langgraph/langgraph/types.py |
| 命令 | Command | resume / goto / update 三合一原語,既可作節點回傳值也可作 invoke 輸入。libs/langgraph/langgraph/types.py |
| 投遞 | Send | PUSH 任務原語,向指定節點投遞帶特定 arg 的任務,實作 map-reduce 扇出。libs/langgraph/langgraph/types.py |
| 功能 API | @entrypoint / @task | 函式式 API,@entrypoint 把函式包成 Pregel,@task 包成可排程的子任務。libs/langgraph/langgraph/func/__init__.py |
| 流模式 | stream_mode | Pregel.stream / astream 的輸出投影選項:values / updates / messages / custom / checkpoints / tasks / debug。libs/langgraph/langgraph/pregel/main.py |
目錄約定
- 主源碼在
libs/langgraph/langgraph/,按職責分目錄:pregel/— 執行引擎內核。main.py是Pregel類別入口,__init__.py匯出公共介面,_loop.py是PregelLoop狀態機,_runner.py是PregelRunner並行執行器,_algo.py是apply_writes/prepare_next_tasks/should_interrupt等演算法函式,_io.py是map_command/map_input/map_output_*,_call.py是SyncAsyncFuture和 task 的 Runnable 包裝,_read.py是PregelNode,_executor.py是BackgroundExecutor/AsyncBackgroundExecutor,remote.py是RemoteGraph。graph/—StateGraph/CompiledStateGraph使用者介面,state.py是核心,_node.py/_branch.py是輔助。channels/—BaseChannel/LastValue/Topic/Binop等通道實作。func/—@entrypoint/@task函式式 API(實際全部在func/__init__.py一個檔案)。types.py—Command/Send/Interrupt/StateSnapshot/PregelExecutableTask等公共資料型別。stream/—GraphRunStream/StreamMux等串流 mux 實作。managed/—IsLastStep等執行期注入值。
- 檢查點實作拆成獨立包:
libs/checkpoint/(base + memory)、libs/checkpoint-sqlite/、libs/checkpoint-postgres/。 - Pregel 引擎入口在
libs/langgraph/langgraph/pregel/__init__.py,主類別Pregel在pregel/main.py。
官方資料
- LangGraph 官方文件
- LangGraph 教學
- LangGraph 串流指南
- LangGraph 人在環指南
- GitHub 倉庫 langchain-ai/langgraph(本站源碼釘定 tag
1.2.9)
源碼版本
本站源碼版本釘定 1.2.9,行號以該 tag 為準。所有 <SrcLink> 指向 github.com/langchain-ai/langgraph/blob/1.2.9/<path>#Lxx-Lyy。升版本改 docs/.vitepress/site.ts 的 LANGGRAPH_TAG 再跑 npm run check:refs。