置信度门控路由
把置信度作为第二个维度——回答说明做什么,置信度决定是否行动——为每个问题设置最低置信度,并为每个行动设置 AND 规则。基于语音银行模板构建。
把置信度作为第二个维度:回答告诉你做什么,置信度告诉你是否据此行动。有些行动比其他行动风险更高,因此在系统自行执行之前需要更高的确定性。
收益:可靠性和安全性。TypeSafe 的指南:Confidence-gated routing。
为什么有效
Jev 经过训练,能返回校准过的概率:在大量回答中,给出约 80% 的那些回答应当约有 80% 是正确的。每个回答都带有一个由该分布得出的、介于 0 和 1 之间的置信度——当全部概率集中在一个回答上时为 1,当概率均匀分布时为 0。“我不确定”变成了你的系统可以据以路由的数字,而不是一个自信的错误回答。
一个实用的起点是三条路径:
| 置信度 | 行为 |
|---|---|
| 高 | 自动执行。 |
| 中 | 谨慎进行:请用户确认、标记待审核或收集更多信息。 |
| 低 | 不执行:转给人工、请求澄清或回退到另一个系统。 |
边界设在哪里取决于风险大小:阈值随风险而变化。以 60% 的置信度查询余额没有问题——最坏的情况只是显示了错误的页面。批准转账则不行。
何时使用
任何会产生后果的行动:付款、账户变更、删除、代表他人发送消息、删除内容的审核。把它与意图路由搭配使用:意图选择处理程序,置信度决定该处理程序能否独自行动。
如何对应到 Dcision
| 在 TypeSafe 的指南中 | 在 Dcision 中 |
|---|---|
if action.confidence < 0.6: route_to_support_agent() | 在问题上设置 minConfidence: 0.6——低于该值时,决策返回其 fallback 行动(escalate),且 action_reason.type = "low_confidence" |
elif choice == "approve_transfer" and confidence > 0.85: approve() | 每个高风险行动一条规则:intent = approve_transfer AND intent 的置信度低于 0.9 → escalate |
else: ask_user_to_confirm() | 你的代码把来自该规则的 escalate 映射为“请用户确认” |
| 兜底选项 | 保留的 other 选项,它同样返回 fallback 行动 |
先运行规则,然后是 other 检查,最后是 minConfidence——参见行动如何计算。
构建
在应用中
打开模板,选择语音银行指令(置信度把关)。把决策命名为 Voice Banking,使其 slug 为 voice-banking,然后点击创建决策。
状态为文本:你的语音转文字得到的指令转写。
唯一的问题 intent 是一个 choice:check_balance(只读)、transfer_money、approve_transfer、block_card 以及保留的 other。它的最低置信度已开启,为 60%——这是所有行动的下限。
在策略中,为每个高风险行动设置一条规则,并把该问题的置信度作为第二个条件:
- IF
intent· 回答 · = ·approve_transfer,+ ANDintent· 置信度 · < · 0.9——THENescalate。 - IF
intent· 回答 · = ·transfer_money,+ ANDintent· 置信度 · < · 0.8——THENescalate。
在引擎与运行时中,将 Fallback 动作保持为 escalate。对于必须始终作答的语音渠道,可以考虑 如果引擎出错 → 以 fallback 动作作答(参见决策设置)。测试后,点击部署 v1。
决策 schema
{
"stateSchema": { "kind": "text" },
"questions": [
{
"key": "intent",
"type": "choice",
"instructions": "What does the customer want to do with their account?",
"minConfidence": 0.6,
"options": [
{ "value": "check_balance", "description": "hear the balance or recent transactions (read-only)" },
{ "value": "transfer_money", "description": "start a new transfer to someone" },
{ "value": "approve_transfer", "description": "confirm a transfer that is waiting for approval" },
{ "value": "block_card", "description": "block or freeze a card" }
]
}
],
"policies": [
{
"field": "intent",
"on": "output",
"operator": "eq",
"value": "approve_transfer",
"and": [{ "field": "intent", "on": "confidence", "operator": "lt", "value": 0.9 }],
"action": "escalate"
},
{
"field": "intent",
"on": "output",
"operator": "eq",
"value": "transfer_money",
"and": [{ "field": "intent", "on": "confidence", "operator": "lt", "value": 0.8 }],
"action": "escalate"
}
],
"settings": { "fallbackAction": "escalate" }
}调用
状态就是转写文本,以字符串形式发送:
curl -X POST https://api.dcision.io/v1/decisions/voice-banking \
-H "Authorization: Bearer $DCISION_API_KEY" \
-H "Content-Type: application/json" \
-d '{ "state": "Yeah, go ahead and approve that payment to my landlord." }'{
"decision_id": "dec_Wb3Kq9Tz1Lm7Xv5Rn2Hd",
"execution_id": "exec_Pz8Nc4Wq1Ht6Ks3Lm9Vb",
"schema": "voice-banking",
"version": 1,
"result": { "intent": "approve_transfer" },
"confidence": { "intent": 0.8125 },
"action": "escalate",
"action_reason": { "type": "policy", "rule": 0 },
"metrics": {
"latency_ms": 248,
"engine": "jev",
"model": "jev-1.13.0",
"estimated_cost_usd": 0.00001008,
"input_tokens": 240,
"output_tokens": 14
}
}意图足够清晰,越过了 60% 的下限,但批准转账需要 90%:规则 0 进行升级处理。同一个决策在其他指令上的表现:
| 指令 | result.intent | confidence.intent | action | action_reason |
|---|---|---|---|---|
| "Yeah, go ahead and approve that payment to my landlord." | approve_transfer | 0.8125 | escalate | { "type": "policy", "rule": 0 } |
| "What's my balance?" | check_balance | 0.95 | continue | { "type": "default" } |
| "Uh, the thing from before, with the money" | check_balance | 0.4 | escalate | { "type": "low_confidence", "question": "intent", "confidence": 0.4, "minConfidence": 0.6 } |
| "Change my mailing address" | other | 0.9 | escalate | { "type": "other_option", "question": "intent" } |
据此行动
action_reason 可以区分两种 escalate:一种是因为高风险行动不够确定而触发了规则——请确认;另一种是决策没有理解——请转交:
const decision = await response.json();
const { action, action_reason: reason, result } = decision;
if (action === "continue") return perform(result.intent, account);
if (reason.type === "policy") {
// A risky intent below its threshold: verify instead of acting.
return voice.ask(`Just to confirm: you want to ${describe(result.intent)}, is that right?`);
}
return transferToAgent(call, { reason }); // low_confidence, other_option or engine_error调优
- 先保守,再衡量。 通过
GET /v1/executions或执行记录页面获取最近的运行,把confidence与实际发生的情况进行比较,然后分别调整每个阈值。 - 每个风险级别一条规则。 一个决策最多有 50 条规则,每条最多 5 个
and条件——足以按行动、按客户等级或按你在代码中计算的金额区间分别设置阈值。 - 选项变化时重新检查阈值。 choice 的置信度衡量的是最高选项高出所有选项(包括
other)均匀分布多少:增加或删除选项会改变这个刻度。 - probability 问题的置信度不同。 对于是/否的 probability,置信度为
|2p − 1|:minConfidence为 0.6 会标记所有介于 0.2 和 0.8 之间的p——参见置信度与概率。 - 让错误走同一条路径。 使用
onEngineError: "fallback"时,引擎故障会以escalate作答,且action_reason.type = "engine_error",而不是返回 HTTP 错误——由上面代码的最后一行处理。
相关内容:处理低置信度和 other · 意图路由