開始使用免費開始

加入圖形記憶體

太棒了!你的聊天機器人已經能根據使用者的查詢,利用 Wikipedia 回答問題。現在再更進一步,讓使用者可以追問後續問題!為了做到這點,你需要先在聊天機器人中啟用記憶體。記憶體會讓你的聊天機器人取用完整的對話脈絡,因此能妥善處理後續的互動。

本練習屬於課程

Designing Agentic Systems with LangChain

檢視課程

練習說明

  • 先從 LangGraph 的 checkpoint.memory 模組匯入 MemorySaver
  • 建立 MemorySaver() 的實例為 memory
  • 重新編譯聊天機器人圖形:對 graph_builder 呼叫 .compile() 時,將 checkpointer 參數設為 memory

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Import the modules for saving memory
from langgraph.____.____ import ____

# Modify the graph with memory checkpointing
memory = ____()

# Compile the graph passing in memory
graph = ____.___(checkpointer=____)
編輯並執行程式碼