ドキュメント

信頼度で分岐するルーティング

信頼度で分岐するルーティング

信頼度を第 2 の軸として使います。答えは何をするかを、信頼度は実行すべきかを教えてくれます。

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:ユーザーの意図を判定する

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)が必要で、そうでなければシステムはユーザーに確認を求めるべきです。

システムの中で信頼度をどう捉えるべきかの詳細は、信頼度を参照してください。