Skip to main content

接入決策模型

透過 AI 工具的擴充機制接入決策模型:以評論自動審核為例,一次請求並行判定多條評論,返回 choice、probabilities、confidence,依信賴度自動放行、自動隱藏或轉人工。

背景:為什麼使用決策模型

評論審核、工單分類、請求路由這類判斷,常見做法是讓對話模型輸出 JSON:判定規則寫在 prompt 裡,容易被誘導性內容帶偏;輸出外層常包著程式碼圍欄,解析不穩定;而且模型會先生成一段分析文字,增加權杖成本。 將 state(待判定內容)和 questions(類型化問題)發送到 /compatible-mode/v1/systemone 端點,即可取得結構化答案:choice(結論)、probabilities(分布)、confidence(把握),不會生成自然語言文字。問題分為三種類型:Choice(從選項中選擇)、Score(按有序等級評分)和 Noul(返回 0 到 1 的機率),一次呼叫可以混合多個問題並行評估。 與讓對話模型「順手分類一下」相比:
  • 判定標準寫在 criteria 欄位裡結構化傳入,不依賴長 prompt 的措辭
  • 返回就是 JSON,沒有圍欄、沒有多餘文字,Agent 與程式碼可直接使用
  • 答案是短結構而非長文字,輸出權杖開銷小,適合高頻呼叫

請求與回應

請求地址:https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/systemone 鑑權:Authorization: Bearer $ANTHROPIC_AUTH_TOKEN,值為 Token Plan 套餐 API Key(sk-sp- 前綴)。 呼叫會消耗 Credits,計費規則見用量與額度。本文範例使用 decision-model。 請求體欄位:
欄位類型必選說明
modelString是decision-model
stateString / Object / Array是待判定的內容,可以是文字、物件或陣列
imageObject否單張圖片輸入。url 傳入公網圖片地址或 Base64 Data URL
imagesArray否多張圖片輸入。每個問題最多 4 張,每個請求最多 16 張
questionsObject是問題對應表。key 可自訂,value 為問題物件
問題物件的 type 支援 choice(從選項中選擇)、noul(返回 0 到 1 的機率)和 score(按等級評分);instructions 寫判定要求,criteria 寫選項或等級定義。 返回欄位:
  • answers:按問題 ID 返回的答案。
  • choice:choice 類型選中的選項。
  • noul:noul 類型的 P(yes),範圍 0 到 1。
  • score:score 類型的機率加權等級索引期望值,可落在兩個等級之間。
  • probabilities:每個選項或等級的機率,總和為 1。
  • confidence:choice 和 score 答案的信賴度。
  • legend:score 類型的等級索引對等級描述的映射。
  • usage.input_tokens:輸入權杖數。
  • request_id:請求 ID,用於問題排查。
  • latency_ms:服務端延遲,單位為毫秒。

範例:在 Claude Code 中接入評論審核

本文以 Claude Code 為例,透過 Slash Command 接入決策模型。其他工具的接入方式類似,差別在於擴充機制和設定檔路徑不同。

步驟一:建立 Slash Command

將套餐 API Key(以 sk-sp- 為前綴)設定為環境變數 $ANTHROPIC_AUTH_TOKEN,供後續 curl 鑑權使用。 在專案根目錄建立 .claude/commands/review-comments.md,寫入以下內容:
Call the Token Plan decision model to moderate comments in batch and route them by confidence.

User input: $ARGUMENTS (a comments file path, or multiple comments pasted directly)

## Steps

1. Read the comments. If $ARGUMENTS is a file path, read that file; if it is text, use it directly. One comment per line, skip empty lines, number them starting from 1.

2. Call the decision model endpoint (run curl with the Bash tool) and judge all comments in one request. Each comment maps to one c<number> question in questions, with the same structure as c1 and the id in instructions replaced accordingly:

```
curl -s -X POST "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/systemone" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "state": {
      "comments": [
        {"id": 1, "text": "<comment 1>"},
        {"id": 2, "text": "<comment 2>"}
      ]
    },
    "model": "decision-model",
    "questions": {
      "c1": {
        "type": "choice",
        "instructions": "Which category does the comment with id 1 in `comments` belong to?",
        "criteria": {
          "pass": "Normal discussion, including criticism, questions, and error reports",
          "spam": "Ad or scam solicitation, bulk marketing scripts, buying or selling accounts or course materials"
        }
      }
    }
  }'
```

