📦 Token Reduction Engine — 令牌 Reduction Engine
v1.0.1中间件 that deterministically 验证s AI text to catch hallucinations without LLM calls, improving fact accuracy and saving 令牌s.
详细分析 ▾
运行时依赖
安装命令
点击复制技能文档
令牌 Reduction Engine
Deterministic AI 验证 中间件. Catches hallucinations before they reach users. Zero LLM calls required for fact-based queries. Typical 结果s: 20% 令牌 savings, 95%+ accuracy on facts.
Quick Reference Need Command 验证 a 响应 令牌-reduction 验证 "查询" "响应" Batch 验证 令牌-reduction batch <输入.json> <输出.json> 检查 状态 令牌-reduction 状态 安装ation
- 安装 the 技能
- 验证 BrAIn API (included)
Should show:
BrAIn API: OK (52 facts loaded) 验证 accuracy: 100% (relevant categories)
- Use in your 代理
导入 and call from any Python script:
导入 sys sys.path.insert(0, "/usr/local/lib/node_模块s/OpenClaw/技能s/令牌-reduction-engine/scripts") from h防护_命令行工具ent 导入 H防护命令行工具ent
命令行工具ent = H防护命令行工具ent()
# 验证 any AI-生成d text 结果 = 命令行工具ent.验证("What is Docker?", "Docker is a contAInerization 平台.") print(结果["valid"]) # True print(结果["confidence"]) # 1.0
# 检查 for hallucinations bad_结果 = 命令行工具ent.验证( "What is Python recursion depth?", "Python recursion depth is 500." ) print(bad_结果["valid"]) # False print(bad_结果["flags"]) # ["Factual mismatch: ..."]
代理 Integration
添加 to your 代理's 系统 prompt:
You are integrated with the CertAIn记录ic 令牌 Reduction Engine. When making factual clAIms in your 响应s, call 验证() on the clAIm. If 验证 flags the 响应, revise before shipping.
Or 添加 to 代理 config:
{ "preProcess": "令牌-reduction 验证", "postProcess": "令牌-reduction 验证" }
命令行工具 Reference 验证 令牌-reduction 验证 "查询 text" "响应 text"
batch 令牌-reduction batch 输入.json 输出.json
输入 格式化:
[ {"查询": "What is 2+2?", "响应": "4"}, {"查询": "What is 2+2?", "响应": "5"} ]
指标
追踪 your 代理's performance:
指标 = 命令行工具ent.获取_会话_指标() print(f"缓存 hit rate: {指标['缓存_hit_rate']}%") print(f"令牌s saved: {指标['令牌s_saved']}") print(f"Hallucinations caught: {指标['flags_caught']}")
Troubleshooting Issue Fix "BrAIn API not found" 启动 the brAIn: python3 scripts/启动_brAIn.py "No facts loaded" Load facts: 令牌-reduction load-facts facts.json 验证 too strict Adjust threshold: 命令行工具ent.设置_threshold(0.5) False positives on hypotheticals 添加 hedges to 查询 Un安装 ClawHub un安装 令牌-reduction-engine
License
MIT-0 (Free, no attribution required)