Skip to content

詞彙表與資料

源码版本1.2.9

核心術語

術語英文說明
狀態圖StateGraph使用者建構入口,add_node / add_edge / add_conditional_edges / compilelibs/langgraph/langgraph/graph/state.py
編譯圖CompiledGraph / PregelStateGraph.compile() 的產物,實作 PregelProtocol,承載 stream / invoke / astream 入口。libs/langgraph/langgraph/pregel/main.py
Pregel 執行體Pregel編譯後的可執行圖,繼承 PregelProtocol,持有 nodes / channels / checkpointerlibs/langgraph/langgraph/pregel/main.py
超步superstepPregel 模型的執行單位,一個超步內並行執行被觸發的所有「節點 (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 / subgraphslibs/langgraph/langgraph/pregel/_read.py
加節點add_nodeStateGraph.add_node(name, action) 註冊節點函式或 Runnable,內部走 coerce_to_runnablelibs/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 / listlibs/checkpoint/langgraph/checkpoint/base/__init__.py
記憶體保存器InMemorySaver / MemorySaverBaseCheckpointSaver 的記憶體實作,僅用於除錯;MemorySaverInMemorySaver 的舊別名。libs/checkpoint/langgraph/checkpoint/memory/__init__.py
狀態快照StateSnapshot步開始時的狀態視圖,含 values / next / tasks / interruptslibs/langgraph/langgraph/types.py
中斷interrupt / Interrupt節點內 interrupt(value)GraphInterrupt 暫停圖執行,客戶端用 Command(resume=...) 恢復。libs/langgraph/langgraph/types.py
命令Commandresume / goto / update 三合一原語,既可作節點回傳值也可作 invoke 輸入。libs/langgraph/langgraph/types.py
投遞SendPUSH 任務原語,向指定節點投遞帶特定 arg 的任務,實作 map-reduce 扇出。libs/langgraph/langgraph/types.py
功能 API@entrypoint / @task函式式 API,@entrypoint 把函式包成 Pregel,@task 包成可排程的子任務。libs/langgraph/langgraph/func/__init__.py
流模式stream_modePregel.stream / astream 的輸出投影選項:values / updates / messages / custom / checkpoints / tasks / debuglibs/langgraph/langgraph/pregel/main.py

目錄約定

  • 主源碼在 libs/langgraph/langgraph/,按職責分目錄:
    • pregel/ — 執行引擎內核。main.pyPregel 類別入口,__init__.py 匯出公共介面,_loop.pyPregelLoop 狀態機,_runner.pyPregelRunner 並行執行器,_algo.pyapply_writes / prepare_next_tasks / should_interrupt 等演算法函式,_io.pymap_command / map_input / map_output_*,_call.pySyncAsyncFuture 和 task 的 Runnable 包裝,_read.pyPregelNode,_executor.pyBackgroundExecutor / AsyncBackgroundExecutor,remote.pyRemoteGraph
    • graph/StateGraph / CompiledStateGraph 使用者介面,state.py 是核心,_node.py / _branch.py 是輔助。
    • channels/BaseChannel / LastValue / Topic / Binop 等通道實作。
    • func/@entrypoint / @task 函式式 API(實際全部在 func/__init__.py 一個檔案)。
    • types.pyCommand / 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,主類別 Pregelpregel/main.py

官方資料

源碼版本

本站源碼版本釘定 1.2.9,行號以該 tag 為準。所有 <SrcLink> 指向 github.com/langchain-ai/langgraph/blob/1.2.9/<path>#Lxx-Lyy。升版本改 docs/.vitepress/site.tsLANGGRAPH_TAG 再跑 npm run check:refs