3. Read the choice, confidence, and probabilities fields of c1, c2, ... one by one from answers in the returned JSON.

4. Determine an action for each comment by the following rules and output a table (number, comment summary, verdict, confidence, action):
   - confidence >= 0.9 and choice is spam: auto-hide
   - confidence >= 0.9 and choice is pass: auto-approve
   - confidence < 0.9: human review

5. After the table, output one summary line: X comments handled automatically, Y sent to human review. For each human-review entry, add one sentence citing the spam probability from that entry's probabilities.

步驟二:審核評論

準備一份評論檔案 comments.txt,每行一條評論: 在 Claude Code 中輸入 /review-comments comments.txt,輸出範例: 輸出中有兩處值得留意:
  • #5 和 #9 是負評和報錯,均判為 pass。 判定反映的是內容性質,而非語氣。批評、質疑和報錯回饋屬於正常討論,這條規則寫在 criteria 裡。
  • #8 是帶連結的技術分享,信賴度 0.93,按 0.9 閾值自動隱藏。 內容介於分享與引流之間,spam 機率 0.96、pass 機率 0.04。信賴度高於閾值,因此自動處理。閾值寫在 Command 的第 4 步:調到 0.95,這條評論會轉人工;調低則更多自動處理。在 criteria 裡寫清邊界描述,有助於減少這類樣本轉入人工。

讀懂返回的三個欄位

答案會按 questions 中使用的 key 原樣返回,每個 Choice 答案包含:
欄位含義使用方式
choice選中的選項分支依據:放行或隱藏
probabilities每個選項的機率,總和為 1展示、排序、加權
confidence判定把握,0 到 1閾值分流:高信賴度自動執行,低信賴度轉人工
questions 中的 key 可自訂,不參與推理。需要「程度」類判斷時,改用 Noul(返回 0 到 1 的機率)或 Score(按等級評分),一次呼叫可以混合使用。

範例:圖像判定

decision-model 支援圖像輸入。將圖片地址傳入 image,與 state 一起用於判定:
curl -s -X POST "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/systemone" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "decision-model",
    "state": "Judge the content of the image.",
    "image": {"url": "https://dashscope.oss-cn-beijing.aliyuncs.com/images/dog_and_girl.jpeg"},
    "questions": {
      "animal": {
        "type": "choice",
        "instructions": "What is in the image?",
        "criteria": {"dog": "Dog", "cat": "Cat", "other": "Other"}
      }
    }
  }'
返回範例:
{
  "model": "decision-model",
  "answers": {
    "animal": {
      "type": "choice",
      "choice": "dog",
      "confidence": 0.9967,
      "probabilities": {"dog": 0.9978, "cat": 0.0002, "other": 0.0020}
    }
  },
  "usage": {"input_tokens": 2859}
}
本機圖片可先轉為 Base64 Data URL(data:image/png;base64,...)後傳入。多張圖片使用 images 陣列。每個問題最多支援 4 張圖片,每個請求最多支援 16 張圖片。

其他工具

下表列出各工具的擴充機制和設定檔路徑,涵蓋支援擴充機制的主流 AI 程式設計工具。將上述 Claude Code 的設定內容儲存到對應路徑即可。
工具擴充機制設定檔路徑
Claude CodeSlash Command.claude/commands/review-comments.md
CodexSkill~/.codex/skills/token-plan-review/SKILL.md
Qwen CodeSkill~/.qwen/skills/review-comments/SKILL.md
OpenCodeAgent.opencode/agents/review-comments.md
OpenClawSkill~/.openclaw/workspace/skills/token-plan-review/SKILL.md
Hermes AgentSkill~/.hermes/skills/moderation/review-comments/SKILL.md
QoderSkill~/.qoder/skills/review-comments/SKILL.md
Skill 類工具(Codex、Qwen Code、OpenClaw、Hermes Agent、Qoder)需要在設定檔開頭加入 YAML front matter,完整設定檔如下:
---
name: "token-plan-review"
description: "Call the Token Plan decision model to moderate comments in batch and route them by confidence. Activated when the user asks to moderate or filter comments."
---

