Community编程与开发github.com

压缩控制分析

该技能用于决定针对特定模型和工作负载,是由框架还是模型控制压缩,并通过测量(上下文预算扫描、行为分析、定时校准等)来验证该选择。

压缩控制分析 是什么?

该技能旨在解决自主压缩代理设计的前置决策问题:针对特定模型和负载,压缩的时机和方式应由框架还是模型自主决定?答案需通过测量而非假设获得。一项涉及四种模型的交叉研究表明,在严格上下文预算下,某模型使用压缩接口后得分几乎翻倍,而另一模型仅在少数任务中调用接口,表现落后于框架基线。技能核心操作规则包括:通过预算扫描和模型行为分析(接口调用率、压缩因子、恢复率、首次压缩填充率等)对模型进行资格认证;校准定时指令以消除上下文焦虑(过早压缩)或抑制压缩行为;使用可逆压缩接口(归档原始内容并支持按标签检索)确保安全;以累积输入令牌和前导计算成本而非简单令牌数量评估代价。技能明确了分配条件:在高压力下调用接口并有效恢复状态的模型,赋予自主控制权;反之保留框架控制或使用混合策略。每次模型或提示变更后需重新认证。

兼容平台~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)。

操作规则:将压缩控制视为特定模型在特定上下文压力下、在特定提示下的属性。该研究发现,不同模型、不同预算以及仅一条定时指令的变化都能改变结果。该研究未测试模型版本或替代措辞,因此在上述变更发生时重新认证是本技能增加的一项预防措施,而非测得的结果。通过预算扫描和行为分析对模型进行资格认证,校准定时指令,根据模型和压力机制分配控制权,并在模型或提示发生变更时重新认证。

何时激活

在以下情况下激活此技能:

  • 为特定模型和工作负载选择框架阈值、模型调用压缩接口或混合方案
  • 将新模型、模型版本或系统提示接入暴露压缩功能给模型的框架
  • 设计比较不同上下文预算下压缩策略的实验
  • 拥有压缩接口的代理从未调用该接口、在低填充率时调用,或在收到上下文填充警告时直接返回答案
  • 校准压缩定时指令或上下文压力警告的措辞
  • 指定可逆压缩接口的遥测:范围折叠、归档原始内容、按标签检索
  • 检查消耗更少令牌的运行时服务成本是否更低

不要将此技能用于其他技能负责的相邻工作:

  • 构建自编辑框架(将上下文视为可编辑文件及其相关不变量)、编辑位置缓存成本,以及训练上下文编辑策略: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)。在该研究中,使用接口的三个模型的使用率相似,但收益却不同;获益最大的模型每次压缩的收缩量最大且恢复率最高。仅关注使用率并非目标。

下表是根据这些结果得出的操作规则。该研究观察到了这些信号,但未测试相应的行动。

信号解读行动
使用率低,在严格预算下得分等于或低于框架基线模型正在拒绝控制权保持框架驱动,或带框架兜底的混合方案
使用率低,任务在定时阈值之前结束从未需要压缩非失败;对于此任务而言预算较为宽松
首次压缩远低于指定阈值,或在无指令时在低填充率下开始上下文焦虑在较大预算下比较有无定时下限的准确性。在早期压缩会损害准确性的地方添加或提高下限;在准确性不受影响的地方,下限是可选的
添加定时指令后使用率骤降指令可能抑制了使用检查这些任务是否到达了警告或兜底机制;如果是,则降低阈值,或将下限与明确的行动期望配对
每次压缩收缩量大,且恢复率高激进的压缩,通过归档恢复可接受;统计重读已归档内容消耗的令牌
每次压缩收缩量大,恢复率低,得分下降状态丢失且未能恢复需要更丰富的摘要;将摘要内容路由至 context-compression
第一次压力警告被处理为返回一个答案警告被解读为停止信号改写警告,将压缩列为预期行动

上下文压力决定收益

在选择策略前,估算上下文压力,即任务所需内容与窗口容量之比。在压力较高的情况下,委托控制权能带来收益:最大的增益出现在严格预算下,并随着预算增长而缩小;一个落后于框架基线的模型仅在较大预算下才能追平。在第二个基准测试中(其任务所需上下文远小于前者),效果小得多且仅限于最严格的预算(claim-compaction-control-tight-budget-gain, claim-compaction-control-low-demand-benchmark)。当无约束运行的峰值远在窗口之内时,保持框架策略:委托控制权几乎没有收益,而焦虑的模型只会丢失状态。

预算扫描

通过扫描而非单一预算对模型进行资格认证,因为策略的排名会随压力变化。在相同框架、模型、工具、任务和评分器上,对一系列硬性上下文预算(应覆盖任务的自然峰值)运行两种策略(claim-compaction-control-study-setup)。

条件定义
框架驱动在预算的固定比例处,框架总结早期历史,并逐字保留初始指令和固定数量的最近事件
模型驱动模型接收压缩接口、实时使用读数、定时指令以及在接近限制时的压力警告
溢出兜底机制(两种条件均适用)超出硬性预算的请求会丢弃最旧的事件并重试;在固定次数的失败后,该任务评分失败

