开放决策编译器
用 LLM 编译一次你的意图。然后永远对每条记录做决策— 分类、评分、路由 — 以类型安全的 JSON 形式,带概率和置信度,在你自己的硬件上,以零边际成本。
Agents at compile time. Never at runtime.
pip install strot-ai
import strot result = strot.run( tickets, query="将传入的支持工单分诊到正确的工作流。", action_registry={ "billing_dispute": "退款、发票更正、重复扣费", "technical_defect": "崩溃、缺陷、异常行为", }, llm="anthropic/claude-opus-4-8", # 仅使用一次,仅在首次编译时 ) 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": "是否提到崩溃/错误?"}, "customer_sentiment":{"type": "score", "min": 1, "max": 5, "instructions": "1 愤怒,5 满意"}, "routing_bucket": {"type": "choice", "options": ["billing", "engineering", "spam"]}, }) # → {"booleans": {...}, "scores": {...}, "choices": {...}} 带概率 + 置信度
实测
真实模型(SupersonicLabs/Julia-1,144M,CPU)、真实数据集、干净的 Docker 容器:
| 结果 | |
|---|---|
| 有依据的路由准确率(398 条记录) | 92.5%编译版 vs 朴素版 74.8% — 在同一模型上,编译器带来 +18pp 的提升 |
| 语义文本(AG News,未见过的标签) | 86.7%编译版 vs 朴素版 72.7%(+14pp) |
| 类型化决策 vs 领先托管决策 API 自带的示例 | 几乎相同(情感 1.79 vs 1.8) |
| 每条记录的延迟 / 边际成本 / LLM 调用次数 | ~60 ms · $0 · 0 |
复现全部结果:benchmarks/— 并同时公布损失数据。
它的不同之处
- 编译一次,永远决策— 内容寻址的产物缓存;模式漂移只会触发恰好一次重新编译。
- 黄金记录晋升— 产物在提供服务之前必须通过你的已知答案。
- 拟合保证— 温度缩放 + 分裂共形预测,内置:已派发决策的错误率 ≤ 所有记录中的 α(边际);其余弃权。
- 实测,而非猜测— 编译器对标注打分,并可训练一个蒸馏头,只保留在留出数据上优于基线的部分。
- 0% 结构性幻觉— 输出是对你的注册表进行选择 + 计算;运行时不会生成任何内容。
- 与模型无关— 决策模型是一个插槽(
nlu=):默认使用本地 Julia-1、托管 API,或任何可直接替换的专用模型。
安装
pip install strot-ai #core:纯标准库 pip install strot-ai[local] #+ 本地决策模型(torch/transformers) pip install strot-ai[hosted] #+ openai,用于托管决策运行时 pip install strot-ai[anthropic] #+ anthropic,用于合成器
将本地模型烘焙进你的镜像,用于离线生产:
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)中的思想。