Chain-of-Density Summarization
Compress text through iterative entity injection following the CoD paper methodology. Each pass identifies missing entities from the source and incorporates them while maintaining identical length.
The Method
Chain-of-Density works through multiple iterations:
- 1. Iteration 1: Create sparse, verbose base summary (4-5 sentences at
target_words) - Subsequent iterations: Each iteration:
- Identify 1-3 missing entities from SOURCE (not summary)
- Rewrite summary to include them
- Maintain IDENTICAL word count through compression
Key principle: Never drop entities - only add and compress.
Missing Entity Criteria
Each entity added must meet ALL 5 criteria:
| Criterion | Description |
|---|
| Relevant | To the main story/topic |
| Specific |
Descriptive yet concise (≤5 words) |
|
Novel | Not in the previous summary |
|
Faithful | Present in the source (no hallucination) |
|
Anywhere | Can be from anywhere in the source |
Quick Start
- 1. User provides text to summarize
- Orchestrate 5 iterations via
cod-iteration agent - Each iteration reports entities added via
Missing_Entities: line - Return final summary + entity accumulation history
Orchestration Pattern
CODEBLOCK0
How to Orchestrate
Iteration 1 - Pass source text only:
CODEBLOCK1
Iterations 2-5 - Pass BOTH previous summary AND source:
CODEBLOCK2
Critical:
- - Invoke serially, not parallel
- Pass SOURCE text in every iteration for entity discovery
- Parse
Missing_Entities: line to track entity accumulation
Expected Agent Output Format
The cod-iteration agent returns:
CODEBLOCK3
Parse both parts - track entities for history, pass summary to next iteration.
Measuring Density
Use scripts/text_metrics.py for deterministic word counts:
CODEBLOCK4
Parameters
| Parameter | Default | Description |
|---|
| iterations | 5 | Number of density passes (paper uses 5) |
| target_words |
80 | Word count maintained across ALL iterations |
| return_history | false | Include intermediate summaries + entities |
Note: target_words can be adjusted based on source length and desired output density.
Output Format
Minimal (default)
CODEBLOCK5
With History (return_history=true)
CODEBLOCK6
When to Use
- - Verbose documentation exceeding 500 words
- Requirements documents needing condensation
- Creating executive summaries from detailed reports
- Compressing skills that exceed recommended length
When NOT to Use
- - Legal/compliance text (precision required)
- Tutorial content (beginners need explanation)
- Already concise content (<300 words)
- Specifications (don't compress specs)
Example
Source (180 words, verbose skill excerpt):
CODEBLOCK7
Iteration 1 (Sparse, 80 words):
CODEBLOCK8
Iteration 3 (After 2 passes, same 80 words):
CODEBLOCK9
Final Iteration 5 (Same 80 words, maximum density):
CODEBLOCK10
Architecture Note
This skill implements the CoD paper methodology:
- - Skill = orchestrator (this file)
- Agent = stateless worker (
cod-iteration) - Script = deterministic utility (
text_metrics.py)
Sub-agents cannot call other sub-agents. Only skills orchestrate via Task tool.
References
密度链式摘要
通过遵循CoD论文方法的迭代实体注入来压缩文本。每次迭代从源文本中识别缺失实体并将其纳入,同时保持相同的长度。
方法
密度链式通过多次迭代工作:
- 1. 迭代1:创建稀疏、冗长的基础摘要(target_words下的4-5个句子)
- 后续迭代:每次迭代:
- 从源文本(而非摘要)中识别1-3个缺失实体
- 重写摘要以包含这些实体
- 通过压缩保持完全相同的字数
关键原则:永不丢弃实体——只添加和压缩。
缺失实体标准
每个添加的实体必须满足所有5个标准:
描述性强但简洁(≤5个词) |
|
新颖 | 不在之前的摘要中 |
|
忠实 | 存在于源文本中(无幻觉) |
|
任意位置 | 可来自源文本的任何位置 |
快速开始
- 1. 用户提供要总结的文本
- 通过cod-iteration代理编排5次迭代
- 每次迭代通过Missing_Entities:行报告添加的实体
- 返回最终摘要 + 实体累积历史
编排模式
迭代1:稀疏基础(target_words,冗长填充)
↓ Missing_Entities:(无 - 建立基础)
迭代2:+3个实体,压缩填充
↓ Missing_Entities:实体1;实体2;实体3
迭代3:+3个实体,进一步压缩
↓ Missing_Entities:实体4;实体5;实体6
迭代4:+2个实体,收紧
↓ Missing_Entities:实体7;实体8
迭代5:+1-2个实体,最终密度
↓ Missing_Entities:实体9
最终密集摘要(相同字数,9+个实体)
如何编排
迭代1 - 仅传递源文本:
Task(subagent_type=cod-iteration, prompt=
iteration: 1
target_words: 80
text: [源文本在此]
)
迭代2-5 - 同时传递前一个摘要和源文本:
Task(subagent_type=cod-iteration, prompt=
iteration: 2
target_words: 80
text: [前一个摘要在此]
source: [原始源文本在此]
)
关键:
- - 串行调用,而非并行
- 每次迭代都传递源文本以发现实体
- 解析Missing_Entities:行以跟踪实体累积
预期代理输出格式
cod-iteration代理返回:
Missing_Entities: 实体1;实体2;实体3
Denser_Summary:
[密集化摘要 - 与前一个相同的字数]
解析两部分——跟踪实体历史,将摘要传递给下一次迭代。
测量密度
使用scripts/text_metrics.py进行确定性字数统计:
bash
echo 你的摘要文本 | uv run scripts/text_metrics.py words
返回:字数
uv run scripts/text_metrics.py metrics 你的摘要文本
返回:{words: N, chars: N, bytes: N}
参数
| 参数 | 默认值 | 描述 |
|---|
| iterations | 5 | 密度传递次数(论文使用5次) |
| target_words |
80 | 所有迭代中保持的字数 |
| return_history | false | 包含中间摘要 + 实体 |
注意:target_words可根据源文本长度和期望输出密度进行调整。
输出格式
最小化(默认)
[最终密集摘要文本]
带历史(return_history=true)
yaml
final_summary: |
[在target_words下包含累积实体的密集摘要]
iterations:
- turn: 1
missing_entities: (无 - 建立基础)
words: 80
summary: |
[稀疏迭代1]
- turn: 2
missing_entities: 实体1;实体2;实体3
words: 80
summary: |
[密集迭代2]
# ... 等等
total_entities: 9
何时使用
- - 超过500词的冗长文档
- 需要浓缩的需求文档
- 从详细报告中创建执行摘要
- 压缩超出推荐长度的技能
何时不使用
- - 法律/合规文本(需要精确性)
- 教程内容(初学者需要解释)
- 已简洁的内容(<300词)
- 规格说明(不要压缩规格)
示例
源文本(180词,冗长的技能摘录):
名称字段是每个技能中必须存在的必填字段。
名称字段标识技能,必须遵循特定格式。
对于名称字段,应仅使用小写字母和连字符。
名称字段长度可为1到64个字符。描述字段
也是必填的,告诉代理何时使用你的技能...
迭代1(稀疏,80词):
Missing_Entities:(无 - 建立基础)
Denser_Summary:
本文档讨论了代理系统中技能配置字段的要求。它涵盖了字段应如何格式化以及可包含哪些值的各个方面。文档还提到了适用于这些字段的验证规则,并为开发者提供了最佳实践指导。此外,它包含了在创建系统新技能时需要考虑的可选和必填元素的信息。
迭代3(经过2次传递,相同80词):
Missing_Entities: 1-64字符;小写字母数字连字符;使用时机短语
Denser_Summary:
技能需要name(1-64字符,小写字母数字连字符)和description字段,并带有验证规则。名称标识技能;描述使用使用时机...短语告诉代理何时调用。两个字段都有格式约束和最佳实践。可选的元数据字段提供作者、版本和兼容性信息,用于跨平台代理发现。
最终迭代5(相同80词,最大密度):
Missing_Entities: Claude Code;Cursor;GitHub Copilot
Denser_Summary:
必填:name(1-64字符,^[a-z0-9]+(-[a-z0-9]+)*$)和description(1-1024字符)带验证。描述包含使用时机...+发现关键词用于自动调用。可选:许可证(SPDX)、兼容性、元数据(作者、版本、标签)。跨平台:Claude Code、Cursor、GitHub Copilot。名称匹配目录。通过references/、assets/、scripts/子目录进行渐进式展示。
架构说明
该技能实现了CoD论文方法:
- - 技能 = 编排器(此文件)
- 代理 = 无状态工作者(cod-iteration)
- 脚本 = 确定性工具(text_metrics.py)
子代理不能调用其他子代理。只有技能通过Task工具进行编排。
参考