Skip to main content

意思決定モデルの接続

AI ツールの拡張メカニズムを介して意思決定モデルを接続します。コメントの自動モデレーションを例に、1 回のリクエストで複数のコメントを並列に判定し、choice、probabilities、confidence を返して、信頼度に基づく自動承認、自動非表示、または人によるレビューを行います。

背景:意思決定モデルを使う理由

コメントモデレーション、チケットの振り分け、リクエストのルーティングは、いずれも判断を伴うタスクです。一般的な方法は、チャットモデルに JSON を出力させることです。判定ルールはプロンプトに記述するため、誘導的な内容に影響されて判断がぶれる可能性があります。出力はコードフェンスで囲まれることが多く、解析が不安定になります。また、モデルは最初に分析の文章を生成するため、トークンのコストが増加します。 /compatible-mode/v1/systemone エンドポイントに state(判定対象の内容)と questions(型付きの質問)を送信すると、構造化された回答が返ります。choice(判定結果)、probabilities(確率分布)、confidence(信頼度)です。自然言語テキストは生成されません。質問には Choice(選択肢から選ぶ)、Score(順序付けられた段階で評価する)、Noul(0 から 1 の確率を返す)の 3 つのタイプがあり、1 回の呼び出しで複数の質問を混在させて並列に評価できます。 チャットモデルに「ざっと判定してもらう」場合と比較すると、次の点が異なります:
  • 判定基準は criteria フィールドで構造化して渡すため、長いプロンプトの言い回しに依存しません
  • レスポンスは JSON で、コードフェンスや余分な文章がなく、エージェントやコードがそのまま利用できます
  • 回答は長いテキストではなく短い構造であるため、出力トークンのコストを抑えられ、高頻度の呼び出しに適しています

リクエストとレスポンス

エンドポイント:https://token-plan.ap-southeast-1.maas.aliyuncs.com/compatible-mode/v1/systemone 認証:Authorization: Bearer $ANTHROPIC_AUTH_TOKEN に、Token Plan サブスクリプションの API キー(sk-sp- プレフィックス)を設定します。 呼び出しは Credits を消費します。課金ルールについては、使用量とクォータをご参照ください。本トピックの例では decision-model を使用します。 リクエスト本文のフィールド:
フィールド型必須説明
modelStringはいdecision-model
stateString / Object / Arrayはい判定対象の内容。テキスト、オブジェクト、または配列で指定します
imageObjectいいえ単一画像の入力。url には公開画像の URL または Base64 Data URL を指定します
imagesArrayいいえ複数画像の入力。各質問で最大 4 枚、各リクエストで最大 16 枚です
questionsObjectはい質問のマップ。キーは任意で、値は質問オブジェクトです
質問の 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 を介して意思決定モデルを接続します。その他のツールも同様の手順で、異なるのは拡張メカニズムと設定ファイルのパスのみです。

ステップ 1:Slash Command を作成する

サブスクリプションの API キー(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.

ステップ 2:コメントをモデレーションする

1 行に 1 件のコメントを記述したコメントファイル comments.txt を用意します: Claude Code で /review-comments comments.txt を入力します。出力例: 出力で注目すべき点が 2 つあります:
  • #5 と #9 は批判とエラーレポートですが、いずれも pass と判定されています。 判定は内容の性質によるもので、口調によるものではありません。批判、質問、エラーレポートは正常な議論と見なされます。このルールは criteria に記述されています。
  • #8 はリンク付きの技術的な共有で、confidence は 0.93、0.9 のしきい値で自動的に非表示になっています。 内容は共有と勧誘の中間に位置し、spam の確率は 0.96、pass の確率は 0.04 です。confidence がしきい値を上回っているため、自動処理されます。しきい値は Command のステップ 4 にあります。0.95 に設定するとこのコメントは人によるレビューに回り、低く設定すると自動処理の範囲が広がります。criteria に境界を明確に記述すると、このようなサンプルが人によるレビューに回るのを減らせます。

レスポンスの 3 つのフィールドを理解する

回答は、questions で使用したキーと同じキーで返されます。各 Choice の回答には次のフィールドが含まれます:
フィールド意味使用方法
choice選択された選択肢分岐の基準:承認するか非表示にするか
probabilities各選択肢の確率(合計は 1)表示、並べ替え、重み付け
confidence判定の信頼度(0 から 1)しきい値による振り分け:高い場合は自動実行、低い場合は人によるレビュー
questions のキーは任意で、推論には関与しません。「程度」を表す判断が必要な場合は、Noul(0 から 1 の確率を返す)または Score(段階で評価する)に切り替えてください。1 回の呼び出しで混在させることもできます。

例:画像判定

decision-model は画像入力をサポートしています。image に画像の URL を渡し、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 に記述します。境界的なケース(リンク付きの技術的な共有など)を明示的な選択肢の説明として記述する方が、質問の言い回しを繰り返し調整するより効果的です。
  • 複雑な判断は分割します。一度に 1 つの具体的な質問を尋ね、各次元を個別に判定し、結果を Command の振り分けルールで組み合わせます。
  • confidence が低いことは、モデルが不確実性を明示的に示している状態です。再試行するより、人によるレビューに回す方が効果的です。しきい値 0.9 は例示値であり、誤判定のコストに応じて調整してください。
  • 失敗はステータスコードに応じて処理します。401 は API キーを確認し、422 はリクエスト本文の検証失敗(レスポンス本文に問題のあるフィールドが示されます)を意味し、429 と 529 はバックオフ後に再試行します。
  • モデルが出力するのは判定とその確実性であり、事実の保証ではありません。アカウントの凍結や資金の処理などリスクの高い操作では、人によるレビューのステップを維持してください。