開始使用免費開始

別忘了:在多次呼叫間保留記憶

你正在規劃畢業旅行,並使用 smolagents 的旅遊助理來追蹤重要日期與資訊。

不過,除非你明確保留記憶,否則這個 agent 會忘記內容。你的目標是避免 agent 在每個問題之間重設,讓它能在多次互動中記住關鍵旅遊細節。

你可以使用已設定好模型、且沒有工具的 travel_agent

本練習屬於課程

使用 Hugging Face smolagents 的 AI 代理

檢視課程

練習說明

  • 修改第二次呼叫的 .run(),使用 reset 參數讓 agent 保留記憶。
  • reset 的值設為 False,避免 agent 重設其狀態。

動手互動練習

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

# Step 1: Tell the agent your flight date
travel_agent.run("My Tokyo flight confirmation code is ZX9Q2L.")

# Step 2: Confirm the agent remember when passing the correct reset parameter
follow_up = "What’s my Tokyo flight confirmation code?"
response = travel_agent.run(follow_up, ____=____)

print(response)
編輯並執行程式碼