关于 Decompose
Decompose 是面向 AI Agent 的确定性文本分类工具,可将文本拆分为带有权威性、风险和注意力评分的语义单元。它使用正则表达式与启发式方法,无需 LLM,适合在推理前筛选和路由文档内容。
主要功能
- 01拆分并分类语义单元
- 02标注权威性、风险和类型
- 03提取标准与法规实体
- 04评估注意力和可执行性
- 05筛选高价值文本供 LLM 使用
适用场景
- 01预处理合同与技术规范
- 02将安全和财务内容分流处理
- 03减少送入 LLM 的文本量
MCP 相关
MCP 服务提供 decompose_text 和 decompose_url 工具,用于分类文本或抓取并分类 URL 内容。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
Decompose
别再写提示词,开始分解文本。
为 AI Agent 提供确定性文本分类。Decompose 可即时将任意文本拆解为经过分类的结构化语义单元。不需要大模型,无需设置,只需调用一个函数。
之前:你的 Agent 读到的是
The contractor shall provide all materials per ASTM C150-20. Maximum load
shall not exceed 500 psf per ASCE 7-22. Notice to proceed within 14 calendar
days of contract execution. Retainage of 10% applies to all payments.
For general background, the project is located in Denver, CO...
之后:你的 Agent 读到的是
[
{
"text": "The contractor shall provide all materials per ASTM C150-20.",
"authority": "mandatory",
"risk": "compliance",
"type": "requirement",
"irreducible": true,
"attention": 8.0,
"entities": ["ASTM C150-20"]
},
{
"text": "Maximum load shall not exceed 500 psf per ASCE 7-22.",
"authority": "prohibitive",
"risk": "safety_critical",
"type": "constraint",
"irreducible": true,
"attention": 10.0,
"entities": ["ASCE 7-22"]
}
]
每个单元都经过分类,每项标准都已提取,每项风险都已评分。你的 Agent 知道哪些内容至关重要。
安装
pip install decompose-mcp
用作 MCP 服务
将其添加到 Agent 的 MCP 配置中(Claude Code、Cursor、Windsurf 等):
{
"mcpServers": {
"decompose": {
"command": "uvx",
"args": ["decompose-mcp", "--serve"]
}
}
}
你的 Agent 将获得两个工具:
decompose_text— 分解任意文本decompose_url— 获取 URL 并分解其内容
OpenClaw
从 ClawHub 安装技能,或直接进行配置:
{
"mcpServers": {
"decompose": {
"command": "python3",
"args": ["-m", "decompose", "--serve"]
}
}
}
也可以安装技能:clawdhub install decompose-mcp
用作 CLI
# Pipe text
cat spec.txt | decompose --pretty
# Inline
decompose --text "The contractor shall provide all materials per ASTM C150-20."
# Compact output (smaller JSON)
cat document.md | decompose --compact
用作库
from decompose import decompose_text, filter_for_llm
result = decompose_text("The contractor shall provide all materials per ASTM C150-20.")
for unit in result["units"]:
print(f"[{unit['authority']}] [{unit['risk']}] {unit['text'][:60]}...")
# Pre-filter for LLM context — keep only high-value units
filtered = filter_for_llm(result, max_tokens=4000)
print(f"{filtered['meta']['reduction_pct']}% token reduction")
llm_input = filtered["text"] # Ready for your LLM
各字段含义
| 字段 | 值 | 告诉 Agent 的信息 |
|---|---|---|
authority | mandatory, prohibitive, directive, permissive, conditional, informational | 这是硬性要求还是背景信息? |
risk | safety_critical, security, compliance, financial, contractual, advisory, informational | 这有多重要? |
type | requirement, definition, reference, constraint, narrative, data | 这是什么类型的内容? |
irreducible | true/false | 是否必须原样保留? |
attention | 0.0 - 10.0 | Agent 应在此投入多少计算资源? |
entities | standards, codes, regulations | 引用了哪些正式资料? |
actionable | true/false | 是否有人需要采取行动? |
可以用它做什么
Decompose 并非最终目的,而是开发者常常跳过的大模型处理前步骤——不是因为它很难,而是因为没人告诉他们这一步的存在。文档具有结构,这些结构可以分类,而且分类应该先于推理。
Without: document → chunk → embed → retrieve → LLM → answer (100% of tokens)
With: document → decompose → filter/route → LLM → answer (20-40% of tokens)
过滤:内置大模型预过滤器
filter_for_llm() 会保留强制性、安全关键、财务和合规类单元,并在内容到达你的大模型或向量存储之前丢弃套话。
from decompose import decompose_text, filter_for_llm
result = decompose_text(open("contract.md").read())
filtered = filter_for_llm(result, max_tokens=4000)
# filtered["text"] = high-value units only, ready for LLM
# filtered["meta"]["reduction_pct"] = how much was dropped (typically 60-80%)
# Or use the units directly for embedding
for unit in filtered["units"]:
embed_and_store(unit["text"], metadata={
"authority": unit["authority"],
"risk": unit["risk"],
"attention": unit["attention"],
})
路由:基于风险的处理
安全关键内容交给一条处理链,财务内容交给另一条。套话则跳过。
from decompose import decompose_text
result = decompose_text(spec_text)
for unit in result["units"]:
if unit["risk"] == "safety_critical":
safety_chain.process(unit) # Full analysis + human review
elif unit["risk"] == "financial":
audit_chain.process(unit) # Flag for finance team
elif unit["attention"] < 0.5:
pass # Skip boilerplate
else:
general_chain.process(unit) # Standard LLM analysis
衡量:减少 Token 开销
from decompose import decompose_text
result = decompose_text(spec_text)
total = len(result["units"])
high = [u for u in result["units"] if u["attention"] >= 1.0]
print(f"{len(high)}/{total} units need LLM analysis")
print(f"{100 - len(high) * 100 // total}% token reduction")
可运行的脚本请参见 examples/。
为什么不用大模型?
Decompose 仅使用正则表达式和启发式方法运行。不需要 Ollama、API 密钥或 GPU,也没有推理成本。
这是有意为之:
- 快速:处理一份 50 页的规范不到 500ms
- 确定性:相同输入始终产生相同输出
- 离线:在隔离网络、飞机上或 CI 中均可运行
- 可组合:你的 Agent 的大模型基于结构化输出进行推理,Decompose 则负责预处理
大模型是你的 Agent 使用的工具。无论你运行哪种模型,Decompose 都能让它发挥得更好。
由 Echology 构建
Decompose 由 Echology 构建,并从面向建筑、工程和施工公司的文档智能平台 AECai 中提取而来。其分类模式、实体提取和不可约性检测已通过数千份真实 AEC 文档的验证,包括规范、合同、RFI、检查报告和付款申请。
Decompose 已具备独立发展的能力:它最初是 AECai 的文本分类模块,后来证明足以适用于保险、交易和监管等不同领域,因此作为独立项目发布。免费,采用 MIT 许可证。
案例研究:Open Scripture Intelligence
用于分类工程规范的同一套分块和实体提取模式,也能为《圣经》构建结构。Open Scripture Intelligence 使用 Decompose 的 Markdown 感知型分块器和正则表达式实体提取,将 31,100 节经文转换为包含 344,799 条交叉引用边和语义嵌入的知识图谱,证明了这种方法不受领域限制。
博客
- 正则表达式何时胜过大模型 — Decompose 在 3.78ms 内对 MCP 规范进行分类
- 为什么你的 Agent 需要认知原语 — 注意力评分、不可约性与路由
- “仿真感知”究竟意味着什么 — AECai 背后的架构
许可证: MIT — 版权所有 (c) 2025-2026 Echology, Inc.
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。