Agent 記憶完全指南:打造真正記得住的 AI Agent
AI Agent 每次執行後都會遺忘所有內容。本文介紹三種記憶架構與實用模式,讓你的 Agent 真正記得住跨執行的決策與死路。
AI Agent 非常擅長處理一次性任務。請 Claude 審查 PR、研究主題或產生規格文件——它都能做得很好。但對於持續性工作——每日程式碼審查、迭代研究、長期專案管理——沒有記憶的 Agent 根本撐不住。
問題不在於智能,而在於持久性。每次執行都從零開始。
本指南介紹如何實作真正適用於實際 Agent 工作流程的記憶機制。

Agent 記憶的三種類型
情境內記憶(In-Context Memory)
目前活躍 session 中的內容。存取速度快、立即可用——但 session 結束後完全消失。你告訴 Agent 的一切、它讀取的每個檔案、它做出的每個決策:全部消失。
對於一次性任務,這已足夠。對於在同一領域反覆執行的 Agent,這是致命的限制。
外部記憶(External Memory)
模型之外的持久儲存——檔案、資料庫、向量儲存。Agent 在 session 開始時從中讀取,並在執行期間和之後寫回。這正是 MemClaw 提供的:Agent 自動讀寫的結構化工作區。
外部記憶是大多數持續性 Agent 工作流程的正確選擇。它跨 session 持久存在、可搜尋,並可在團隊成員和不同 Agent 之間共享。
權重內記憶(In-Weights Memory)
訓練期間烘焙進模型的知識。這包括 Claude 對程式語言、框架和一般軟體實踐的所有了解。你無法寫入它——它是固定的。微調可以增加領域知識,但成本高昂且緩慢。
對於自訂專案知識——你的特定程式碼庫、你的團隊決策——外部記憶是唯一可行的選項。
為什麼「儲存所有內容」會失敗
天真的做法:指示 Agent 儲存所有重要的東西。這在實踐中會失敗,原因有二:
過度儲存: 被告知「記住重要事項」的 Agent 會儲存雜訊——中間推理步驟、暫時性想法、已被取代的內容。記憶儲存充滿了會主動誤導未來 session 的情境。
儲存不足: Agent 會錯過真正有價值的東西——已做出的決策、已排除的方法、已新增的限制。這些比人類理解專案更難自動識別。
可靠的模式:由人類判斷什麼重要的明確回寫(write-back)。
常見 Agent 類型的記憶模式
程式碼審查 Agent
跨執行需要記住的內容:
- 程式碼規範和團隊慣例
- 過去的審查決策及其理由
- 此程式碼庫中的已知反模式
- 反覆出現問題的檔案或模組
Session 開始:
Load the Code Review workspace
I'm reviewing the payment module changes. Load the coding standards
and any past decisions about the payment module.
審查後回寫:
Add to workspace: Reviewed payment/webhook.ts — flagged direct DB query
in route handler (violates Repository Pattern). Team convention requires
all DB access through /lib/repositories/. Logged 2026-04-08.
下週的審查:Claude 知道該模式已被標記。它可以追蹤是否已修復,以及相同模式是否出現在其他地方。
研究 Agent
死路記錄是研究 Agent 能做的最高價值的事:
Add to workspace: Explored Redis for session caching — ruled out.
Race condition in webhook handler when processing concurrent requests.
Idempotency keys don't solve it because the race is at the DB query level.
Do NOT revisit Redis for this use case.
沒有這個,每次研究執行都會重新探索相同的死路。
Session 開始:
Load the Research workspace
Continuing research on [topic]. What have we already explored?
What approaches have been ruled out?
專案管理 Agent
對 PM Agent 最有複利效果的內容:
- 包含利害關係人情境和理由的決策
- 範圍變更及其原因
- 有負責人和最後更新的阻塞項目
回寫:
Add decision to workspace: Deprioritized search feature for Q2.
Finance said CAC model doesn't support it this quarter.
Sarah (VP Product) confirmed — revisit in Q3 planning. 2026-04-08.
使用 MemClaw 設定 Agent 記憶
在 Claude Code 上安裝:
/plugin marketplace add Felo-Inc/memclaw
/plugin install memclaw@memclaw
export FELO_API_KEY="your-api-key-here"
為每種 Agent 類型建立工作區:
Create a workspace called Code Review Agent
Create a workspace called Research Agent
Create a workspace called Project Management
Session 模式:
- 開始時載入工作區
- 執行工作
- 在關閉前回寫決策、死路、狀態更新
這是完整的循環。區分隨時間進步的 Agent 和保持靜止的 Agent 的關鍵:一致的回寫。
回寫問題(及解決方法)
自動提取不可靠。有效的解決方案:將明確的回寫建立到 Agent 的工作流程中。
在重要時刻立即告訴 Agent 要儲存什麼:
We just decided to use server-side rendering for the dashboard.
Add this to the workspace: SSR chosen for dashboard pages — client
requires SEO indexability. CSR ruled out. 2026-04-08.
或建立到 session 結束:
Before we close: summarize the key decisions from this session
and add them to the workspace with today's date.
三個月一致回寫後:
- Agent 從記錄的歷史回答「我們上次嘗試了什麼?」
- 它不會重新建議已排除的方法
- 它給出與幾個月前做出的決策一致的建議
這就是外部記憶正確執行的複利效果。
評估 Agent 記憶品質
三個問題揭示你的 Agent 記憶是否有效:
- Agent 能準確回答「我們上次嘗試了什麼?」嗎? — 測試情節記憶
- Agent 是否重新建議已排除的方法? — 測試死路記錄
- Agent 隨時間給出更具體、更一致的建議嗎? — 測試複利效果
如果使用兩個月後第三個問題的答案是否定的,記憶就沒有被有效使用。要麼回寫沒有一致發生,要麼工作區沒有在 session 開始時載入。
開始使用
- 安裝 MemClaw(memclaw.me)
- 為每個 Agent 領域建立工作區
- 用 Agent 需要的基礎知識填充它
- Session 開始時載入,Session 結束時回寫