缩减预算模拟更长的任务。这是一种代理方法,而让运行在最小预算下存活的兜底机制本身也是一种可能影响得分的上下文策略。

行为分析

记录每个预算下的五个指标。定义遵循该研究,以确保结果的可比性。

指标定义区分什么
使用率至少发生一次压缩调用的任务比例使用控制权与拒绝控制权
压缩因子模型决定压缩的请求的输入令牌数除以下一次请求的输入令牌数激进的调用与谨慎的调用;低于1表示上下文增大了
恢复率其归档事件后来被检索的压缩调用比例恢复的状态与不需要或丢失的状态;这是一个下限估计
首次压缩填充率任务中首次压缩调用时已使用的预算比例;任务间取中位数及时的压缩与焦虑的压缩
警告解决从第一次压力警告到任务结束:返回答案、立即压缩、阅读接口文档后压缩、检查历史后压缩、其他压缩行为与结束任务行为

上下文焦虑与定时指令

针对每个模型校准定时指令,注意两种方向。上下文焦虑指在仍有充足空间时就开始压缩。当指令建议仅在超过高使用率阈值时才考虑压缩时,研究中的大多数模型都会等待直到接近该阈值。没有指令时,两个模型在不到一半预算时就开始压缩,并在大预算下得分低于框架基线;而第三个模型,在带有指令的情况下几乎从不压缩,在没有指令时则开始压缩得既早又规律(claim-compaction-control-context-anxiety)。因此,定时指令是一个每个模型都需调节的旋钮,可能在两个方向上出错:如果没有它,某些模型会过度压缩;有了它,研究中一个模型几乎完全停止了压缩。该研究报告称,对于该模型,无论哪种方式,准确性没有变化,因此将抑制使用率视为需要调查的信号,而非已证实的损失。早期压缩的一个假设原因是训练中惩罚长推理链(claim-compaction-control-rollout-penalty)。将原因视为推测,将行为视为可测量。早期压缩是信号;其准确性成本是另一项测量,并且研究发现,在三个早期压缩的模型中,有两个存在准确性成本。

可逆折叠是待测试的接口

针对一个可逆的压缩接口进行分析:模型用一个它编写的摘要替换一个标记范围的事件,框架归档原始内容,任何归档事件都能通过其原始标签检索(claim-compaction-control-reference-interface)。可逆性使得激进的压缩可以安全地允许,并且一旦框架记录下每个对归档事件的读取,代价就变得可观察。参考框架本身并不记录这些读取;该研究通过追踪来计数这些读取。一个仅支持删除的接口会将相同的损失隐藏在重复的工具调用中。

保证测量清晰的接口属性:

  • 标签稳定且在记录中可见;摘要携带其范围标签和一行检索提示。
  • 与现有摘要重叠的折叠会合并为一个摘要;重写摘要是一个显式操作,而非副作用。
  • 接口文档简短且可随时访问。一个模型在大多数首次警告事件中在压缩前阅读了它(claim-compaction-control-warning-response);每次查阅都是一个在压力下消耗完整上下文的回合。
  • 使用率读数的刷新频率至少应等于模型被期望采取行动的频率。每隔几轮才刷新一次读数会使首次压缩填充率反映的是刷新周期。
  • 每次折叠都记录其范围、前后的令牌数量以及填充率。每条可能返回归档事件的读取路径(按标签查找、索引访问、历史查询)都记录一次恢复。

令牌不是成本

压缩策略的成本应以重新计算的令牌数来衡量,而不仅仅是发送的令牌数。模型驱动的运行可以达到相同或更好的准确性,同时消耗更少的累计输入令牌(claim-compaction-control-token-savings),但累计输入计数的是每一轮的每个输入令牌,无论是否缓存。在前缀缓存机制下,一次编辑会使它之后的所有内容缓存失效,因此较短的上下文不一定更便宜。一个通过重用未更改后缀的缓存状态来减少每次请求预填充量的服务原型,在可测量的准确性没有变化的情况下减少了预填充计算,尤其是在存留后缀较大的情况下(claim-compaction-control-suffix-kv-reuse)。报告令牌数,并在可以观察服务栈的情况下,报告预填充计算量。将编辑放置和后缀重用机制路由至 self-managed-context。

实践指导

认证工作流程

  1. 估算压力。在最大可用预算下运行任务集,记录每个任务的峰值和累计上下文。
  2. 固定比较。对两种策略使用相同的框架、模型、工具、任务和评分器。记录框架阈值和保留规则,以及模型驱动接口的文档、读数、定时指令和警告文本。版本化提示文本;它是结果的一部分。
  3. 预算扫描。使用覆盖第一步中自然峰值的几何级数硬性请求限制,并在其下方至少有两个梯级。定义溢出兜底机制,统计其触发次数,并将错误计为失败。
  4. 每个单元重复实验并报告分布。将分布内的差异视为无差异。
  5. 记录每个预算下的行为分析。切勿跨预算汇总定时指标。
  6. 在一个严格和一个宽松的预算下消融定时指令:带指令、不带指令,如果使用率崩溃则再测试另一个阈值。
  7. 使用信号表进行分类,并根据模型和压力机制分配控制权。
  8. 以累计输入令牌以及在服务可观察的地方以前预填充计算量来评估成本。
  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.

相关技能