Community程式設計與開發github.com

壓縮控制剖析

此技能用於針對特定模型與工作負載,判斷應由框架還是模型控制壓縮,並透過量測來驗證或校準此選擇。

壓縮控制剖析 是什麼?

此技能旨在解決自主壓縮代理設計前的一個關鍵決策:對於特定模型與工作負載,應由框架還是模型來決定何時及如何壓縮上下文?答案需要透過量測而非假設來獲得。跨模型研究顯示,不同模型在同一壓縮介面與指令下表現差異極大,有的模型在緊湊預算下分數幾乎翻三倍,有的則只在少數任務中呼叫介面,直到預算充裕才追上框架基準線。技能涵蓋完整的評估框架:上下文預算掃描(比較框架驅動與模型驅動壓縮)、行為剖析(介面採用率、每次呼叫壓縮比、歸檔內容重新開啟率、首次壓縮時上下文填充程度、對壓力警告的反應),以及時序指令校準。此外,還提供可逆的崩潰與歸檔介面設計原則,並要求在模型或提示變更後重新驗證。支援的平台包括 Claude Code、Cursor、Codex 等具備壓縮介面的代理框架。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/tree/main/skills/compaction-control-profiling

Installed? Explore more 程式設計與開發 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

壓縮控制剖析 是做什麼的?

此技能涵蓋在任何自我壓縮代理設計之前必須做出的決定:對於此模型與此工作負載,應由框架還是模型決定何時及壓縮什麼?答案需透過量測而非假設。在一項跨模型研究中,四種當前模型獲得相同的壓縮介面與一組指令,其中一個模型在緊湊的上下文預算下分數幾乎翻了三倍,而另一個模型僅在少數任務中呼叫該介面,且直到預算充裕才追上框架基準線(claim-compaction-control-tight-budget-gain, claim-compaction-control-uptake-variance)。

操作規則:將壓縮控制視為一個模型在一個上下文壓力下、一個提示下的屬性。該研究觀察到結果隨模型、預算甚至一個時序句子的變化而改變。它並未測試模型版本或替代措辭,因此在這些變更後重新驗證是此技能添加的預防措施,而非已量測的結果。使用預算掃描與行為剖析來驗證模型,校準時序指令,為每個模型與壓力區間分配控制權,並在模型或提示變更時重新驗證。

啟動時機

在以下情況啟動此技能:

  • 為特定模型與工作負載,在框架閾值、模型呼叫的壓縮介面或混合方案之間做出選擇
  • 將新模型、模型版本或系統提示導入一個向模型暴露壓縮功能的框架時
  • 設計一個比較不同上下文預算下壓縮策略的實驗
  • 一個擁有壓縮介面的代理從不呼叫它、在低填充時呼叫、或在收到上下文即將填滿的警告時直接返回答案
  • 校準壓縮時序指令或上下文壓力警告的措辭
  • 指定可逆壓縮介面的遙測:範圍崩潰、歸檔原件、按標籤檢索
  • 檢查使用了較少 token 的執行是否更便宜

不要為其他技能負責的相鄰工作啟動此技能:

  • 建構自我編輯框架(將上下文視為可編輯檔案及其不變量)、編輯位置快取成本,以及訓練上下文編輯策略:self-managed-context。此技能決定模型是否符合該控制資格及應使用哪些設定。
  • 崩潰時摘要必須保留的內容:context-compression。
  • 框架端閾值策略、遮罩與快取穩定佈局:context-optimization。
  • 診斷長上下文內部輸出品質下降的原因:context-degradation。
  • 通用評估設計、評分標準與回歸測試套件:evaluation。
  • 基於任務簡報而非上下文警告的提前停止:long-horizon-prompting。

核心概念

控制是每個模型的屬性

