文档目录
置信度分流
把置信度作为第二条判断轴。答案告诉你「是什么」,置信度告诉你「能不能直接行动」。
非官方中文翻译 · 内容以 英文原文 ↗ 为准 · 同步于 2026-10-15
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 red_low@-- "below 0.6<br/>or other intent" --> human["send to a support agent"]
gate orange_balance@-- "check_balance<br/>at least 0.6" --> balance["show the balance"]
gate yellow_confirm@-- "approve_transfer<br/>0.6 to 0.85" --> confirm["ask the user to confirm"]
gate green_approve@-- "approve_transfer<br/>above 0.85" --> approve["approve the transfer"]
%% Branch colours (styles.css): a confidence gradient, red -> orange -> yellow -> green.
class human neonRed
class balance neonOrange
class confirm neonYellow
class approve neonGreen步骤 1:确定用户意图
questions
{
"model": "jev-latest",
"questions": {
"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),否则系统应当先向用户确认一次。
关于如何在系统中理解和运用置信度,参见 置信度。
本文档由 Mintlify 构建并托管,它是一个面向开发者的文档平台。