← Archive
lm-002715 · 2026-08

三域上下文動力學:從工作記憶、壓縮投影到外部典範庫

下載 MD 檔 ⬇

三域上下文動力學:從工作記憶、壓縮投影到外部典範庫

Three-Domain Context Dynamics: Working Context, Compressed Projection, and External Canonical Memory

摘要

大型語言模型與自主智能體的長程運作,通常被描述為一個「有限上下文窗口對抗無限增長歷史」的問題。既有方法因而集中於摘要、檢索增強、長期記憶、階層式記憶以及自適應記憶管理。MemGPT 將此問題類比為作業系統中的虛擬記憶管理,透過不同記憶層之間的資料移動突破有限上下文窗口;近期研究則進一步把記憶管理描述為可學習的控制過程,包括決定何時儲存、檢索、更新、摘要、合併與遺忘。

然而,單純增加外部記憶、進行摘要或提高檢索能力,仍不足以解決長程智能體的核心問題:何種資訊應存在於當下上下文,以及當前上下文何時應被清理、展開、重新連接與收斂。

本文提出「三域上下文動力學」(Three-Domain Context Dynamics, TDCD)。其基本主張是:智能體的記憶系統不應被視為單一記憶庫,而應區分為三個不同功能與不同資訊保真度的域:

Wt=Working Context Domain,\mathcal W_t = \text{Working Context Domain}, Pt=Projection / Compiled Context Domain,\mathcal P_t = \text{Projection / Compiled Context Domain}, D=Canonical External Domain.\mathcal D = \text{Canonical External Domain}.

其中, Wt\mathcal W_t 是時間 tt 真正進入模型推理過程的有限工作域; Pt\mathcal P_t 是經過壓縮、索引、分類、地址化與重要性估計後形成的投影域; D\mathcal D 則保存完整、可驗證、可追溯的典範資料。

本文進一步提出四類核心算子:

E=Expand,\mathcal E = \text{Expand}, L=Link,\mathcal L = \text{Link}, C=Converge,\mathcal C = \text{Converge}, G=Govern.\mathcal G = \text{Govern}.

本框架的核心觀點不是「透過壓縮解決上下文限制」,而是:

Compression is an observation layer; context governance is the control layer.\boxed{ \text{Compression is an observation layer; context governance is the control layer.} }

壓縮負責揭露結構、重要性與可恢復地址;真正改善長程推理品質的則是持續治理當下上下文的內容。


關鍵詞

大型語言模型、智能體記憶、上下文治理、長期記憶、記憶壓縮、典範資料庫、投影記憶、上下文清理、記憶編譯、MCP、Autonomous Context Runtime


1. 問題的重新定義

有限上下文窗口通常被形式化為容量問題。

令完整歷史資訊為:

Ht={m1,m2,,mt},H_t=\{m_1,m_2,\ldots,m_t\},

模型在時間 tt 可接受的上下文預算為:

Bt<Ht.B_t<|H_t|.

最直接的問題因此看似是:

如何把 Ht 壓縮進 Bt?\text{如何把 }H_t\text{ 壓縮進 }B_t?

然而這個表述隱含了一個錯誤假設:

所有歷史資訊只是因為「太長」而無法進入現在。

實際上,即使:

HtBt,|H_t|\leq B_t,

仍可能存在低品質上下文。

例如:

  1. 相同資訊被不同措辭重複;
  2. 舊版本結論仍與新版結論共同存在;
  3. 已完成的任務資訊持續佔據工作域;
  4. 不同研究分支彼此污染;
  5. 次要細節遮蔽主要目標;
  6. 曾經重要的資訊在當前任務中已失去相關性;
  7. 真正重要的舊資訊反而沒有被重新帶入。

因此上下文失效並不等價於上下文容量不足:

Context FailureContext Overflow.\boxed{ \text{Context Failure} \neq \text{Context Overflow}. }

更一般地:

Context Failure=f(overflow,redundancy,staleness,conflict,branch contamination,retrieval failure,attention dilution).\text{Context Failure} = f( \text{overflow}, \text{redundancy}, \text{staleness}, \text{conflict}, \text{branch contamination}, \text{retrieval failure}, \text{attention dilution} ).