從四個維度同時解讀模型的壓縮行為,絕不單獨看一個:是否呼叫介面、每次呼叫移除多少內容、是否回頭取回已移除的內容、以及何時開始。獲得相同介面的模型在這四個維度上表現各異(claim-compaction-control-uptake-variance, claim-compaction-control-compression-reopen, claim-compaction-control-context-anxiety)。在該研究中,三個使用介面的模型採用率相似,但它們的收益卻不同;收益最大的模型每次收縮幅度最大且重新開啟率最高。採用率本身並非目標。

下表是根據這些結果得出的操作規則。該研究觀察到了這些信號,但並未測試這些行動。

信號解讀行動
低採用率,分數在緊湊預算下等於或低於框架基準線模型拒絕控制保持框架驅動,或使用帶有框架備援的混合方案
低採用率,任務在時序閾值以下結束從不需要壓縮非失敗;對此任務來說預算寬裕
首次壓縮遠低於指示閾值,或在無指示時於低填充時進行上下文焦慮比較有大和無時序下限的大型預算下的準確度。在早期壓縮影響準確度的地方添加或提高下限;在準確度不受影響的地方,下限可選
加入時序指令後採用率崩潰指令可能抑制了使用檢查這些任務是否到達警告或備援;如果是,降低閾值或將下限與明確的行動期望配對
每次呼叫大幅收縮且重新開啟率高攻擊性強,透過歸檔恢復可接受;計算用於重新開啟的 token 數
每次呼叫大幅收縮,重新開啟率低,分數下降狀態遺失且未恢復需要更豐富的摘要;將摘要內容路由到 context-compression
首次壓力警告以返回答案解決警告被解讀為停止信號重新措辭警告,將壓縮指定為預期行動

上下文壓力決定回報

在選擇策略之前,先估算上下文壓力,即任務所需內容與視窗容量的比率。在壓力高的地方,委派控制能帶來回報:最顯著的收益出現在緊湊預算下,並隨著預算增長而縮小;而唯一落後於框架基準線的模型直到大預算才追上。在第二個基準測試中(作者認為其任務所需上下文遠少),效果小得多且僅限於最緊湊的預算(claim-compaction-control-tight-budget-gain, claim-compaction-control-low-demand-benchmark)。當無限制的執行在視窗內達到峰值時,保持框架策略:委派幾乎沒有什麼可買,而焦慮的模型只會遺失狀態。

預算掃描

使用掃描而非單一預算來驗證模型,因為策略的排名會隨壓力變化。在同一框架、模型、工具、任務和評分器上,對一個階梯式的硬性上下文預算(涵蓋任務的自然峰值)執行兩種策略(claim-compaction-control-study-setup)。

條件定義
框架驅動在預算的固定比例下,框架總結較早的歷史,並保留初始指令和固定數量的近期事件(逐字)
模型驅動模型獲得壓縮介面、即時使用量讀數、時序指令和接近限制時的壓力警告
溢位備援,兩種條件超出硬性預算的請求會丟棄最舊的事件並重試;在固定次數失敗後,任務計為失敗

縮減預算代表更長的任務。這是一個代理,而使執行在最小預算下存活的備援本身也是一種可能影響分數的上下文策略。

行為剖析

每個預算記錄五個指標。定義遵循研究,以便結果與之保持可比性。

指標定義區分什麼
採用率至少進行一次壓縮呼叫的任務比例使用控制 vs 拒絕控制
壓縮因子模型決定壓縮的請求的輸入 token 數,除以下一個請求的輸入 token 數攻擊性 vs 謹慎呼叫;小於 1 表示上下文增長
重新開啟率其歸檔事件後來被檢索的壓縮呼叫比例恢復的狀態 vs 不需要或遺失的狀態;是一個下限
首次壓縮填充任務中首次壓縮呼叫時正在使用的預算比例;任務間的中位數及時 vs 焦慮
警告解決從首次壓力警告到片段結束:返回答案、立即壓縮、閱讀介面文件後壓縮、檢查歷史後壓縮、其他壓縮 vs 收尾

上下文焦慮與時序指令

