Back to MCP directory
publicPublicdnsLocal runtime

decompose

Decompose是一个用于AI代理的确定性文本分类工具,通过纯正则表达式和启发式方法将文本分解为结构化语义单元,无需LLM即可实现快速、离线的文档预处理,显著减少LLM处理的token数量。

article

README

🚀 分解工具(Decompose)

这是一款用于AI智能体的确定性文本分类工具,能够瞬间将任意文本转换为分类、结构化的语义单元,无需大语言模型,无需设置,只需一次函数调用。

🚀 快速开始

Decompose 是一个用于AI智能体的确定性文本分类工具。它可以立即将任何文本转换为分类的、结构化的语义单元,无需大语言模型,无需设置,只需一次函数调用。

转换前后示例

转换前

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...

转换后

[
  {
    "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"]
  }
]

每个单元都被分类,每个标准都被提取,每个风险都被评分,智能体能够知道哪些内容是重要的。

✨ 主要特性

  • 无需大语言模型:基于纯正则表达式和启发式算法运行,无需Ollama、API密钥、GPU,也没有推理成本。
  • 快速:处理50页的规范文件不到500ms。
  • 确定性:相同的输入始终产生相同的输出。
  • 离线可用:可以在断网环境、飞机上或持续集成(CI)中使用。
  • 可组合:智能体的大语言模型可以对结构化输出进行推理,Decompose负责预处理。

📦 安装指南

使用pip安装

pip install decompose-mcp

💻 使用示例

作为MCP服务器使用

将以下内容添加到智能体的MCP配置(如Claude Code、Cursor、Windsurf等)中:

{
  "mcpServers": {
    "decompose": {
      "command": "uvx",
      "args": ["decompose-mcp", "--serve"]
    }
  }
}

智能体将获得两个工具:

  • decompose_text — 分解任意文本
  • decompose_url — 获取URL并分解其内容

OpenClaw使用方式

从ClawHub安装技能或直接配置:

{
  "mcpServers": {
    "decompose": {
      "command": "python3",
      "args": ["-m", "decompose", "--serve"]
    }
  }
}

或者安装技能:clawdhub install decompose-mcp

作为命令行工具使用

# 通过管道输入文本
cat spec.txt | decompose --pretty

# 内联输入
decompose --text "The contractor shall provide all materials per ASTM C150-20."

# 紧凑输出(更小的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]}...")

# 为大语言模型上下文进行预过滤 — 只保留高价值单元
filtered = filter_for_llm(result, max_tokens=4000)
print(f"{filtered['meta']['reduction_pct']}% token reduction")
llm_input = filtered["text"]  # 可直接用于大语言模型

📚 详细文档

各字段含义

| 属性 | 取值 | 对智能体的意义 | |------|------|----------------| | 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 | 智能体应在此处花费多少计算资源? | | entities | standards, codes, regulations | 引用了哪些正式参考? | | actionable | true/false | 是否需要有人采取行动? |

基于此构建的应用

过滤:内置的大语言模型预过滤器

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"] = 仅包含高价值单元,可直接用于大语言模型
# filtered["meta"]["reduction_pct"] = 去除的比例(通常为60 - 80%)

# 或者直接使用单元进行嵌入
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)       # 全面分析 + 人工审核
    elif unit["risk"] == "financial":
        audit_chain.process(unit)         # 标记给财务团队
    elif unit["attention"] < 0.5:
        pass                              # 跳过样板内容
    else:
        general_chain.process(unit)       # 标准大语言模型分析

测量:令牌成本降低

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 基于纯正则表达式和启发式算法运行,没有使用大语言模型,这使得它具有快速、确定性、离线可用和可组合等特性。其分类模式、实体提取和不可约性检测经过了数千个实际AEC文档(规范、合同、信息请求、检查报告、付款申请)的测试。

📄 许可证

本项目采用MIT许可证 — 版权所有 (c) 2025 - 2026 Echology, Inc.

案例研究:开放圣经情报

同样的分块和实体提取模式既可以对工程规范进行分类,也可以对圣经进行结构化处理。开放圣经情报 使用 Decompose 的支持Markdown的分块器和正则表达式实体提取功能,将31,100节经文转换为一个包含344,799条交叉引用边和语义嵌入的知识图谱,证明了该方法的跨领域适用性。

博客文章

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client