ai-context-pollution-detector
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "ai-context-pollution-detector" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-297d1e9589af61839bf0896b37807d9e2fb9f6eaf2500dceff64e343b6b0d148. Verify the upstream source and version against https://skillhub.cn/skills/user_638e256a/ai-context-pollution-detector before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Five-dimension dialogue context pollution detector: evaluates information density, topic consistency, redundancy, timeliness, and contradictions; identifies rounds where drift occurs and provides cleanup recommendations.
Introduction source: third_party · user_638e256a · 1.0.3 Reference
SkillPi interpretation
- Tasks
- Translation pending; see source documentation.
- Audience
- Translation pending; see source documentation.
- Testing
- Not tested
Browse files
Frontmatter
name: ai-context-pollution-detector
version: "2.1.0"
description: 五维检测对话上下文污染(信息密度/话题一致/冗余/时效/矛盾),识别漂移轮次并给出清理建议。AI上下文污染检测器 v2.1
纯Python零依赖 | 6命令 | 678行 | 五维加权评分+双通道漂移检测
命令速查
| 命令 | 用途 | 示例 |
|---|---|---|
detect <text> |
完整检测报告 | python main.py detect "对话..." |
score <text> |
仅健康度评分 | python main.py score "对话..." |
locate <text> |
定位污染源轮次 | python main.py locate "对话..." |
suggest <text> |
清理建议 | python main.py suggest "对话..." |
monitor <text> --threshold 70 |
低于阈值报警 | python main.py monitor "对话..." --threshold 60 |
history |
历史趋势 | python main.py history |
支持管道输入:echo "对话..." | python main.py detect
检测维度
| 维度 | 权重 | 含义 | 异常判定 |
|---|---|---|---|
| 信息密度 | 35% | 有效字符占比(汉字/字母/数字/代码符号) | <0.4 → 信息过载 |
| 话题一致性 | 15% | 全局词袋覆盖率+锚点回溯检测 | <0.3 → 话题漂移 |
| 冗余度 | 20% | 相邻轮关键词Jaccard重叠率 | >0.5 → 重复冗余 |
| 时效性 | 15% | 否定信号密度("不对""错了"等) | <0.6 → 信息过时 |
| 矛盾检测 | 15% | 否定词密集度 | >0.15 → 前后矛盾 |
健康度 = info_density×35 + topic_coherence×15 + (1-redundancy)×20 + freshness×15 + (1-contradiction)×15
评分标准
- 90-100 🟢 健康 — 上下文紧凑有效
- 70-89 🟡 轻微污染 — 可继续,建议总结关键点
- 50-69 🟠 中度污染 — 建议清理或开新对话
- 0-49 🔴 严重污染 — 强烈建议立即开新对话
使用场景
| 触发(任一命中) | 不触发 |
|---|---|
| 对话超30轮 / AI答非所问 | 单轮长文档分析 |
| 切换多个任务 / 讨论跑偏 | 图片/语音非文本 |
| "检测污染""上下文健康""开新对话" | 少于3轮 |
| "上下文太长了""对话乱了" | 发散性讨论 |
触发词
上下文污染 对话污染 检测污染 上下文健康 开新对话 上下文太长了 对话乱了 答非所问 话题跑偏
示例输出
示例1:正常技术讨论
$ python main.py detect "用户: 帮我写一个Python的快速排序
AI: 好的,这是实现...
def quicksort(arr):
if len(arr) <= 1: return arr
...
用户: 时间复杂度是多少?
AI: 平均O(n log n),最坏O(n²)
用户: 空间复杂度呢?
AI: O(log n),来自递归调用栈
用户: 能优化成迭代版本吗?
AI: 可以,用显式栈..."
输出(实测真实值):
{
"health_score": 80.5,
"dims": {"info_density": 0.94, "topic_coherence": 0.3, "redundancy": 0.01, "freshness": 1.0, "contradiction": 0.0},
"pollution_types": ["irrelevant"],
"pollution_sources": [],
"suggestion": "continue_with_care",
"summary": "轻微污染,可继续但需注意"
}
示例2:多轮污染对话
$ python main.py detect "用户: 帮我设计一个数据库表结构
AI: 好的,这是用户表的DDL...
用户: 对了,周末去哪玩比较好?
AI: 推荐去郊外爬山...
用户: 然后用户表还要加一个角色字段
AI: 已添加role字段...
用户: 你知道今天中午食堂有什么菜吗?
AI: 今天有宫保鸡丁...
用户: 数据库索引怎么设计?
AI: 建议在user_id上建B+树索引..."
输出(实测真实值):
{
"health_score": 87.4,
"dims": {"info_density": 0.94, "topic_coherence": 0.3, "redundancy": 0.01, "freshness": 1.0, "contradiction": 0.0},
"pollution_types": ["irrelevant"],
"pollution_sources": [
{"round": 3, "type": "topic_drift", "content_preview": "对了,周末去哪玩比较好?", "severity": "high"},
{"round": 4, "type": "topic_drift", "content_preview": "推荐去郊外爬山...", "severity": "high"},
{"round": 7, "type": "topic_drift", "content_preview": "你知道今天中午食堂有什么菜吗?", "severity": "medium"}
],
"suggestion": "continue_with_care",
"summary": "轻微污染,可继续但需注意"
}
示例3:history 历史趋势
$ python main.py history
输出(实测真实值):
{"count": 2, "avg_score": 84.0, "recent_avg": 84.0, "trend": "stable"}
FAQ
健康度<90需要恐慌吗?
不需要。70-89是"轻微污染",长对话天然有冗余,完全正常。只有<50才需立即处理。
为什么算法不完美区分所有话题边界?
本技能用纯Python标准库实现,中文分词采用bigram滑动窗口。技术术语("时间复杂度""迭代版本")可能被切为碎片。但话题一致性仅占15%权重,info_density(35%)+redundancy(20%)+freshness(15%)+contradiction(15%)共85%权重不受影响,健康度评分依然可靠。
对话只有2轮能检测吗?
能运行,但大部分维度退化为中性值。建议≥5轮再检测。
输出JSON结构
{
"id": "ctx_1783770196",
"health_score": 87.4,
"dims": {"info_density": 0.94, "topic_coherence": 0.3, "redundancy": 0.01, "freshness": 1.0, "contradiction": 0.0},
"pollution_types": ["irrelevant"],
"pollution_sources": [{"round": 3, "type": "topic_drift", "content_preview": "...", "severity": "high"}],
"suggestion": "continue_with_care",
"summary": "轻微污染,可继续但需注意",
"detected_at": "2026-07-11T19:43:16+08:00"
}
文件结构
skills/ai-context-pollution-detector/
├── SKILL.md # 本文件
├── main.py # 可执行代码(678行,6种算法+6个CLI命令)
└── data/ # 运行时数据(自动生成)
└── history.json # 检测历史
联动
ai-error-evolution:反复犯错未纠偏→污染源
ai-token-stats:上下文膨胀→Token浪费交叉验证
Current listing version
1.0.3
Safety and assessment details
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 解决AI对话中上下文污染这一明确痛点
- 适用于长对话场景,具有广泛实用价值
- 提供五维加权评分+双通道漂移检测
Highlights
- 触发词精准完整,覆盖多种变体
- 边界清晰,不易误触或漏触
Highlights
- Phase/步骤清晰,有出口条件
- 含端到端示例,frontmatter完整
- 单文件≤500行,结构良好
Highlights
- 工具来源明确,参数正确
- 覆盖主要异常,不可逆操作有确认机制
- 纯Python零依赖,执行稳定
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
These common operations were not identified in the main document. This does not mean no permissions or risks exist.
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.