Call the Token Plan decision model to moderate comments in batch and route them by confidence.

User input: a comments file path, or multiple comments pasted directly.

## Steps

1. Read the comments. If the user input is a file path, read that file; if it is text, use it directly. One comment per line, skip empty lines, number them starting from 1.

2. Call the decision model endpoint (run curl with the Bash tool) and judge all comments in one request. Each comment maps to one c<number> question in questions, with the same structure as c1 and the id in instructions replaced accordingly:

```
curl -s -X POST "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/systemone" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "state": {
      "comments": [
        {"id": 1, "text": "<comment 1>"},
        {"id": 2, "text": "<comment 2>"}
      ]
    },
    "model": "decision-model",
    "questions": {
      "c1": {
        "type": "choice",
        "instructions": "Which category does the comment with id 1 in `comments` belong to?",
        "criteria": {
          "pass": "Normal discussion, including criticism, questions, and error reports",
          "spam": "Ad or scam solicitation, bulk marketing scripts, buying or selling accounts or course materials"
        }
      }
    }
  }'
```

3. Read the choice, confidence, and probabilities fields of c1, c2, ... one by one from answers in the returned JSON.

4. Determine an action for each comment by the following rules and output a table (number, comment summary, verdict, confidence, action):
   - confidence >= 0.9 and choice is spam: auto-hide
   - confidence >= 0.9 and choice is pass: auto-approve
   - confidence < 0.9: human review

5. After the table, output one summary line: X comments handled automatically, Y sent to human review. For each human-review entry, add one sentence citing the spam probability from that entry's probabilities.
OpenCode Agent 使用不同的 front matter 格式,完整設定檔如下:
---
description: "Call the Token Plan decision model to moderate comments in batch and route them by confidence."
mode: subagent
tools:
  bash: true
  write: false
  edit: false
---

Call the Token Plan decision model to moderate comments in batch and route them by confidence.

User input: a comments file path, or multiple comments pasted directly.

## Steps

1. Read the comments. If the user input is a file path, read that file; if it is text, use it directly. One comment per line, skip empty lines, number them starting from 1.

2. Call the decision model endpoint (run curl with the Bash tool) and judge all comments in one request. Each comment maps to one c<number> question in questions, with the same structure as c1 and the id in instructions replaced accordingly:

```
curl -s -X POST "https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/systemone" \
  -H "Authorization: Bearer $ANTHROPIC_AUTH_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "state": {
      "comments": [
        {"id": 1, "text": "<comment 1>"},
        {"id": 2, "text": "<comment 2>"}
      ]
    },
    "model": "decision-model",
    "questions": {
      "c1": {
        "type": "choice",
        "instructions": "Which category does the comment with id 1 in `comments` belong to?",
        "criteria": {
          "pass": "Normal discussion, including criticism, questions, and error reports",
          "spam": "Ad or scam solicitation, bulk marketing scripts, buying or selling accounts or course materials"
        }
      }
    }
  }'
```

3. Read the choice, confidence, and probabilities fields of c1, c2, ... one by one from answers in the returned JSON.

4. Determine an action for each comment by the following rules and output a table (number, comment summary, verdict, confidence, action):
   - confidence >= 0.9 and choice is spam: auto-hide
   - confidence >= 0.9 and choice is pass: auto-approve
   - confidence < 0.9: human review

5. After the table, output one summary line: X comments handled automatically, Y sent to human review. For each human-review entry, add one sentence citing the spam probability from that entry's probabilities.

注意事項

  • 判定邊界寫在 criteria 裡。將邊界案例(例如帶連結的技術分享)寫成明確的選項描述,比反覆調整問題措辭更有效。
  • 拆分複雜判斷:一次只問一個具體問題,各維度分開判定,再在 Command 的分流規則中組合結果。
  • confidence 偏低是模型明確表示不確定;轉人工比重新嘗試更有效。0.9 的閾值是範例值,請依誤判成本調整。
  • 依狀態碼處理失敗:401 檢查 API Key,422 表示請求體校驗失敗(回應主體會指出出錯欄位),429 和 529 退避後重試。
  • 模型輸出的是判定和把握,不是事實保證。涉及帳號封禁、資金處理等高風險動作時,請保留人工複核環節。