上下文治理算子與動態工作集理論:三域上下文動力學的控制層
Context Governance Operator and Dynamic Working-Set Theory: The Control Layer of Three-Domain Context Dynamics
Series I / Paper 02 — v0.1
摘要
本文承接「三域上下文動力學」(Three-Domain Context Dynamics, TDCD),進一步研究其核心控制問題:在外部典範記憶可長期保存、投影記憶可低成本尋址的條件下,如何決定什麼資訊應在當下工作上下文中存在、退出、重新召回、被新版本覆寫、與其他分支隔離或重新連接。
本文將上下文治理從一般性的記憶檢索或壓縮問題中分離,定義治理算子
G t : ( W t , P t , D t , s t ) → A t , \mathcal G_t:(\mathcal W_t,\mathcal P_t,\mathcal D_t,s_t)\rightarrow A_t, G t : ( W t , P t , D t , s t ) → A t ,
其中 W t \mathcal W_t W t 為工作域, P t \mathcal P_t P t 為投影域, D t \mathcal D_t D t 為典範域, s t s_t s t 為當前任務狀態, A t A_t A t 為一組治理行為。本文定義上下文污染量、動態工作集、版本偏序、分支隔離、召回與驅逐遲滯、治理震盪與穩定條件,並提出安全驅逐、版本頭唯一性、非單調上下文效用與遲滯抑制震盪等命題。
本文的核心觀點是:長程智能體的問題不只是「記憶是否存在」,而是「當下工作集是否處於適合推理的狀態」。因此:
More accessible memory does not imply a better active context. \boxed{
\text{More accessible memory does not imply a better active context.}
} More accessible memory does not imply a better active context.
上下文治理的目的,是在保留典範可恢復性的同時,使工作域持續逼近當前任務的最小充分工作集。
關鍵詞
上下文治理、工作集、智能體記憶、記憶覆寫、分支隔離、上下文污染、召回、驅逐、遲滯、典範記憶、長程智能體、TDCD
1. 從記憶容量問題進入控制問題
在 TDCD Paper 01 中,系統記憶被區分為三個域:
M t = ( W t , P t , D t ) , \mathfrak M_t=(\mathcal W_t,\mathcal P_t,\mathcal D_t), M t = ( W t , P t , D t ) ,
其中:
W t = Working Context Domain , \mathcal W_t=\text{Working Context Domain}, W t = Working Context Domain ,
P t = Projection / Compiled Domain , \mathcal P_t=\text{Projection / Compiled Domain}, P t = Projection / Compiled Domain ,
D t = Canonical External Domain . \mathcal D_t=\text{Canonical External Domain}. D t = Canonical External Domain .
這個區分解決了一個基本混淆:完整保存、低成本表示與當下推理並不是同一個問題。
若系統已經具有近乎無界的外部資料庫,仍不能推出:
the agent always has the right context . \text{the agent always has the right context}. the agent always has the right context .
同樣地,即使存在高品質壓縮:
C ( D t ) = P t , C(\mathcal D_t)=\mathcal P_t, C ( D t ) = P t ,
也不能推出:
P t = W t ∗ . \mathcal P_t=\mathcal W_t^*. P t = W t ∗ .
因此本文研究的是一個控制問題:
How should the active context state evolve? \boxed{
\text{How should the active context state evolve?}
} How should the active context state evolve?
這一問題與經典 working-set 思想存在結構類比:Denning 的 working-set model 研究執行中的程式在某段時間真正需要哪些 pages,而非要求所有 pages 同時駐留主記憶體。[1] 然而,AI 上下文中的「工作集」不能只由 recency 決定,因為語義依賴、版本有效性、任務分支、持續性與來源可信度皆可能使很久以前的資訊重新成為當下核心。
因此本文把 working set 從「近期被引用的資訊集合」推廣為「在當前任務狀態下具有主動參與資格的資訊集合」。
2. 記憶物件與治理狀態
令一個可治理記憶物件為:
m = ( x , a , b , v , p , r , d , c ) , m=(x,a,b,v,p,r,d,c), m = ( x , a , b , v , p , r , d , c ) ,
其中:
x x x :內容或 canonical object;
a a a :canonical restoration address;
b b b :branch identifier;
v v v :version state;
p p p :persistence class;
r r r :relations;
d d d :dependency metadata;
c c c :confidence / validation state。
系統在時間 t t t 的治理狀態定義為:
S t = ( W t , P t , D t , R t , q t , B t ) , S_t=(\mathcal W_t,\mathcal P_t,\mathcal D_t,\mathcal R_t,q_t,B_t), S t = ( W t , P t , D t , R t , q t , B t ) ,
其中 R t \mathcal R_t R t 是目前已知的關係結構, q t q_t q t 是當前任務或問題狀態, B t B_t B t 是工作上下文預算。
治理算子作用為:
G t ( S t ) → A t , \mathcal G_t(S_t)\rightarrow A_t, G t ( S t ) → A t ,
其中:
A t ⊆ { retain , admit , evict , recall , compress , merge , supersede , fork , bridge , flag , archive } . A_t\subseteq
\{
\operatorname{retain},
\operatorname{admit},
\operatorname{evict},
\operatorname{recall},
\operatorname{compress},
\operatorname{merge},
\operatorname{supersede},
\operatorname{fork},
\operatorname{bridge},
\operatorname{flag},
\operatorname{archive}
\}. A t ⊆ { retain , admit , evict , recall , compress , merge , supersede , fork , bridge , flag , archive } .
治理因而不是單一函數,而是根據狀態輸出操作集合的 policy。
3. 上下文效用不是單調函數
對任意工作上下文集合 W W W ,定義其任務效用為:
U t ( W ) = U ( W ∣ q t , S t ) . U_t(W)=U(W\mid q_t,S_t). U t ( W ) = U ( W ∣ q t , S t ) .
直覺上,人們容易假定加入更多可用資訊不會使結果變差:
W ⊆ W ′ ⇒ U t ( W ′ ) ≥ U t ( W ) . W\subseteq W'
\Rightarrow
U_t(W')\geq U_t(W). W ⊆ W ′ ⇒ U t ( W ′ ) ≥ U t ( W ) .
本文拒絕這個假設。
在長上下文模型中,無關內容、位置效應與累積歷史可能造成 reasoning degradation;近期研究亦持續測量 context rot 與長程任務中因歷史累積造成的效能下降。[2][3]
因此一般情況下:
W ⊆ W ′ ⇏ U t ( W ′ ) ≥ U t ( W ) . \boxed{
W\subseteq W'
\not\Rightarrow
U_t(W')\geq U_t(W).
} W ⊆ W ′ ⇒ U t ( W ′ ) ≥ U t ( W ) .
命題 1:上下文效用非單調命題
存在 W W W 與 m m m ,使得:
U t ( W ∪ { m } ) < U t ( W ) . U_t(W\cup\{m\})<U_t(W). U t ( W ∪ { m }) < U t ( W ) .
證明構想
令 m m m 為與當前任務高度詞彙相似、但已被更新版本取代的舊資訊。加入 m m m 後,模型可能在舊值與新值之間產生錯誤競爭,因此工作域增大而任務效用降低。
故上下文治理不能以:
max ∣ W ∣ \max |W| max ∣ W ∣
作為目標,而必須尋找:
max U t ( W ) \max U_t(W) max U t ( W )
subject to
C ( W ) ≤ B t . C(W)\leq B_t. C ( W ) ≤ B t .
4. 上下文污染量
令記憶物件 m m m 在時間 t t t 的污染向量為:
K t ( m ) = ( K t d u p , K t s t a l e , K t c o n f , K t b r a n c h , K t i r r , K t p r o v ) . \mathbf K_t(m)
=
(K_t^{dup},K_t^{stale},K_t^{conf},K_t^{branch},K_t^{irr},K_t^{prov}). K t ( m ) = ( K t d u p , K t s t a l e , K t co n f , K t b r an c h , K t i r r , K t p r o v ) .
分別表示:
重複污染;
過期污染;
衝突污染;
分支洩漏;
當下無關;
provenance 不足。
定義標量污染量:
K t ( m ) = ∑ i λ i K t ( i ) ( m ) , K_t(m)
=
\sum_i \lambda_iK_t^{(i)}(m), K t ( m ) = i ∑ λ i K t ( i ) ( m ) ,
其中:
λ i ≥ 0. \lambda_i\geq0. λ i ≥ 0.
對整個工作域:
K t ( W t ) = ∑ m ∈ W t K t ( m ) + ∑ i ≠ j κ t ( m i , m j ) , K_t(\mathcal W_t)
=
\sum_{m\in\mathcal W_t}K_t(m)
+
\sum_{i\neq j}\kappa_t(m_i,m_j), K t ( W t ) = m ∈ W t ∑ K t ( m ) + i = j ∑ κ t ( m i , m j ) ,
其中 κ t \kappa_t κ t 表示 pairwise interference,例如兩個互斥版本同時出現在工作域。
因此 context noise 不是只有單一物件自身的問題,也可能由物件之間的關係產生。
5. 動態工作集
定義記憶物件 m m m 的當下適格度為:
Ψ t ( m ) = α R t ( m ) + β D t ( m ) + γ P t ( m ) + δ V t ( m ) + ϵ Q t ( m ) − ζ K t ( m ) , \Psi_t(m)
=
\alpha R_t(m)
+\beta D_t(m)
+\gamma P_t(m)
+\delta V_t(m)
+\epsilon Q_t(m)
-\zeta K_t(m), Ψ t ( m ) = α R t ( m ) + β D t ( m ) + γ P t ( m ) + δ V t ( m ) + ϵ Q t ( m ) − ζ K t ( m ) ,
其中:
R t R_t R t :與當前任務的 relevance;
D t D_t D t :dependency necessity;
P t P_t P t :persistence value;
V t V_t V t :version validity;
Q t Q_t Q t :source / validation quality;
K t K_t K t :污染量。
則理論有效工作集定義為:
W t ∗ = arg max W ⊆ M t [ ∑ m ∈ W Ψ t ( m ) − Ω t ( W ) ] \mathcal W_t^*
=
\arg\max_{W\subseteq\mathcal M_t}
\left[
\sum_{m\in W}\Psi_t(m)
-\Omega_t(W)
\right] W t ∗ = arg W ⊆ M t max [ m ∈ W ∑ Ψ t ( m ) − Ω t ( W ) ]
subject to
C ( W ) ≤ B t C(W)\leq B_t C ( W ) ≤ B t
以及 dependency closure:
m ∈ W , d ( m j , m ) = 1 ⇒ m j ∈ W m\in W,\ d(m_j,m)=1
\Rightarrow
m_j\in W m ∈ W , d ( m j , m ) = 1 ⇒ m j ∈ W
或存在足以替代 m j m_j m j 的有效投影。
Ω t ( W ) \Omega_t(W) Ω t ( W ) 是集合級干擾成本。
這使工作集不再是單純 top- k k k retrieval,而是一個帶有依賴、版本與衝突限制的 constrained selection problem。
6. Admission 與 Retention 必須分離
新資訊進入工作域與舊資訊繼續停留在工作域,是兩種不同決策。
定義 admission threshold:
θ i n , \theta_{in}, θ in ,
以及 retention / eviction threshold:
θ o u t . \theta_{out}. θ o u t .
若單純使用同一閾值:
θ i n = θ o u t , \theta_{in}=\theta_{out}, θ in = θ o u t ,
則當 Ψ t ( m ) \Psi_t(m) Ψ t ( m ) 在臨界值附近震盪時,容易形成:
admit → evict → recall → evict → ⋯ \operatorname{admit}\rightarrow
\operatorname{evict}\rightarrow
\operatorname{recall}\rightarrow
\operatorname{evict}\rightarrow\cdots admit → evict → recall → evict → ⋯
本文稱之為 Context Thrashing 。
因此設定遲滯帶:
θ i n > θ o u t . \theta_{in}>\theta_{out}. θ in > θ o u t .
Admission rule:
m ∉ W t , Ψ t ( m ) ≥ θ i n ⇒ admit ( m ) . m\notin\mathcal W_t,
\quad
\Psi_t(m)\geq\theta_{in}
\Rightarrow
\operatorname{admit}(m). m ∈ / W t , Ψ t ( m ) ≥ θ in ⇒ admit ( m ) .
Retention rule:
m ∈ W t , Ψ t ( m ) > θ o u t ⇒ retain ( m ) . m\in\mathcal W_t,
\quad
\Psi_t(m)>\theta_{out}
\Rightarrow
\operatorname{retain}(m). m ∈ W t , Ψ t ( m ) > θ o u t ⇒ retain ( m ) .
Eviction rule:
m ∈ W t , Ψ t ( m ) ≤ θ o u t ⇒ evict ( m ) . m\in\mathcal W_t,
\quad
\Psi_t(m)\leq\theta_{out}
\Rightarrow
\operatorname{evict}(m). m ∈ W t , Ψ t ( m ) ≤ θ o u t ⇒ evict ( m ) .
這使單次小幅 relevance 波動不會立即觸發狀態切換。
7. 上下文震盪與遲滯穩定性
定義時間區間 [ t 0 , t 1 ] [t_0,t_1] [ t 0 , t 1 ] 內物件 m m m 的上下文切換次數:
N s w i t c h ( m ; t 0 , t 1 ) . N_{switch}(m;t_0,t_1). N s w i t c h ( m ; t 0 , t 1 ) .
總震盪率:
Γ t 0 : t 1 = ∑ m N s w i t c h ( m ; t 0 , t 1 ) t 1 − t 0 . \Gamma_{t_0:t_1}
=
\frac{
\sum_mN_{switch}(m;t_0,t_1)
}{t_1-t_0}. Γ t 0 : t 1 = t 1 − t 0 ∑ m N s w i t c h ( m ; t 0 , t 1 ) .
命題 2:遲滯抑制局部震盪命題
若:
θ i n − θ o u t = h > 0 \theta_{in}-\theta_{out}=h>0 θ in − θ o u t = h > 0
且單步適格度擾動滿足:
∣ Ψ t + 1 ( m ) − Ψ t ( m ) ∣ < h , |\Psi_{t+1}(m)-\Psi_t(m)|<h, ∣ Ψ t + 1 ( m ) − Ψ t ( m ) ∣ < h ,
則單一小擾動不能同時完成一次完整的 admit-evict 往返。
證明
若 m m m 由外部進入工作域,必有:
Ψ t ( m ) ≥ θ i n . \Psi_t(m)\geq\theta_{in}. Ψ t ( m ) ≥ θ in .
要在下一步被驅逐,必須:
Ψ t + 1 ( m ) ≤ θ o u t . \Psi_{t+1}(m)\leq\theta_{out}. Ψ t + 1 ( m ) ≤ θ o u t .
因此需要:
Ψ t ( m ) − Ψ t + 1 ( m ) ≥ θ i n − θ o u t = h , \Psi_t(m)-\Psi_{t+1}(m)
\geq
\theta_{in}-\theta_{out}
=h, Ψ t ( m ) − Ψ t + 1 ( m ) ≥ θ in − θ o u t = h ,
與假設矛盾。
故小於遲滯帶的單步擾動不足以形成完整往返。證畢。
這並不保證全域穩定,但提供一個最基本的 anti-thrashing 條件。
8. 安全驅逐與可恢復性
對任意:
m ∈ W t , m\in\mathcal W_t, m ∈ W t ,
若存在:
m ∈ D t m\in\mathcal D_t m ∈ D t
以及 canonical address:
a ( m ) , a(m), a ( m ) ,
且 restoration operator 滿足:
R ( a ( m ) , D t ) = m , R(a(m),\mathcal D_t)=m, R ( a ( m ) , D t ) = m ,
則可以定義:
evict s a f e ( m ) . \operatorname{evict}_{safe}(m). evict s a f e ( m ) .
定理 1:安全驅逐定理
若 canonical domain 在 [ t , t ′ ] [t,t'] [ t , t ′ ] 期間保持完整,且地址 a ( m ) a(m) a ( m ) 有效,則:
m ∉ W t + 1 m\notin\mathcal W_{t+1} m ∈ / W t + 1
不導致:
m ∉ M t + 1 . m\notin\mathfrak M_{t+1}. m ∈ / M t + 1 .
並且存在未來時間 t ′ > t t'>t t ′ > t ,使:
recall ( a ( m ) ) = m . \operatorname{recall}(a(m))=m. recall ( a ( m )) = m .
因此:
Active forgetting can coexist with lossless archival memory. \boxed{
\text{Active forgetting can coexist with lossless archival memory.}
} Active forgetting can coexist with lossless archival memory.
此定理就是 aggressive context cleaning 能安全成立的基礎。
9. 版本不是重複資料:Supersession Relation
長程記憶最危險的情況之一,是同一 predicate 在不同時間具有不同有效值。
例如:
m 1 = ( k = v 1 , t 1 ) , m_1=(k=v_1,t_1), m 1 = ( k = v 1 , t 1 ) ,
m 2 = ( k = v 2 , t 2 ) , m_2=(k=v_2,t_2), m 2 = ( k = v 2 , t 2 ) ,
且:
t 2 > t 1 . t_2>t_1. t 2 > t 1 .
若 m 2 m_2 m 2 明確取代 m 1 m_1 m 1 ,定義:
m 1 ≺ v m 2 . m_1\prec_v m_2. m 1 ≺ v m 2 .
≺ v \prec_v ≺ v 稱為 supersession relation。
近期 Supersede 工作顯示,bounded self-maintained memory 在事實更新情境中仍存在明顯的 stale-memory failure,而單純增加記憶容量不必然解決問題。[4] 因此 version freshness 應被視為獨立治理維度。
令某語義鍵 k k k 的所有版本為:
V ( k ) = { m 1 , … , m n } . V(k)=\{m_1,\ldots,m_n\}. V ( k ) = { m 1 , … , m n } .
若 ≺ v \prec_v ≺ v 在 V ( k ) V(k) V ( k ) 上形成有向無環偏序,定義 active head:
head t ( k ) = max ≺ v V t ( k ) . \operatorname{head}_t(k)
=
\max_{\prec_v}V_t(k). head t ( k ) = ≺ v max V t ( k ) .
對一般事實型 context,治理器預設只允許 active head 直接參與工作域:
W t ∩ V ( k ) = { head t ( k ) } , \mathcal W_t\cap V(k)
=
\{\operatorname{head}_t(k)\}, W t ∩ V ( k ) = { head t ( k )} ,
除非當前任務明確需要版本比較或歷史追蹤。
10. 版本頭唯一性命題
命題 3:版本頭唯一性
若 V ( k ) V(k) V ( k ) 上的 supersession relation 是有限 DAG,且所有不可比較的極大元素均被標記為 unresolved conflict 或 branch-specific state,則在任一已解決 branch 中存在唯一有效 active head。
說明
若存在兩個不同極大元素:
m i ≠ m j , m_i\neq m_j, m i = m j ,
且二者不可比較,系統不能任意把「較新時間戳」當作唯一真值,而應進入:
conflict ( m i , m j ) \operatorname{conflict}(m_i,m_j) conflict ( m i , m j )
或:
b ( m i ) ≠ b ( m j ) . b(m_i)\neq b(m_j). b ( m i ) = b ( m j ) .
因此 uniqueness 不是資料天然具有,而是由「偏序 + branch/conflict resolution」共同產生。
這避免系統把真正存在的分歧錯誤壓縮成單一結論。
11. Supersede 不等於 Delete
若:
m 1 ≺ v m 2 , m_1\prec_v m_2, m 1 ≺ v m 2 ,
治理行為應是:
supersede ( m 1 , m 2 ) , \operatorname{supersede}(m_1,m_2), supersede ( m 1 , m 2 ) ,
而不是:
delete ( m 1 ) . \operatorname{delete}(m_1). delete ( m 1 ) .
因為舊版本仍可能具有:
provenance value;
historical value;
debugging value;
causal reconstruction value;
branch recovery value。
因此:
Superseded from active context ≠ erased from canonical history . \boxed{
\text{Superseded from active context}
\neq
\text{erased from canonical history}.
} Superseded from active context = erased from canonical history .
在三域模型中,典型狀態轉換為:
m 1 : W → P / D , m_1:\mathcal W\rightarrow\mathcal P/\mathcal D, m 1 : W → P / D ,
m 2 : D → P → W . m_2:\mathcal D\rightarrow\mathcal P\rightarrow\mathcal W. m 2 : D → P → W .
12. 分支隔離
對每個 memory object 定義 branch label:
b ( m ) ∈ B . b(m)\in\mathcal B. b ( m ) ∈ B .
當前任務 branch 為:
b t ∗ . b_t^*. b t ∗ .
最簡單的 branch admission penalty 可寫成:
K t b r a n c h ( m ) = { 0 , b ( m ) = b t ∗ , λ b , b ( m ) ≠ b t ∗ and no bridge exists , λ b ( 1 − ρ b r i d g e ) , valid bridge exists . K_t^{branch}(m)
=
\begin{cases}
0,&b(m)=b_t^*,\\
\lambda_b,&b(m)\neq b_t^*\text{ and no bridge exists},\\
\lambda_b(1-\rho_{bridge}),&\text{valid bridge exists}.
\end{cases} K t b r an c h ( m ) = ⎩ ⎨ ⎧ 0 , λ b , λ b ( 1 − ρ b r i d g e ) , b ( m ) = b t ∗ , b ( m ) = b t ∗ and no bridge exists , valid bridge exists .
其中:
0 ≤ ρ b r i d g e ≤ 1. 0\leq\rho_{bridge}\leq1. 0 ≤ ρ b r i d g e ≤ 1.
橋接物件 g g g 必須記錄:
g = ( b i , b j , r , s c o p e , p r o v e n a n c e ) . g=(b_i,b_j,r,scope,provenance). g = ( b i , b j , r , sco p e , p r o v e nan ce ) .
亦即不能因為兩個分支詞彙相似,就自動融合。
13. 分支污染與橋接原則
命題 4:無橋接跨分支加入可以降低工作域效用
存在 branches b 1 , b 2 b_1,b_2 b 1 , b 2 及:
m 1 ∈ b 1 , m 2 ∈ b 2 , m_1\in b_1,
\quad
m_2\in b_2, m 1 ∈ b 1 , m 2 ∈ b 2 ,
使得在任務屬於 b 1 b_1 b 1 時:
U t ( W ∪ { m 2 } ) < U t ( W ) . U_t(W\cup\{m_2\})<U_t(W). U t ( W ∪ { m 2 }) < U t ( W ) .
因此跨 branch retrieval 需要比同 branch retrieval 更高的 admission evidence。
但 branch isolation 不能退化為完全封閉:若存在 dependency、method reuse 或明確 bridge,則:
b ( m ) ≠ b t ∗ b(m)\neq b_t^* b ( m ) = b t ∗
仍可能有:
Ψ t ( m ) ≥ θ i n . \Psi_t(m)\geq\theta_{in}. Ψ t ( m ) ≥ θ in .
故理論上應實施的是:
Isolation by default, connection by evidence. \boxed{
\text{Isolation by default, connection by evidence.}
} Isolation by default, connection by evidence.
而不是永久分割。
14. Conflict 與 Supersession 必須分開
兩個互斥資訊:
m i ⊥ m j m_i\perp m_j m i ⊥ m j
可能有至少三種語義:
m i ≺ v m j m_i\prec_v m_j m i ≺ v m j :舊版本被新版本取代;
b ( m i ) ≠ b ( m j ) b(m_i)\neq b(m_j) b ( m i ) = b ( m j ) :不同 branch 各自有效;
unresolved contradiction:尚不能判定哪一個成立。
因此 conflict classifier:
χ ( m i , m j ) ∈ { supersession , branch , unresolved } . \chi(m_i,m_j)
\in
\{
\operatorname{supersession},
\operatorname{branch},
\operatorname{unresolved}
\}. χ ( m i , m j ) ∈ { supersession , branch , unresolved } .
如果系統把三者全部視為 duplication,壓縮器就可能刪除必要資訊;若全部視為平等共存,又會污染工作域。
所以治理發生在 compression 之前與之後,而不是 compression 的附帶功能。
15. Recall 不等於 Search
令外部記憶中候選集合為:
C t ( q t ) . \mathcal C_t(q_t). C t ( q t ) .
搜尋只回答:
match ( m , q t ) . \operatorname{match}(m,q_t). match ( m , q t ) .
召回治理則必須回答:
admissible ( m ∣ S t ) . \operatorname{admissible}(m\mid S_t). admissible ( m ∣ S t ) .
因此召回函數應寫成:
Recall t ( q t ) = { m ∈ C t ( q t ) : Ψ t ( m ) ≥ θ i n } . \operatorname{Recall}_t(q_t)
=
\left\{
m\in\mathcal C_t(q_t):
\Psi_t(m)\geq\theta_{in}
\right\}. Recall t ( q t ) = { m ∈ C t ( q t ) : Ψ t ( m ) ≥ θ in } .
這意味:
Retrieved ≠ Admitted . \boxed{
\text{Retrieved}
\neq
\text{Admitted}.
} Retrieved = Admitted .
retriever 可以找到十個高度相關物件,governor 仍可能只允許其中兩個進入 W t \mathcal W_t W t 。
16. 缺失成本:清理也可能過度
治理不能只有污染成本,還必須考慮「該存在卻不在工作域」的缺失成本。
定義:
M t ( W t ) = ∑ m ∈ N t ∗ ∖ W t ω t ( m ) , M_t(\mathcal W_t)
=
\sum_{m\in\mathcal N_t^*\setminus\mathcal W_t}
\omega_t(m), M t ( W t ) = m ∈ N t ∗ ∖ W t ∑ ω t ( m ) ,
其中 N t ∗ \mathcal N_t^* N t ∗ 為當前任務真正需要的記憶集合。
因此治理目標不能只最小化:
K t ( W t ) . K_t(\mathcal W_t). K t ( W t ) .
否則最乾淨的上下文將退化為空集合。
更完整的目標是:
J t ( W t ) = K t ( W t ) + α M t ( W t ) + β C t ( W t ) + γ T t , J_t(\mathcal W_t)
=
K_t(\mathcal W_t)
+\alpha M_t(\mathcal W_t)
+\beta C_t(\mathcal W_t)
+\gamma T_t, J t ( W t ) = K t ( W t ) + α M t ( W t ) + β C t ( W t ) + γ T t ,
其中:
K t K_t K t :污染成本;
M t M_t M t :必要資訊缺失成本;
C t C_t C t :token / latency / compute cost;
T t T_t T t :狀態切換與重取成本。
治理器目標:
min W t J t ( W t ) . \boxed{
\min_{\mathcal W_t}J_t(\mathcal W_t).
} W t min J t ( W t ) .
17. Context Governor 的動態方程
令:
F t = C t ∘ L t ∘ E t ∘ G t , F_t
=
\mathcal C_t\circ\mathcal L_t\circ\mathcal E_t\circ\mathcal G_t, F t = C t ∘ L t ∘ E t ∘ G t ,
則:
M t + 1 = F t ( M t , q t ) . \mathfrak M_{t+1}=F_t(\mathfrak M_t,q_t). M t + 1 = F t ( M t , q t ) .
如果任務在一段期間內近似穩定:
q t + 1 ≈ q t , q_{t+1}\approx q_t, q t + 1 ≈ q t ,
我們希望工作域收斂到近似固定點:
W t + 1 ≈ W t . \mathcal W_{t+1}\approx\mathcal W_t. W t + 1 ≈ W t .
理想情況:
W ∗ = F ( W ∗ ) . \mathcal W^*=F(\mathcal W^*). W ∗ = F ( W ∗ ) .
這裡的固定點不是「永遠不變」,而是在任務狀態未顯著改變時,不應無原因持續清理與重新召回同一批資訊。
18. 治理穩定性
定義上下文距離:
d W ( W t , W t + 1 ) , d_W(\mathcal W_t,\mathcal W_{t+1}), d W ( W t , W t + 1 ) ,
可以由 weighted symmetric difference 表示:
d W ( A , B ) = ∑ m ∈ A △ B ω ( m ) . d_W(A,B)
=
\sum_{m\in A\triangle B}\omega(m). d W ( A , B ) = m ∈ A △ B ∑ ω ( m ) .
若任務變化量:
d q ( q t , q t + 1 ) → 0 , d_q(q_t,q_{t+1})\rightarrow0, d q ( q t , q t + 1 ) → 0 ,
而:
d W ( W t , W t + 1 ) d_W(\mathcal W_t,\mathcal W_{t+1}) d W ( W t , W t + 1 )
長期仍維持高值,則系統可能處於治理震盪。
定義局部穩定條件:對任意 ε > 0 \varepsilon>0 ε > 0 ,存在 δ > 0 \delta>0 δ > 0 ,使:
d q ( q t , q t + 1 ) < δ d_q(q_t,q_{t+1})<\delta d q ( q t , q t + 1 ) < δ
時有:
d W ( W t , W t + 1 ) < ε d_W(\mathcal W_t,\mathcal W_{t+1})<\varepsilon d W ( W t , W t + 1 ) < ε
在排除外部 canonical update 的條件下。
這提供未來 benchmark 一個比單純 recall accuracy 更重要的量:工作上下文是否在穩定任務下不必要地持續抖動。
19. Context Thrashing 與經典 Working Set 的差異
Denning 的 working-set 理論用 locality 管理 page residency 並研究 thrashing。[1][5]
本文借用的只是結構:
有限高成本工作空間 ↔ 較大外部空間 . \text{有限高成本工作空間}
\leftrightarrow
\text{較大外部空間}. 有限高成本工作空間 ↔ 較大外部空間 .
但 AI context thrashing 額外包含:
semantic recall thrashing;
branch switching;
version reactivation;
summary expansion / recompression;
tool-output reloading;
conflicting memory oscillation。
因此 AI 工作集不能只定義為最近使用窗口:
W t ≠ { m : recent ( m , t ) ≥ τ } . \mathcal W_t\neq
\{m:\operatorname{recent}(m,t)\geq\tau\}. W t = { m : recent ( m , t ) ≥ τ } .
它是任務條件化、版本條件化、依賴條件化的動態集合。
20. Governance Policy
治理器可抽象為 policy:
π G ( A t ∣ S t ) . \pi_G(A_t\mid S_t). π G ( A t ∣ S t ) .
它可以由:
deterministic rules;
learned policy;
contextual bandit;
reinforcement learning;
LLM judgment;
hybrid controller
實作。
近期 MemCon 已將 retrieve、plan injection、consolidate 與 forget 等操作建模為 context-dependent control policy,顯示這個問題可以從固定 heuristic 推進為 learned control。[6]
本文與此類工作並不衝突。TDCD 的目的不是指定唯一的 policy learner,而是定義 policy 必須治理的狀態結構與安全條件。
換言之:
TDCD specifies what must be governed; \boxed{
\text{TDCD specifies what must be governed;}
} TDCD specifies what must be governed;
a learned controller may decide how to govern it. \boxed{
\text{a learned controller may decide how to govern it.}
} a learned controller may decide how to govern it.
21. 治理安全不變量
為避免 autonomous governor 在清理時破壞長期記憶,提出以下 invariants。
Invariant A:Canonical Preservation
若物件尚未被明確授權永久刪除:
m ∈ D t ⇒ m ∈ D t + 1 m\in\mathcal D_t
\Rightarrow
m\in\mathcal D_{t+1} m ∈ D t ⇒ m ∈ D t + 1
或存在版本化 successor 能恢復其歷史狀態。
Invariant B:Address Preservation
若投影層提及 canonical object:
p ( m ) ∈ P t , p(m)\in\mathcal P_t, p ( m ) ∈ P t ,
則必須存在:
a ( m ) . a(m). a ( m ) .
Invariant C:Supersession Traceability
若:
m i ≺ v m j , m_i\prec_v m_j, m i ≺ v m j ,
則 canonical history 必須可回答:
why ( m i → m j ) . \operatorname{why}(m_i\rightarrow m_j). why ( m i → m j ) .
Invariant D:Branch Provenance
跨 branch 進入工作域的物件應保留來源:
b ( m ) , b(m), b ( m ) ,
不可在 merge 後失去其原始 scope。
Invariant E:Reversible Active Eviction
在正常清理模式中:
evict \operatorname{evict} evict
不得等價於:
destroy . \operatorname{destroy}. destroy .
22. MCP 在治理架構中的位置
MCP 2026-07-28 將 protocol core 改為 stateless request/response,並明確允許需要持久狀態的應用透過顯式 handle 自行管理跨呼叫狀態。[7]
因此 TDCD 的治理狀態不應寄生在 transport session 中。
更適合的結構是:
Agent / Context Governor ↔ MCP Bus ↔ Memory Services / Databases . \boxed{
\text{Agent / Context Governor}
\leftrightarrow
\text{MCP Bus}
\leftrightarrow
\text{Memory Services / Databases}.
} Agent / Context Governor ↔ MCP Bus ↔ Memory Services / Databases .
例如:
Governor → recall ( m e m o r y _ h a n d l e ) , \text{Governor}
\rightarrow
\operatorname{recall}(memory\_handle), Governor → recall ( m e m or y _ han d l e ) ,
Governor → expand ( c a n o n i c a l _ a d d r e s s ) , \text{Governor}
\rightarrow
\operatorname{expand}(canonical\_address), Governor → expand ( c an o ni c a l _ a dd r ess ) ,
Governor → store ( s n a p s h o t _ h a n d l e ) . \text{Governor}
\rightarrow
\operatorname{store}(snapshot\_handle). Governor → store ( s na p s h o t _ han d l e ) .
MCP 負責能力暴露與傳輸; G \mathcal G G 負責狀態判斷。
23. 可觀測量與 Benchmark
若 TDCD 只能提出抽象概念而沒有量測方式,就無法成為可驗證理論。
因此提出第一組治理指標。
23.1 Active Context Precision
A C P = ∣ W t ∩ N t ∗ ∣ ∣ W t ∣ . ACP
=
\frac{|\mathcal W_t\cap\mathcal N_t^*|}{|\mathcal W_t|}. A C P = ∣ W t ∣ ∣ W t ∩ N t ∗ ∣ .
衡量目前上下文有多少內容真正需要。
23.2 Active Context Recall
A C R = ∣ W t ∩ N t ∗ ∣ ∣ N t ∗ ∣ . ACR
=
\frac{|\mathcal W_t\cap\mathcal N_t^*|}{|\mathcal N_t^*|}. A C R = ∣ N t ∗ ∣ ∣ W t ∩ N t ∗ ∣ .
衡量必要資訊有多少已在工作域。
23.3 Stale Activation Rate
S A R = N s t a l e − a c t i v e N v e r s i o n e d − a c t i v e . SAR
=
\frac{N_{stale-active}}{N_{versioned-active}}. S A R = N v er s i o n e d − a c t i v e N s t a l e − a c t i v e .
衡量已被 supersede 的資訊錯誤進入 active context 的比例。
23.4 Branch Leakage Rate
B L R = N u n j u s t i f i e d − c r o s s − b r a n c h N a c t i v e . BLR
=
\frac{N_{unjustified-cross-branch}}{N_{active}}. B L R = N a c t i v e N u nj u s t i f i e d − cr oss − b r an c h .
23.5 Restoration Fidelity
若原始 bytes 為 x x x ,恢復結果為 x ^ \hat x x ^ :
R F = Pr [ H ( x ) = H ( x ^ ) ] . RF
=
\Pr[H(x)=H(\hat x)]. R F = Pr [ H ( x ) = H ( x ^ )] .
理想 canonical restoration:
R F = 1. RF=1. R F = 1.
23.6 Context Thrashing Rate
C T R = N a d m i t + N e v i c t + N r e c a l l T . CTR
=
\frac{N_{admit}+N_{evict}+N_{recall}}{T}. C T R = T N a d mi t + N e v i c t + N r ec a l l .
需與任務狀態變化量共同解讀。
23.7 Governance Cost
G C = C r e t r i e v a l + C c o m p r e s s i o n + C L L M − j u d g m e n t + C t r a n s f e r + C l a t e n c y . GC
=
C_{retrieval}
+C_{compression}
+C_{LLM-judgment}
+C_{transfer}
+C_{latency}. GC = C r e t r i e v a l + C co m p r ess i o n + C LL M − j u d g m e n t + C t r an s f er + C l a t e n cy .
最終系統不能以節省 prompt tokens 為名,產生更高的隱藏治理成本。
24. Governance Frontier
上下文治理存在至少四個互相競爭的目標:
O t = ( task utility , fidelity , cost , stability ) . \mathbf O_t
=(
\text{task utility},
\text{fidelity},
\text{cost},
\text{stability}
). O t = ( task utility , fidelity , cost , stability ) .
一般不存在單一設定同時最大化全部維度。
例如 aggressive eviction 可以降低 token cost,但可能提高 recall latency;保留大量版本可以提高 auditability,卻降低 active context precision。
因此合理系統追求的是 Pareto frontier:
F G = Pareto ( U , R F , − G C , − C T R ) . \mathcal F_G
=
\operatorname{Pareto}
(U,RF,-GC,-CTR). F G = Pareto ( U , R F , − GC , − C T R ) .
這也意味不同任務應具有不同 governor profile,而不是一組通用固定閾值。
25. 最小治理循環
本文最小可執行治理循環如下:
Observe → Score → Admit/Evict → Resolve Version → Check Branch → Execute → Archive → Re-evaluate . \boxed{
\text{Observe}
\rightarrow
\text{Score}
\rightarrow
\text{Admit/Evict}
\rightarrow
\text{Resolve Version}
\rightarrow
\text{Check Branch}
\rightarrow
\text{Execute}
\rightarrow
\text{Archive}
\rightarrow
\text{Re-evaluate}.
} Observe → Score → Admit/Evict → Resolve Version → Check Branch → Execute → Archive → Re-evaluate .
以三域表示:
D t → Π P t → G W t → interaction Δ t → canonicalize D t + 1 . \mathcal D_t
\xrightarrow{\Pi}
\mathcal P_t
\xrightarrow{\mathcal G}
\mathcal W_t
\xrightarrow{\text{interaction}}
\Delta_t
\xrightarrow{\text{canonicalize}}
\mathcal D_{t+1}. D t Π P t G W t interaction Δ t canonicalize D t + 1 .
再由:
D t + 1 → P t + 1 → W t + 1 \mathcal D_{t+1}
\rightarrow
\mathcal P_{t+1}
\rightarrow
\mathcal W_{t+1} D t + 1 → P t + 1 → W t + 1
形成閉環。
26. 本文的主要理論結果
本文得到以下結論。
第一:
Context utility is generally non-monotonic in context size. \boxed{
\text{Context utility is generally non-monotonic in context size.}
} Context utility is generally non-monotonic in context size.
因此「能塞更多」不等價於「應塞更多」。
第二:
Eviction from W ≠ deletion from D . \boxed{
\text{Eviction from }\mathcal W
\neq
\text{deletion from }\mathcal D.
} Eviction from W = deletion from D .
只要 canonical restoration 成立,工作域可以積極清理。
第三:
Version management is a partial-order problem, not a deduplication problem. \boxed{
\text{Version management is a partial-order problem, not a deduplication problem.}
} Version management is a partial-order problem, not a deduplication problem.
第四:
Branch isolation should be default; cross-branch linking requires evidence. \boxed{
\text{Branch isolation should be default; cross-branch linking requires evidence.}
} Branch isolation should be default; cross-branch linking requires evidence.
第五:
θ i n > θ o u t \boxed{
\theta_{in}>\theta_{out}
} θ in > θ o u t
提供一個簡單但重要的 anti-thrashing mechanism。
第六:
Retrieval produces candidates; governance produces active context. \boxed{
\text{Retrieval produces candidates; governance produces active context.}
} Retrieval produces candidates; governance produces active context.
27. 結論
長期記憶系統真正困難的地方,不只是如何儲存更多資訊,也不是如何把更多歷史壓縮進有限 token window。
真正的問題是:
What belongs in the present? \boxed{
\text{What belongs in the present?}
} What belongs in the present?
本文因此把 TDCD 的核心控制層形式化為 Context Governor,並把工作域視為一個持續變化的 semantic working set。
完整系統不是:
Memory → Search → Prompt . \text{Memory}
\rightarrow
\text{Search}
\rightarrow
\text{Prompt}. Memory → Search → Prompt .
而是:
Canonical Memory → Projection → Governance → Working Set → Execution → Canonical Update . \boxed{
\text{Canonical Memory}
\rightarrow
\text{Projection}
\rightarrow
\text{Governance}
\rightarrow
\text{Working Set}
\rightarrow
\text{Execution}
\rightarrow
\text{Canonical Update}.
} Canonical Memory → Projection → Governance → Working Set → Execution → Canonical Update .
其最核心的治理原則可以濃縮為:
記憶的安全保存,使上下文可以勇敢地清理; \boxed{
\text{記憶的安全保存,使上下文可以勇敢地清理;}
} 記憶的安全保存,使上下文可以勇敢地清理;
上下文的持續清理,使長期記憶真正變得可用。 \boxed{
\text{上下文的持續清理,使長期記憶真正變得可用。}
} 上下文的持續清理,使長期記憶真正變得可用。
因此,對長程 AI 而言,理想狀態不是永遠記住所有事情,而是:
完整地保存過去,選擇性地形成現在,必要時精確地重新展開。 \boxed{
\text{完整地保存過去,選擇性地形成現在,必要時精確地重新展開。}
} 完整地保存過去,選擇性地形成現在,必要時精確地重新展開。
參考文獻
[1] Denning, P. J. (1968). The Working Set Model for Program Behavior . Communications of the ACM, 11(5), 323–333. DOI: 10.1145/363095.363141.
[2] Positional Failures in Long-Context LLMs: A Blind Spot in Reasoning Benchmarks . arXiv:2605.23170, 2026.
[3] Diagnosing and Mitigating Context Rot in Long-horizon Search . arXiv:2606.29718, 2026.
[4] Patel, V. (2026). Supersede: Diagnosing and Training the Memory-Update Gap in LLM Agents . arXiv:2606.27472.
[5] Denning, P. J. (1968). Thrashing: Its Causes and Prevention . AFIPS Fall Joint Computer Conference.
[6] Jiang, E. H., Zhang, Z., Wu, Y., et al. (2026). Memory as a Controlled Process: Learned Adaptive Memory Management for LLM Agents . arXiv:2607.13591.
[7] Model Context Protocol Core Maintainers. (2026). The 2026-07-28 Specification .