為每個模型雙向校準時序指令。上下文焦慮是在仍有充足空間時開始的壓縮。在僅在高使用率閾值以上考慮壓縮的指令下,研究中的大多數模型會等到接近該閾值。沒有該指令時,兩個模型在不到一半預算時就開始壓縮,並且在大預算下得分低於框架基準線;第三個模型(幾乎從不帶指令壓縮)則早期且規律地壓縮(claim-compaction-control-context-anxiety)。因此,時序指令是一個可能在兩個方向出錯的每模型旋鈕:缺少時,一些模型過度壓縮;存在時,研究中的一個模型幾乎停止了壓縮。該研究報告該模型的準確度無論如何都沒有變化,因此將抑制的採用率視為需要調查的信號,而非已證明的損失。早期壓縮的一個假設原因是訓練懲罰長 rollout(claim-compaction-control-rollout-penalty)。將原因視為推測,將行為視為可量測。早期壓縮是信號;其準確度成本是單獨的量測,而研究發現三個早期壓縮模型中的兩個存在此成本。

可逆崩潰是測試中的介面

針對壓縮可逆的介面進行剖析:模型用其編寫的摘要替換帶有標籤的事件範圍,框架歸檔原件,且任何歸檔事件均可透過其原始標籤檢索(claim-compaction-control-reference-interface)。可逆性使得激進的壓縮可以被安全允許,並且一旦框架記錄每次讀取歸檔事件,成本就變得可觀察。參考框架本身並不記錄這些讀取;研究是從追蹤中計數的。僅刪除的介面會在重複的工具呼叫中隱藏相同的損失。

保持量測乾淨的介面屬性:

  • 標籤在轉錄本中穩定且可見;摘要承載其範圍標籤和一行檢索提示。
  • 與現有摘要重疊的崩潰會合併為一個摘要;重寫摘要是一個明確的操作,而非副作用。
  • 介面文件簡短且可按需存取。一個模型在大多數首次警告片段中在壓縮前閱讀了它(claim-compaction-control-warning-response);每次查詢都是在壓力下花費的完整上下文回合。
  • 使用量讀數的刷新頻率至少與模型被期望採取行動的頻率相同。每幾個回合刷新一次的讀數會使首次壓縮填充量測到的是刷新頻率。
  • 每次崩潰記錄其範圍、之前和之後的 token 數以及填充。每個可能返回歸檔事件的讀取路徑(按標籤查找、索引存取、歷史查詢)都會記錄一次重新開啟。

Token 不是成本

以重新計算的 token 而非僅發送的 token 來評估壓縮策略的成本。模型驅動的執行可以用更少的累積輸入 token 達到相同或更好的準確度(claim-compaction-control-token-savings),但累積輸入會計入每個回合的每個輸入 token,無論是否快取。在前綴快取下,編輯會使之後的所有內容失效,因此較短的上下文並非自動更便宜。一個重用未更改後綴快取狀態的服務原型,在響應較大的後綴時,減少了每個請求的預填充,且無可量測的準確度變化(claim-compaction-control-suffix-kv-reuse)。報告 token 數,並在服務堆疊可觀察時報告預填充計算量。將編輯位置與後綴重用機制路由到 self-managed-context。

實用指南

驗證工作流程

  1. 估算壓力。以最大可用預算執行任務集,並記錄每個任務的峰值和累積上下文。
  2. 固定比較。對兩種策略使用相同的框架、模型、工具、任務和評分器。記錄框架閾值和保留規則,以及模型驅動的介面文件、讀數、時序指令和警告文字。對提示文字進行版本控制;它是結果的一部分。
  3. 掃描預算。使用涵蓋步驟 1 中自然峰值的幾何階梯式硬性請求限制,並至少包含兩個低於它的梯級。定義溢位備援,計算其觸發次數,並將錯誤計為失敗。
  4. 複製每個單元格並報告分佈。將分佈內的差異視為無差異。
  5. 記錄每個預算的行為剖析。切勿跨預算匯總時序指標。
  6. 在一個緊湊和一個寬鬆的預算下消融時序指令:有它、沒有它、以及如果採用率崩潰則以第二個閾值進行。
  7. 使用信號表進行分類,並為每個模型和壓力區間分配控制權。
  8. 以累積輸入 token 評估成本,並在服務可觀察時以預填充計算量評估。
  9. 記錄分配結果,包含模型版本和提示表面的雜湊值。當任一項更改時重新驗證。

