GenAI
RAG
AI Agents
原理可參考這篇綜論: How Agents for LLM Perform Task Planning。大型語言模型的代理如何進行任務規劃
Introduction to Agent Memory。Agent 記憶機制介紹
- Al assistants often need context, personalization, ability to
adapt to your feedback
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- Maintain context over time, adapt to our preferences, learn from past interactions
What are types of memory? LLM Agents 的三種記憶類型
- Semantic Memory ➔ 儲存長期事實 (如使用者偏好)。
- Episodic Memory ➔ 儲存過去互動與行動記錄 (如對話歷史)。
- Procedural Memory ➔ 儲存任務執行的規則與步驟 (如系統提示)。
Memory Type |
What is Stored |
Human Example |
Agent Example |
Semantic |
Facts |
Things I learned in school |
Facts about a user |
Episodic |
Experiences |
Things I did |
Past agent actions |
Procedural |
Instructions |
Instincts or motor skills |
Agent system prompt |
在 LLM Agents (大型語言模型代理) 的架構中,這三種記憶類型有以下對應與功能:
-
Semantic Memory (語意記憶)
- 儲存內容:儲存的是「事實性知識」或「長期穩定的資訊」。
- 在人類中的對應:像是在學校學到的知識。
- 在 LLM 中的應用:
- 儲存有關使用者的背景資料、偏好、興趣等長期資訊。
- 例如:「使用者的名字」、「最喜歡的顏色是藍色」或「使用者對科技新聞感興趣」。
- 此類資訊通常不會頻繁更新,屬於較固定的背景知識。
-
Episodic Memory (情節記憶)
- 儲存內容:儲存模型與使用者的「互動記錄」及「過去行為」。
- 在人類中的對應:像是「我昨天去了超市」或「我在某年參加過某場演唱會」。
- 在 LLM 中的應用:
- 儲存模型在過去對話中的行為、決策及回應。
- 例如:「昨天你問了我關於Python的問題」、「上次我推薦了某本書」。
- 此類記憶有助於模型理解對話上下文,提升連貫性。
-
Procedural Memory (程序性記憶)
- 儲存內容:儲存「如何完成某件事」的指令或技能。
- 在人類中的對應:像是「如何打網球」或「如何開車」。
- 在 LLM 中的應用:
- 包括代理系統的「Prompt 模板」、「行動計畫」或「多步驟工作流」。
- 例如:「先查找資料,再進行彙整,最後以條列式回答」。
- Procedural memory 讓 LLM Agents 更具執行複雜任務的能力。
記憶儲存機制 (Memory Storage Mechanisms)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
1. Hot Path (即時路徑)
- 流程特徵:
- 優點:
- 保證每次對話的記憶都即時更新,確保即時反應。
- 更適合短期記憶或快速回應情境。
- 缺點:
- 每次回應時都要花費額外時間來更新記憶,可能增加延遲。
- 適用情境:
- 使用者訊息與記憶高度相關時,例如:追蹤上下文或個人化推薦。
2. Background Path (背景路徑)
- 流程特徵:
- 使用者發送訊息 ➔ 立即回應使用者 ➔ (稍後,批次處理) 更新記憶
- 優點:
- 使用者可獲得更快速的回應,因為記憶更新被延遲至後台處理。
- 更適合非關鍵記憶或延遲儲存即可的資訊。
- 缺點:
- 如果系統在記憶更新前中斷,可能會導致記憶遺失或不完整。
- 適用情境:
- 大量對話且記憶更新非即時性質時,例如:資料摘要、每日彙整。
🔍 關鍵差異
特徵 |
Hot Path |
Background Path |
回應速度 |
慢 (需即時更新記憶) |
快 (記憶更新延遲處理) |
資料完整度 |
記憶即時更新,確保完整性 |
記憶可能有短暫延遲 |
適用場景 |
個人化對話、動態上下文追蹤 |
大量對話、非即時記憶更新 |
🧠 在 LLM Agents 的應用
- Hot Path 適合需要即時理解上下文的場合,例如虛擬助理在多輪對話中需持續理解前文。
- Background Path 則適合需快速回應的場景,尤其是較少需依賴過去對話記錄的情境,例如查詢天氣、執行指令等。
理想的 LLM Agent 通常會結合兩者,確保既有快速回應,又能持續學習與更新記憶,以提升長期互動的品質。
以Email Assistant為例 with Semantic Memory
- Inbox (收件匣)
➔ 所有郵件進入收件匣等待處理。
- Triage (分流)
➔ 使用 Episodic Memory 判斷哪些郵件需優先處理。
- LLM (大型語言模型)
➔ 根據郵件內容決定是否需安排會議 (Calendar Tool)、撰寫回應 (Writing Tool) 或更新記憶 (Memory Tool)。
- Agent (代理)
➔ 協調多個工具並根據使用者偏好最佳化回應行為。
✅ Episodic Memory (情節記憶)
✅ Semantic Memory (語意記憶)
✅ Procedural Memory (程序性記憶)
Semantic Memory(語意記憶)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
Semantic Memory 在此系統中分為兩個核心部分:
- Semantic Memory Profile (語意記憶檔案)
- 會議偏好 (Meeting preferences)
- 回應優先順序 (Response priorities)
- VIP 聯絡人 (VIP contacts)
- Semantic Memory Collection (語意記憶資料庫)
- 事實性資訊 (Facts)
- 過去互動記錄 (Past interactions)
Semantic Memory(語意記憶)+ Episodic Memory(情節記憶)
Image Not Showing
Possible Reasons
- The image was uploaded to a note which you don't have access to
- The note which the image was originally uploaded to has been deleted
Learn More →
- 定義: 儲存「過去事件」的記憶,幫助系統理解並根據以往經驗做出判斷。
- 在圖中的角色:
- 應用於 Triage (分流) 階段,使用「Few-shot examples」快速判斷郵件的重要性。
- 成功範例 (Success examples):
- 失敗範例 (Failure examples):
- ❌ 垃圾郵件 (Spam)
- ❌ 電子報 (Newsletters)
- ❌ 低優先度通知 (Low-priority updates)
- 🔎 功能
- 快速判斷郵件的優先級,減少處理不必要郵件的時間。
- 模型根據「過去經驗」自動標記郵件並過濾垃圾信。
Semantic(語意記憶)+ Episodic(情節記憶) + Procedural Memory(程序性記憶)