Skip to main content

工具呼叫授權 (Tool Call Consent)

當 Bot Provider 設定了需要使用者授權的 Toolset,Agent 呼叫工具前 SDK 會自動彈出授權 Modal, 請使用者對每筆工具呼叫做出決策,才繼續執行。

整合方無需額外接線ToolCallConsentGate 已內建於 <Chatbot> 元件中。

載入中…

三種決策

決策說明
Allow for This Chat核准此次呼叫,並在本次對話中自動核准後續所有相同工具的呼叫
Allow Once僅核准此次呼叫
Deny拒絕此次呼叫;可選填原因讓 Agent 知道為什麼被拒絕

自動略過規則

兩種情況下 SDK 不會彈 Modal,直接處理:

  1. alreadyAllowed: true — 後端標記為已授權(例如前一輪對話已 Allow for This Chat),自動 ALLOW_ONCE
  2. 本批次 Allow for This Chat — 同一批次中已對某工具選擇 Allow for This Chat,後續同 toolset / toolName 自動 ALLOW_ALWAYS

使用方式

不需要任何設定,只要 Bot Provider 的 Toolset 啟用了 consent,SDK 即自動處理:

<Chatbot
config={{
apiKey: 'your-api-key',
botProviderEndpoint: 'https://api.asgard-ai.com/ns/{namespace}/bot-provider/{botProviderId}',
}}
customChannelId="your-channel-id"
/>

Deny 兩步確認

為避免誤按,Deny 採兩步送出:

  1. 第一次按 Deny — 展開 Reason 輸入框,按鈕變為 Send Deny
  2. 第二次按 Send Deny — 才送出拒絕(Reason 可留空)

主題客製化

Modal 預設跟隨 Chatbot 的 --asg-color-* 設計 token,無需額外設定。 若需覆寫個別顏色,可在任意父層設定 CSS 變數:

.my-chatbot-wrapper {
--asgard-consent-modal-bg: #0f172a;
--asgard-consent-modal-accent: #6366f1;
--asgard-consent-modal-danger: #ef4444;
}
CSS 變數用途Fallback
--asgard-consent-modal-bgModal 背景色--asg-color-surface
--asgard-consent-modal-border邊框顏色--asg-color-border
--asgard-consent-modal-title標題 / 主文字色--asg-color-text-primary
--asgard-consent-modal-muted次要文字色--asg-color-text-secondary
--asgard-consent-modal-accent主色(Allow for This Chat 按鈕)--asg-color-primary
--asgard-consent-modal-danger危險色(Deny 按鈕)--asg-color-error
--asgard-consent-modal-input-bgDeny Reason 輸入框背景--asg-color-bg