控制分配

這些分配(包括混合分層)是從研究結果得出的設計推論。該研究分別比較了兩種策略,並未將它們作為干預措施進行測試。

區間剖析分配
低壓力任意框架閾值作為後盾;如果介面被暴露,保持時序下限以防止焦慮模型進行不必要的壓縮
高壓力在閾值附近呼叫介面並恢復所需內容模型驅動,保留溢位備援
高壓力拒絕控制或在警告時收尾框架驅動,或一旦重新措辭的警告恢復採用率後使用混合方案
任意在無時序指令時早期壓縮模型驅動,並在校準的時序下限下,在早期壓縮影響大預算準確度時使用;在準確度不受影響時,下限可選,且額外的編輯改為計價

對於混合方案,按順序排列觸發條件以防止競態:模型的時序閾值低於壓力警告,警告低於框架備援閾值,備援低於硬性限制。框架僅在模型拒絕行動時才行動。在每個預算下檢查該順序:在緊湊預算下,一個大的工具輸出佔據視窗的很大一部分,這可能將警告和備援推低到以預算比例校準的下限以下。降低下限、限制工具輸出大小,或在該預算下僅執行單一策略。

措辭

…(後續內容因翻譯限制被截斷)

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

advanced-evaluation

This skill should be used for advanced LLM evaluation: LLM-as-judge systems, direct scoring, pairwise comparison, rubric calibration, evaluator bias mitigation, confidence scoring, and automated quality assessment.

bdi-mental-states

This skill should be used when modeling agent mental states with BDI concepts: beliefs, desires, intentions, RDF-to-belief transformations, rational agency traces, cognitive agents, BDI ontologies, and neuro-symbolic AI integration.

book-sft-pipeline

This skill should be used for book-to-SFT pipelines: ePub extraction, literary segmentation, author-voice dataset construction, style-transfer training, LoRA workflows, and model evaluation for voice replication.

comprehensive-research-agent

Ensure thorough validation, error recovery, and transparent reasoning in research tasks with multiple tool calls

context-compression

This skill should be used when long-running agent sessions need context compression, structured summarization, compaction, token-per-task optimization, or durable handoff summaries that preserve decisions, files, risks, and next actions.

context-degradation

This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion, attention-pattern issues, and agent performance degradation caused by accumulated or conflicting context.

context-fundamentals

This skill should be used to explain or reason about the foundational concepts of context engineering: what context is, the anatomy of a context window, how attention mechanics work, the U-shaped attention curve, why context quality matters more than quantity, and the mental models needed to interpret every other context-engineering decision. Use this for conceptual explanation, onboarding, and background reading. Route operational work to the specialized skills: debugging attention failures goes to context-degradation, token-efficiency work goes to context-optimization, conversation summarization goes to context-compression, and project-shape decisions go to project-development.

context-optimization

This skill should be used for improving context efficiency: context budgeting, observation masking, prefix or KV-cache strategy, partitioning, token-cost reduction, retrieval scoping, and extending effective context capacity without lowering answer quality.

evaluation

This skill should be used when building agent evaluation systems: deterministic checks, regression suites, multi-dimensional rubrics, quality gates, production monitoring, baseline comparison, and outcome measurement for agent pipelines.

filesystem-context

This skill should be used when agent work needs file-backed context: durable scratchpads, tool-output offloading, just-in-time discovery, cross-agent handoff files, filesystem memory, or cleanup policies for context stored outside the prompt.

