置信度门控路由
置信度门控路由
把置信度当作第二条轴。答案告诉你该做什么;置信度告诉你该不该做。
TypeSafe 最强大的特性之一,是置信度。只要你有意识地把决策门控在置信度上,就能构建出既可靠又安全的系统。
示例:语音银行指令
设想你要做一个语音银行界面,让用户能口头操作自己的账户。解读用户意图时,你当然希望始终有说得过去的置信度,但有些操作比另一些风险更高,因而需要更高的置信度阈值。
%%{init: {"fontFamily": "Inter, sans-serif", "flowchart": {"rankSpacing": 35, "wrappingWidth": 300, "subGraphTitleMargin": {"top": 12, "bottom": 36}}}}%%
flowchart LR
command["voice banking command"]
subgraph req["TypeSafe evaluates<br/>the question"]
intent["<b>Choice:</b> intent"]
end
command -- "one request<br/>command + intent<br/>question" --> req
req -- "one response<br/>intent answer +<br/>confidence" --> gate{"<b>confidence high enough?</b><br/>your code"}
gate -- "below 0.6<br/>or other intent" --> human["send to a support agent"]
gate -- "check_balance<br/>at least 0.6" --> balance["show the balance"]
gate -- "approve_transfer<br/>0.6 to 0.85" --> confirm["ask the user to confirm"]
gate -- "approve_transfer<br/>above 0.85" --> approve["approve the transfer"]
第 1 步:判断用户意图
{
"intent": {
"type": "choice",
"instructions": "What action is the user requesting?",
"criteria": {
"check_balance": "Check the balance of an account",
"approve_transfer": "Approve the pending transfer request",
"other": "Something else"
}
}
}第 2 步:置信度门控路由
action = response.answers["intent"]
# Below 0.6 confidence on any action, route to a human
if action.confidence < 0.6:
route_to_support_agent(account_id)
elif action.choice == "check_balance":
# Low stakes. 0.6 confidence is sufficient.
show_balance(account_id)
elif action.choice == "approve_transfer":
if action.confidence > 0.85:
# High stakes, but high confidence. Safe to act automatically.
approve_transfer(account_id)
else:
# High stakes, moderate confidence. Verify intent first.
ask_user_to_confirm("Just to confirm: you would like to approve this transfer, is that correct?")
else:
route_to_support_agent(account_id)
0.6 这条底线,兜住的是模型确实拿不准的部分。底线之上,每种操作各自有阈值,取决于分类错了还要照做会有什么后果。以 0.6 的置信度去查余额没问题,因为最坏的情况不过是用户听一遍余额播报。但批准一笔转账需要很高的置信度(>0.85),否则系统就该请用户先确认一下。
想更详细地了解在系统里该如何看待置信度,见置信度。