context-compression-skillhub
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "context-compression-skillhub":https://skillpi.com/zh/skills/deepskill-e8623f315ef72054fdb1a53312b7501a649ca7dac808b33631184448fa362404。安装前核对上游来源和版本:https://skillhub.cn/skills/user_3c6cb52e/context-compression-skillhub。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
skillhub.cn
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
SkillHub 技能:用于 SkillHub 平台的通用技能说明,标示该条目的用途为 SkillHub skill。
介绍来源: third_party · user_3c6cb52e · 1.0.0 参考来源
SkillPi 解读
- 能完成的任务
- 将上下文压缩以适应模型的token限制,同时保留任务所需的关键信息。
- 适合谁
- 来源文档未说明。
- 输入和输出
- 来源文档未说明。
- 软件、账号及付费要求
- 来源文档未说明。
- 限制与区别
- 来源文档未说明。
- 实测状态
- 未测试
文件浏览
Frontmatter
name: 上下文压缩
slug: "context-compression"
version: "1.0.0"
displayName: "上下文压缩"
summary: "将上下文压缩以适应模型的token限制,同时保留任务所需的关键信息。"
description: "将上下文压缩以适应模型的token限制,同时保留任务所需的关键信息。"
license: MIT
metadata:
author: awesome-ai-agent-skills
version: "1.0.0"上下文压缩
Context compression is the process of reducing the size of textual context provided to a language model while retaining the information most essential to the task. As conversations grow longer and retrieved documents grow larger, compression becomes critical for staying within token limits and keeping inference costs manageable without sacrificing answer quality.
Workflow
-
Measure the Token Budget: Determine the model's total context window (e.g., 4K, 32K, 128K tokens) and subtract the tokens reserved for the system prompt, instructions, and the model's generation output. The remainder is your available context budget. If the raw context already fits, compression may be unnecessary.
-
Score Information Density: Analyze each paragraph, sentence, or chunk of the raw context and assign an information-density score based on how many task-relevant facts it contains per token. Sentences that are purely stylistic, redundant, or off-topic receive low scores. This can be done heuristically (keyword overlap with the query) or via a lightweight classifier.
-
Select a Compression Strategy: Choose the most appropriate technique based on the compression ratio needed and the nature of the content:
- Extractive summarization — select the most important sentences verbatim.
- Abstractive summarization — rewrite content in fewer words while preserving meaning.
- Key-point extraction — pull out only named entities, facts, and figures.
- Selective pruning — remove low-density sentences, boilerplate, and repeated information.
-
Apply Compression: Execute the chosen strategy. For aggressive compression (>80% reduction), combine techniques — for example, first prune boilerplate, then abstractively summarize the remainder. For moderate compression (40–60%), extractive selection is often sufficient and avoids introducing paraphrasing errors.
-
Validate Information Retention: Compare the compressed output against the original to ensure no critical facts were lost. A quick validation pass can check that key entities, numbers, and conclusions from the original are still present in the compressed version.
-
Assemble the Final Context: Insert the compressed text into the prompt in place of the raw context. Include a note to the model indicating the context has been summarized, so it can calibrate its confidence accordingly.
Techniques
- Extractive Summarization: Selects the top-n most important sentences from the source text based on relevance scoring. Preserves exact wording, which is important when precision matters (legal, medical, code). Tools: TextRank, LexRank, or LLM-based extraction.
- Abstractive Summarization: Generates a new, shorter version of the text that captures the same meaning. Produces more natural and concise output but risks introducing inaccuracies. Best used with a reliable LLM and a validation step.
- Key-Point Extraction: Reduces text to a structured list of facts, entities, and data points. Extremely space-efficient (often 90%+ compression) but loses narrative flow and nuance.
- Selective Pruning: Removes filler sentences, repeated explanations, greetings, and boilerplate while keeping substantive content intact. Low risk of information loss and easy to implement with rule-based heuristics.
- Token Budget Management: Dynamically allocate token budgets across multiple context sources. For example, in a RAG pipeline with 5 retrieved chunks, allocate more tokens to higher-relevance chunks and aggressively compress lower-relevance ones.
Usage
Provide the raw context text and a target token budget. The skill returns a compressed version of the text that fits within the budget. Optionally specify the compression strategy (extractive, abstractive, key-points, or auto) and a list of must-retain keywords or entities.
Examples
Example 1: Compressing a Document for a Q&A Task
Input (excerpt, ~800 tokens):
The Acme Corporation was founded in 1987 by Jane Doe in Austin, Texas. It started as a small consulting firm specializing in environmental compliance. Over the years, the company expanded into waste management technology, receiving its first patent in 1994 for an automated sorting system. By 2005, Acme had grown to 500 employees across 12 offices nationwide. The company went public in 2010 with an IPO price of $18 per share. In 2018, Acme acquired GreenTech Solutions for $240 million, adding recycling automation to its portfolio. As of 2024, Acme reports annual revenue of $1.2 billion and employs 3,400 people. The CEO since 2020 is Michael Chen, who previously served as CTO. Acme's headquarters relocated to Denver, Colorado in 2021. The company's mission statement emphasizes sustainable industrial practices and carbon-neutral operations by 2030.
Compressed Output (key-point extraction, ~150 tokens):
- Acme Corporation: founded 1987 by Jane Doe, Austin TX; now HQ in Denver CO (relocated 2021)
- Business: environmental compliance consulting → waste management tech → recycling automation
- Key milestones: first patent 1994 (automated sorting), IPO 2010 ($18/share), acquired GreenTech Solutions 2018 ($240M)
- Current: CEO Michael Chen (since 2020), 3,400 employees, $1.2B annual revenue
- Goal: carbon-neutral operations by 2030
Example 2: Compressing Conversation History
Input (long-running chat, ~3,000 tokens across 18 messages):
User asks about setting up a Python virtual environment. Agent explains venv creation, pip usage, and requirements.txt. User then asks about Docker containerization. Agent explains Dockerfiles, docker-compose, and volume mounts. User encounters a port-binding error. Agent helps debug by checking for conflicting processes. User resolves the issue. User then asks about deploying to AWS ECS.
Compressed Output (abstractive summary, ~400 tokens):
Conversation summary: The user is setting up a Python application with Docker and deploying to AWS. Key context:
- Python environment is configured with venv and requirements.txt (resolved).
- Docker setup uses a Dockerfile and docker-compose with volume mounts (resolved).
- A port-binding conflict on port 8080 was resolved by killing a conflicting process.
- Current topic: User is now asking about deploying the Dockerized Python app to AWS ECS. They have a working Docker setup locally and need guidance on ECS task definitions, service configuration, and load balancing.
Best Practices
- Compress progressively — apply light pruning first, measure the result, then apply heavier techniques only if you still exceed the budget. This minimizes unnecessary information loss.
- Preserve numbers and names — quantitative data, proper nouns, dates, and code identifiers are disproportionately important and should be retained even in aggressive compression.
- Tag compressed context — always indicate to the model that the context has been compressed so it can appropriately hedge when details might have been lost.
- Prefer extractive methods for code — abstractive summarization can introduce subtle errors in code snippets. Use extractive selection or selective pruning for technical content.
- Keep the most recent turns — when compressing conversation history, preserve the last 2–3 turns verbatim and summarize earlier turns. Recency is a strong signal for relevance.
- Measure information loss — after compression, check that answers to key questions about the content remain correct. If a fact is lost that the task depends on, the compression was too aggressive.
Edge Cases
- Context already within budget: Skip compression entirely — unnecessary compression always loses some information. Only compress when the raw context exceeds available tokens.
- Highly technical or structured content: Tables, JSON, and code blocks compress poorly with abstractive methods. Use selective pruning or extract only the relevant rows/fields rather than summarizing.
- Multiple languages in context: Compression models may perform unevenly across languages. Compress each language segment independently or use a multilingual summarization model.
- Critical safety information: Never compress away safety warnings, legal disclaimers, or medical dosage information. Mark these as must-retain before applying any compression.
- Near-budget context: If the context is only 10–15% over budget, simple pruning of whitespace, boilerplate headers, and duplicate sentences is safer than full summarization.
当前收录版本
1.0.0
安全与评测信息
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 解决大模型上下文长度限制的核心痛点,适用于 RAG、长对话、文档处理等高频场景
- 提供多种压缩策略(抽取式、抽象式、关键点提取等),满足不同压缩需求
亮点
- description 清晰描述功能目标与核心能力,触发词精准
- 覆盖多种使用变体(文档、对话、技术内容等),边界清晰
亮点
- 结构完整,包含完整的工作流、技术细节、使用示例和最佳实践
- 提供端到端示例,帮助用户理解实际应用场景
亮点
- 覆盖主要异常场景(如预算内跳过压缩、技术内容处理、多语言等)
- 最佳实践包含信息保留验证机制,确保压缩后关键信息不丢失
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
来源文档未说明。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。