harness-engineering

This skill should be used when designing autonomous agent harnesses: research loops, evaluation scaffolds, locked and editable surfaces, durable logs, novelty gates, pruning, rollback, PR preparation, and human approval boundaries.

hosted-agents

This skill should be used when designing hosted or background agent infrastructure: sandboxed execution, remote coding environments, warm pools, session persistence, multiplayer collaboration, self-spawning agents, or Modal-style sandboxes.

instruction-surface-security

Hardens agent runtimes against persistent prompt injection or unauthorized changes to instructions and permissions. Use to audit what agents auto-load, design reviewed activation for project rules, skills, memory, or tool configuration, and test whether trust boundaries hold after reload, restart, or delegation.

latent-briefing

This skill should be used when the user asks to "share memory between agents", "KV cache compaction for multi-agent", "orchestrator worker context", "latent briefing", "reduce worker tokens", "cross-agent memory without summarization", or discusses Attention Matching compaction, recursive language models with workers, or token explosion in hierarchical agents.

long-horizon-prompting

This skill should be used when writing, enhancing, or evaluating the launch prompt for a long-running autonomous agent or a parallel multi-agent orchestration attacking a hard problem: pseudo-formal task briefs that define terms and an exact success predicate linguistically, enumerate non-counting outcomes, set persistence rules with explicit stop and return conditions and effort floors, manage a diverse portfolio of parallel approaches with an approach registry and blocked-route bookkeeping, and gate the return on adversarial audit. Route agent topology and coordination protocols to multi-agent-patterns, runtime control surfaces and loop governance to harness-engineering, evaluator and quality-gate construction to evaluation, judge design to advanced-evaluation, and compaction or memory mechanics to context-compression and memory-systems.

memory-systems

This skill should be used for persistent semantic memory in agent systems: cross-session knowledge retention, entity tracking, temporal validity, graph or vector retrieval, memory consolidation, and memory benchmark selection. Route file-backed scratchpads to filesystem-context, handoff summaries to context-compression, and token-efficiency tactics to context-optimization.

multi-agent-patterns

This skill should be used when designing multi-agent systems that need context isolation, supervisor or swarm coordination, explicit handoffs, parallel execution, or a decision on whether multiple agents are justified.

project-development

This skill should be used for project-level decisions about LLM-powered systems: whether an LLM is the right primitive for the task at hand, the shape of a multi-stage batch or agent pipeline, token and cost estimation, choosing between single-agent and multi-agent at the project level, structured output design for downstream parsing, and structuring agent-assisted iteration. Use this when the unit of work is a whole project or a multi-stage pipeline. Route individual tool design to tool-design and individual skill-loading or context-budget tactics to context-optimization.

self-improvement-loops

This skill should be used when the harness, scaffold, workflow, or optimizer itself is the optimization target: recursive self-improvement (RSI) loops, meta-harnesses, self-improving harnesses that mine their own failures and propose bounded edits, evolutionary or population-based search over agent scaffolds, acceptance gates for self-modifying systems, and agentic context evolution where the mechanism that produces context is versioned and evolved. Route governance of a single autonomous loop (locked surfaces, durable logs, rollback, novelty gates, approval boundaries) to harness-engineering, measurement and quality-gate design to evaluation, judge design to advanced-evaluation, and remote sandbox infrastructure to hosted-agents.

self-managed-context

This skill should be used when a model gets read-write control over its own live context window instead of a harness-scheduled compaction policy: the context exposed as an editable file the model rewrites with code tools, model-driven eviction and in-place updates, the harness invariants that keep self-editing safe (pinned prefix, edit gate, edit receipts, budget readouts, rollback on overflow), the prefix-cache cost of mid-context edits, and steering or training the model's own context-editing strategy. Route note content and fixed-threshold summarization to context-compression, cache-stable layout under harness control to context-optimization, file offloading to filesystem-context, and loop governance to self-improvement-loops.

相關技能