因此長程智能系統需要解決的核心問題應重新表述為:

在有限工作域中,持續維持當下最適合推理的資訊狀態。\boxed{ \text{在有限工作域中,持續維持當下最適合推理的資訊狀態。} }

此問題本文稱為 Context Governance Problem


2. 與既有記憶研究的關係

MemGPT 已提出利用階層式記憶與資料移動形成類似虛擬上下文的機制,其基本洞見是有限模型上下文不應等價於整個系統的有效記憶容量。

2026 年的 Agentic Memory 進一步將短期與長期記憶管理整合至 Agent policy,使智能體能自主選擇儲存、檢索、更新、摘要與丟棄等操作。

MemRefine 則直接處理長期記憶庫隨時間增長後所產生的冗餘問題,並指出表面相似性不足以決定記憶的事實價值,因此需要更高階的 merge、delete 與 preserve 判定。

MemCon 更進一步把記憶操作形式化成控制問題,使系統根據當前任務狀態決定何時、如何以及取回多少記憶,並加入 consolidation 與 forgetting。

因此本文不主張「自適應記憶控制」本身是新的問題。

本文提出的差異在於以下三點。

第一,本文明確區分:

working contextcompressed representationcanonical memory.\boxed{ \text{working context} \neq \text{compressed representation} \neq \text{canonical memory}. }

第二,本文不要求壓縮表示本身具有完全可逆性,而要求:

任何具有典範價值的省略資訊,都必須保有返回原始資料的地址。\boxed{ \text{任何具有典範價值的省略資訊,都必須保有返回原始資料的地址。} }

第三,本文把「清理當前上下文」視為獨立於「管理長期記憶庫」的控制問題。

因此本文研究的並非單純 Memory Management,而更接近:

Dynamic Context-State Governance.\boxed{ \text{Dynamic Context-State Governance}. }

3. 三域模型

3.1 工作域 Wt\mathcal W_t

定義時間 tt 的工作域為:

Wt={mm currently participates in model inference}.\mathcal W_t = \{m\mid m\text{ currently participates in model inference}\}.

其容量受到:

WtBt|\mathcal W_t|\leq B_t

限制。

但容量限制並不是其唯一條件。

我們希望:

WtEt,\mathcal W_t \approx \mathcal E_t,

其中 Et\mathcal E_t 表示「真正屬於當下問題的有效資訊集合」。

因此理想工作域不是最大集合,而是一個相關性、可靠度與成本共同約束下的選擇集合。

可寫成:

Wt=argmaxSMU(Sqt,st)\mathcal W_t^* = \arg\max_{\mathcal S\subseteq\mathcal M} U(\mathcal S\mid q_t,s_t)

subject to

C(S)Bt,C(\mathcal S)\leq B_t,

其中:

  • qtq_t 為當前查詢;
  • sts_t 為當前 Agent 狀態;
  • UU 為上下文效用;
  • CC 為上下文成本。

4. 投影域 Pt\mathcal P_t

投影域不是完整記憶,也不是單純摘要。

定義:

Pt=Πt(D),\mathcal P_t = \Pi_t(\mathcal D),

其中 Πt\Pi_t 為時間依賴的投影算子。

Pt\mathcal P_t 可以包含:

  • 摘要;
  • 語義向量;
  • 主題;
  • 標籤;
  • persistence class;
  • 版本資訊;
  • 關係圖;
  • 時間資訊;
  • 來源地址;
  • provenance;
  • importance score;
  • conflict state;
  • branch membership;
  • exact restoration pointer。

因此:

PtD|\mathcal P_t|\ll|\mathcal D|

通常成立,但:

PtD.\mathcal P_t\neq\mathcal D.

這一區別十分重要。

如果將摘要本身視為長期記憶,則一旦摘要丟失某個未被當下認為重要、但未來重新變重要的細節,該資訊便永久消失。

因此本文要求 Canonical Recoverability Condition

若:

mDm\in\mathcal D

具有典範保存資格,且其內容未完整存在於 Pt\mathcal P_t,則必須存在某個地址:

a(m)a(m)

使得:

R(a(m),D)=m.R(a(m),\mathcal D)=m.

其中 RR 為 exact retrieval operator。

因此:

projection may be lossy while memory preservation remains lossless.\boxed{ \text{projection may be lossy while memory preservation remains lossless}. }

5. 典範域 D\mathcal D

典範域保存系統認定具有持續價值的完整資料。

它可以包括:

  • 原始對話;
  • 文件;
  • 原始碼;
  • 資料集;
  • 工具結果;
  • 實驗記錄;
  • provenance;
  • 版本歷史;
  • agent state checkpoint;
  • 外部事件記錄。

其核心要求不是「全部永遠不刪除」,而是:

projection must never silently become canonical source.\boxed{ \text{projection must never silently become canonical source}. }

即若:

p=Π(m),p=\Pi(m),

一般情況下不能推論:

pm.p\equiv m.

除非存在明確驗證:

Equivalent(p,m)=1.\operatorname{Equivalent}(p,m)=1.

這使得摘要、嵌入向量、關係圖與其他衍生表示全部保持為 derivative representation,而非 source of truth。


6. 三域資訊關係

系統的完整記憶狀態定義為:

Mt=(Wt,Pt,Dt).\mathfrak M_t = (\mathcal W_t,\mathcal P_t,\mathcal D_t).

三者具有不同更新速度:

vW>vP>vDv_W>v_P>v_D

通常成立。

其中:

  • Wt\mathcal W_t 高頻變動;
  • Pt\mathcal P_t 中頻重新編譯;
  • Dt\mathcal D_t 低頻、版本化更新。

其資訊保真度通常滿足:

FDFWFP,F_D\geq F_W\geq F_P,

但當前任務效用未必如此:

UW(t)UP(t)U_W(t)\geq U_P(t)

通常是治理系統希望維持的狀態。

因此:

保真度最高的資料,不必直接存在於工作上下文;工作上下文需要的是對當前問題效用最高的資料。


7. 四個基本算子

7.1 展開算子

定義:

E:(Wt,Pt,D,qt)W~t.\mathcal E: (\mathcal W_t,\mathcal P_t,\mathcal D,q_t) \rightarrow \widetilde{\mathcal W}_t.

展開不是把更多歷史無條件加入上下文,而是尋找:

Mt+={mD:Ψt(m,qt)θt}.M_t^{+} = \{m\in\mathcal D: \Psi_t(m,q_t)\geq\theta_t\}.

然後:

W~t=WtMt+.\widetilde{\mathcal W}_t = \mathcal W_t\cup M_t^{+}.

其中 Ψt\Psi_t 是 contextual appropriateness function。


7.2 連接算子

資訊被取回並不代表它已與當前問題形成有效關係。

因此定義:

L:W~tGt,\mathcal L: \widetilde{\mathcal W}_t \rightarrow \mathcal G_t,

其中 Gt\mathcal G_t 是局部關係結構。

對任意:

mi,mjW~t,m_i,m_j\in\widetilde{\mathcal W}_t,

可以存在:

rij{supports,contradicts,updates,depends-on,same-branch,supersedes,derives-from}.r_{ij} \in \{ \text{supports}, \text{contradicts}, \text{updates}, \text{depends-on}, \text{same-branch}, \text{supersedes}, \text{derives-from} \}.

因此:

Gt=(Vt,Et).\mathcal G_t=(V_t,E_t).

這使檢索結果不再只是平坦文字集合,而成為可計算的局部上下文結構。


8. 收斂算子

展開會增加資訊量,因此必須存在與其相反的操作。

定義:

C:(Gt,Bt)Wt+1.\mathcal C: (\mathcal G_t,B_t) \rightarrow \mathcal W_{t+1}.

使得:

Wt+1Bt+1.|\mathcal W_{t+1}|\leq B_{t+1}.

但收斂不是單純截斷。

需要最大化:

U(Wt+1qt+1,st+1)U(\mathcal W_{t+1}\mid q_{t+1},s_{t+1})

並最小化:

N(Wt+1),N(\mathcal W_{t+1}),

其中 NN 是 context noise。

因此可以寫成:

Wt+1=argmaxS[U(S)λN(S)μC(S)].\mathcal W_{t+1} = \arg\max_{\mathcal S} \left[ U(\mathcal S) -\lambda N(\mathcal S) -\mu C(\mathcal S) \right].

