跳到正文
原文
Hacker News· solohunter001·· 2 小时前精选AI 评分65

Strot:编译 LLM 意图一次,本地永久运行决策

Show HN: Strot – Compile an LLM's intent once, run decisions locally forever

AI 导读

Strot 是一款开源工具,可让用户用 LLM 编译一次意图,之后在本地用 144M 模型对每条记录做分类、评分或路由,输出附带概率和置信度的类型安全 JSON。

推荐理由

把一次性 LLM 意图编译成本地决策模型,自带公开评测和 Docker 复现脚本,适合评估离线推理在延迟和成本上的可迁移收益。

正文 · AI 翻译

开源决策编译器

用 LLM 一次性编译你的意图,然后永久地为每条记录做决策—— 分类、评分、路由——以带有概率和置信度的类型安全 JSON,在你自有的硬件上,零边际成本。

PyPI License Tests Python

网站 · 文档 · 基准测试 · PyPI

Agents at compile time.  Never at runtime.

pip install strot-ai
import strot

result = strot.run(
    tickets,
    query="Triage incoming support tickets into the correct workflow.",
    action_registry={
        "billing_dispute":  "Refunds, invoice corrections, double charges",
        "technical_defect": "Crashes, bugs, broken behavior",
    },
    llm="anthropic/claude-opus-4-8",   # used once, on first compile only
)

for o in result.outcomes:
    print(o["action"], round(o["confidence"], 2))
# billing_dispute 0.97
# technical_defect 0.94

LLM 仅运行一次,在编译时完成。生产环境是一个冻结的、自包含的 Python 工件:一个小型本地决策模型对每条记录进行仲裁,不生成任何内容,每个输出都有界,低置信度的记录会弃权而非猜测。

STROT = Agentic Schema Intent + Compiler & State + Code + Execution + NLU
                      ⟹  JSON Decisions
          (classification · scoring · routing · typed answers)

工作原理

            COMPILE  (once per intent + schema)
  intent + sample ─▶ synthesize ─▶ golden gate ─▶ teacher labels ─▶ calibrate
                     (labels,      (your known      (annotate         (fit the
                      projection,   answers must     a sample,         confidence
                      handlers)     pass)            once)             threshold)
                                        │
                                        ▼
                             frozen artifact  (.py)

            RUNTIME  (every record, forever)
  record ─▶ projection ─▶ decision model ─▶ confidence gate ─▶ typed JSON
            (compiled)     (144M, CPU,        (decide or         decision
                            ~60 ms)            abstain)

两种使用面

run() — 将每条记录路由到一个动作,并执行编译后的处理器。

decide() — 按记录回答类型化问题(选项 / 评分 / 布尔值):

result = strot.decide(records, questions={
    "is_bug_report":     {"type": "boolean", "instructions": "mentions crashes/errors?"},
    "customer_sentiment":{"type": "score", "min": 1, "max": 5, "instructions": "1 angry, 5 happy"},
    "routing_bucket":    {"type": "choice", "options": ["billing", "engineering", "spam"]},
})
# → {"booleans": {...}, "scores": {...}, "choices": {...}}  with probabilities + confidence

实测

真实模型(SupersonicLabs/Julia-1,144M,CPU)、真实数据集、干净的 Docker 容器:

结果
有依据的路由准确率(398 条记录) 92.5% 编译版 vs 74.8% 朴素版 —— 编译器在同一模型上价值 +18 个百分点
语义文本(AG News,未见过的标签) 86.7% 编译版 vs 72.7% 朴素版(+14 个百分点)
类型化决策 vs 主流托管决策 API 自家的示例 几乎相同(情感 1.79 vs 1.8)
延迟 / 边际成本 / 每条记录的 LLM 调用次数 ~60 毫秒 · $0 · 0

复现一切:benchmarks/ — 同时也公开损失结果。

有何不同

  • 编译一次,永久决策 —— 内容寻址的工件缓存;架构漂移恰好触发一次重新编译。
  • 黄金记录晋升 —— 工件必须通过你的已知答案才会投入使用。
  • 拟合式保证 —— 内置温度缩放 + 分割保形预测:被分派的决策在(边际)所有记录中错误率 ≤ α,其余弃权。
  • 实测而非猜测 —— 编译器对标注进行打分,并能训练一个蒸馏头,只保留在留出数据上胜过基线的部分。
  • 0% 结构性幻觉 —— 输出是对你注册表的选择 + 计算;运行时不会生成任何内容。
  • 模型无关 —— 决策模型是一个插槽(nlu=):默认是本地 Julia-1,也可是托管 API 或任何可即插即用的专家模型。

安装

pip install strot-ai            # core: pure stdlib
pip install strot-ai[local]     # + the local decision model (torch/transformers)
pip install strot-ai[hosted]    # + openai, for a hosted decision runtime
pip install strot-ai[anthropic] # + anthropic, for the synthesizer

将本地模型烘焙到你的镜像中,以便离线生产:

RUN pip install strot-ai[local] \
 && python -c "import strot; strot.prefetch_nlu(local_dir='/opt/julia-1', install=True)"
ENV STROT_NLU_CHECKPOINT=/opt/julia-1

(绝非 pip install julia —— 无关的包。)

文档

DEVELOPERS.md — 架构、编译生命周期、校准 语义与注意事项、部署、模型替换、完整 API 参考。

许可证

MIT。默认决策模型:Apache-2.0(SupersonicLabs/Julia-1)。实现了 STROT(arXiv:2505.01636)的思想。

来源:Hacker News · github.com