mcpField
D
Decompose

Decompose

本地服务
github.com/echology-ioAI 与智能体1032 周前更新

关于 Decompose

Decompose 是面向 AI Agent 的确定性文本分类工具,可将文本拆分为带有权威性、风险和注意力评分的语义单元。它使用正则表达式与启发式方法,无需 LLM,适合在推理前筛选和路由文档内容。

主要功能

  1. 01拆分并分类语义单元
  2. 02标注权威性、风险和类型
  3. 03提取标准与法规实体
  4. 04评估注意力和可执行性
  5. 05筛选高价值文本供 LLM 使用

适用场景

  1. 01预处理合同与技术规范
  2. 02将安全和财务内容分流处理
  3. 03减少送入 LLM 的文本量

MCP 相关

MCP 服务提供 decompose_text 和 decompose_url 工具,用于分类文本或抓取并分类 URL 内容。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"echology-io-decompose": {
"command": "uvx",
"args": [
"decompose-mcp"
]
}
}
}
启动命令uvx decompose-mcp

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
pypidecompose-mcp0.1.1

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

Decompose

CI PyPI Python

别再写提示词,开始分解文本。

为 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 的信息
authoritymandatory, prohibitive, directive, permissive, conditional, informational这是硬性要求还是背景信息?
risksafety_critical, security, compliance, financial, contractual, advisory, informational这有多重要?
typerequirement, definition, reference, constraint, narrative, data这是什么类型的内容?
irreducibletrue/false是否必须原样保留?
attention0.0 - 10.0Agent 应在此投入多少计算资源?
entitiesstandards, codes, regulations引用了哪些正式资料?
actionabletrue/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 条交叉引用边和语义嵌入的知识图谱,证明了这种方法不受领域限制。

博客

许可证: MIT — 版权所有 (c) 2025-2026 Echology, Inc.

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。