9. 治理算子

本文最核心的算子是:

G.\mathcal G.

它不直接等價於 compression,也不等價於 retrieval。

定義:

G:(Wt,Pt,Dt,st)At,\mathcal G: (\mathcal W_t,\mathcal P_t,\mathcal D_t,s_t) \rightarrow A_t,

其中 AtA_t 為一組治理行為。

例如:

At{retain,remove,compress,expand,relink,merge,supersede,archive,promote,demote,fork,flag-conflict}.A_t \subseteq \{ \text{retain}, \text{remove}, \text{compress}, \text{expand}, \text{relink}, \text{merge}, \text{supersede}, \text{archive}, \text{promote}, \text{demote}, \text{fork}, \text{flag-conflict} \}.

因此上下文治理不是一次性的 preprocessing,而是持續控制過程。


10. 上下文清理

令:

NtN_t

為工作域中的無效或低效資訊。

則:

Nt=NtdupNtstaleNtconflictNtbranchNtirrelevant.N_t = N_t^{dup} \cup N_t^{stale} \cup N_t^{conflict} \cup N_t^{branch} \cup N_t^{irrelevant}.

上下文清理器執行:

Clean(Wt)=WtNt.\operatorname{Clean}(\mathcal W_t) = \mathcal W_t\setminus N_t.

但其中的「刪除」只是:

remove from active context,\text{remove from active context},

而不必等於:

delete from canonical memory.\text{delete from canonical memory}.

因此存在一個極重要的非等價關係:

Forget from ContextDelete from Memory.\boxed{ \text{Forget from Context} \neq \text{Delete from Memory}. }

這使系統可以積極清理工作域,而不必因為害怕永久資訊損失而不敢遺忘。


11. 記憶持續性

每一記憶物件 mm 可以具有 persistence class:

τp(m){I,A,P,T},\tau_p(m) \in \{ I,A,P,T \},

其中:

I=instantaneous,I=\text{instantaneous}, A=active,A=\text{active}, P=persistent,P=\text{persistent}, T=trajectory.T=\text{trajectory}.

不同 persistence class 應具有不同衰減與治理函數。

例如:

dI(t)>dA(t)>dP(t)>dT(t),d_I(t)>d_A(t)>d_P(t)>d_T(t),

其中 d(t)d(t) 表示退出工作域的傾向。

因此「新資訊一定比舊資訊重要」不成立。

一個十年前建立的方法論:

mPm_P

可能比五分鐘前產生的暫時狀態:

mIm_I

更應被保留。


12. 展開—連接—收斂循環

三域系統的基本演化可表示為:

MtEM~tLGtCMt+1.\mathfrak M_t \xrightarrow{\mathcal E} \widetilde{\mathfrak M}_t \xrightarrow{\mathcal L} \mathcal G_t \xrightarrow{\mathcal C} \mathfrak M_{t+1}.

G\mathcal G 治理算子作用於整個循環:

Mt+1=Gt[C(L(E(Mt,qt)))].\boxed{ \mathfrak M_{t+1} = \mathcal G_t \left[ \mathcal C \left( \mathcal L \left( \mathcal E(\mathfrak M_t,q_t) \right) \right) \right]. }

因此系統不是:

StoreRetrieve.\text{Store}\rightarrow\text{Retrieve}.

而是:

StoreCompileProjectExpandLinkConvergeRecompile.\boxed{ \text{Store} \rightarrow \text{Compile} \rightarrow \text{Project} \rightarrow \text{Expand} \rightarrow \text{Link} \rightarrow \text{Converge} \rightarrow \text{Recompile}. }

這是一個持續運作的記憶動力系統。


13. 壓縮的重新定位

由前三域定義可得:

Compress:DP.\operatorname{Compress}: \mathcal D \rightarrow \mathcal P.

但真正形成下一個有效工作上下文的是:

Govern:(W,P,D)W.\operatorname{Govern}: (\mathcal W,\mathcal P,\mathcal D) \rightarrow \mathcal W'.

因此:

CompressGovern.\boxed{ \operatorname{Compress} \neq \operatorname{Govern}. }

壓縮能回答:

哪些資訊可以用較低成本表示?

治理則回答:

現在真正應該讓模型看到什麼?

這是兩個不同問題。


14. 命題一:壓縮不足命題

命題 1(Compression Insufficiency Proposition)

存在歷史集合 HH 與上下文預算 BB,即使:

Compress(H)B,|\operatorname{Compress}(H)|\leq B,

使用壓縮後完整內容作為工作上下文仍非最優:

U(Compress(H))<U(W).U(\operatorname{Compress}(H)) < U(\mathcal W^*).

證明構想

HH 包含大量:

  • 已過期結論;
  • 任務無關資訊;
  • 分支內容;
  • 重複資訊。

即使存在無損或高保真壓縮:

C(H),C(H),

使其長度落入上下文限制,這些低效資訊仍然存在。

因此容量問題被解決並不推出選擇問題被解決。

故:

compression sufficiency⇏context optimality.\text{compression sufficiency} \not\Rightarrow \text{context optimality}.

證畢。


15. 命題二:投影—典範分離命題

若:

Pt\mathcal P_t

允許有損壓縮,而:

D\mathcal D

保存完整 canonical object,且對每個被省略的 canonical object 存在 exact restoration address,則系統可以同時滿足:

PtD|\mathcal P_t|\ll|\mathcal D|

以及:

Pr[R(a(m),D)=m]=1\Pr[ R(a(m),\mathcal D)=m ]=1

在儲存與雜湊完整性假設成立時。

因此:

Active representation can be lossy without making canonical memory lossy.\boxed{ \text{Active representation can be lossy without making canonical memory lossy.} }

這是三域模型相對單一摘要記憶的重要差異。


16. 命題三:安全清理條件

對:

mWt,m\in\mathcal W_t,

若:

mDm\in\mathcal D

且存在可驗證 restoration address:

a(m),a(m),

則:

mWt+1m\notin\mathcal W_{t+1}

並不推出:

mMt+1.m\notin\mathfrak M_{t+1}.

因此工作上下文可以進行 aggressive pruning,而不必等價於系統遺忘。

這可稱為:

Safe Context Eviction Principle.\boxed{ \text{Safe Context Eviction Principle}. }

它與作業系統中的工作集移出具有結構類似性,但此處被移出的並非單純 bytes,而是具有不同語義角色、版本、依賴與持續性的認知物件。


17. MCP 的位置

MCP 的定位也可由本框架重新描述。

2026-07-28 MCP 規格正式將 protocol core 轉為 stateless request/response 模型;若應用需要跨呼叫狀態,規格建議由應用顯式管理並傳遞相應 handle,而不是依靠協議層隱藏 session state。

因此:

MCPMemory Runtime.\boxed{ \text{MCP}\neq\text{Memory Runtime}. }

更適當的關係是:

Context RuntimeMCPMemory Services.\text{Context Runtime} \leftrightarrow \text{MCP} \leftrightarrow \text{Memory Services}.

在 TDCD 中,MCP 可以承載:

  • canonical database access;
  • context projection;
  • exact expansion;
  • semantic retrieval;
  • graph operations;
  • archival operations;
  • external tool access。

但:

G\mathcal G

本身應屬於 Host、Agent Runtime 或更高階 Context Governor。

也就是:

MCP is the bus; governance belongs to the runtime.\boxed{ \text{MCP is the bus; governance belongs to the runtime.} }

18. 從記憶管理到記憶編譯

傳統描述通常使用:

WriteStoreRetrieve.\text{Write} \rightarrow \text{Store} \rightarrow \text{Retrieve}.

三域模型則更適合使用「編譯」隱喻。

原始記憶:

mm

進入典範域後,可以被編譯成:

Π(m)=(summary,embedding,address,relations,persistence,version,importance,provenance).\Pi(m) = ( summary, embedding, address, relations, persistence, version, importance, provenance ).

投影表示不是原文的替代物,而是:

execution-oriented memory representation.\boxed{ \text{execution-oriented memory representation}. }

因此整個系統可稱為:

Memory Compilation Runtime

其循環為:

IngestValidateCanonicalizeCompileProjectGovernExpandExecuteRecompile.\boxed{ \text{Ingest} \rightarrow \text{Validate} \rightarrow \text{Canonicalize} \rightarrow \text{Compile} \rightarrow \text{Project} \rightarrow \text{Govern} \rightarrow \text{Expand} \rightarrow \text{Execute} \rightarrow \text{Recompile}. }

19. 從「記住多少」轉向「現在需要什麼」

三域上下文動力學最根本的轉換,是將問題:

系統能保存多少歷史?

轉化為:

在當前狀態下,哪些歷史應成為現在的一部分?

因此真正核心的集合不是:

M=all memory,\mathcal M = \text{all memory},

而是:

E(t)={mM:Ψt(m)θt}.\mathcal E^{(t)} = \left\{ m\in\mathcal M: \Psi_t(m)\geq\theta_t \right\}.

Ψt\Psi_t 可以由多個維度構成:

Ψt(m)=wqQt(m)+wsSt(m)+wpPt(m)+wrRt(m)+wvVt(m)+wcCt(m)+wdDt(m).\Psi_t(m) = w_qQ_t(m) + w_sS_t(m) + w_pP_t(m) + w_rR_t(m) + w_vV_t(m) + w_cC_t(m) + w_dD_t(m).

其中可以分別表示:

  • query relevance;
  • semantic resonance;
  • persistence;
  • relation strength;
  • version validity;
  • current-task compatibility;
  • dependency importance。

因此:

Memory relevance is a state-dependent quantity.\boxed{ \text{Memory relevance is a state-dependent quantity.} }

同一個 mm 在不同時間滿足:

Ψt1(m)Ψt2(m)\Psi_{t_1}(m)\neq\Psi_{t_2}(m)

是正常現象。


20. 結論

本文提出三域上下文動力學 TDCD,將長程 AI 記憶系統區分為:

WtPtD.\boxed{ \mathcal W_t \leftrightarrow \mathcal P_t \leftrightarrow \mathcal D. }

即:

Working DomainProjection DomainCanonical Domain.\boxed{ \text{Working Domain} \leftrightarrow \text{Projection Domain} \leftrightarrow \text{Canonical Domain}. }

並提出:

E,L,C,G\mathcal E,\mathcal L,\mathcal C,\mathcal G

四類核心操作:

ExpandLinkConverge,\boxed{ \text{Expand} \rightarrow \text{Link} \rightarrow \text{Converge}, }

由:

Govern\boxed{ \text{Govern} }

持續調節。

由此得到本文的主要結論:

The purpose of memory compression is not to preserve the present forever, but to make the past cheap enough to leave the present safely.\boxed{ \text{The purpose of memory compression is not to preserve the present forever, but to make the past cheap enough to leave the present safely.} }

換言之:

壓縮的真正價值,不是把全部歷史塞回上下文,而是讓上下文敢於遺忘。\boxed{ \text{壓縮的真正價值,不是把全部歷史塞回上下文,而是讓上下文敢於遺忘。} }

只要完整歷史存在於可驗證的典範域,投影層提供低成本尋址,而治理層能夠重新判斷當下需求,工作上下文便不必退化為不斷累積的歷史堆疊。

因此未來真正需要建立的不是「更大的 prompt」,而是一個能持續執行:

清理展開連接收斂\boxed{ \text{清理} \leftrightarrow \text{展開} \leftrightarrow \text{連接} \leftrightarrow \text{收斂} }

的自主上下文運行時。


參考文獻

Packer, C., Wooders, S., Lin, K., Fang, V., Patil, S. G., Stoica, I., & Gonzalez, J. E. MemGPT: Towards LLMs as Operating Systems. arXiv:2310.08560.

Yu, Y., Yao, L., Xie, Y., et al. Agentic Memory: Learning Unified Long-Term and Short-Term Memory Management for Large Language Model Agents. arXiv:2601.01885.

Kim, M., Baek, J., Jeong, S., & Hwang, S. J. MemRefine: LLM-Guided Compression for Long-Term Agent Memory. arXiv:2606.13177.

Jiang, E. H., Zhang, Z., Wu, Y., et al. Memory as a Controlled Process: Learned Adaptive Memory Management for LLM Agents. arXiv:2607.13591.

Model Context Protocol Core Maintainers. The 2026-07-28 Specification. Model Context Protocol, July 28, 2026.