confluence-partners.ai ↗

Area 3 · API 機制

真考高頻失分區:tool_choice 與順序編排/structured output 方法選擇/tool 分配 | 讀完 → Drill 3(快檢 10 + 情境 30)

3.1 tool_choice — 四個值背死

行為備註
{"type":"auto"}模型自己決定要不要用工具有給 tools 時的預設
{"type":"any"}必須用某個工具(哪個它挑)強制型
{"type":"tool","name":"x"}強制用指定工具強制型
{"type":"none"}禁用工具沒給 tools 時的預設
三個高頻事實:① disable_parallel_tool_use: true 寫在 tool_choice 物件裡面(不是 top-level 參數)——auto 時「最多一個」、any/tool 時「恰好一個」;② extended thinking 開啟時只能 auto / none,any/tool 直接報錯;③ 強制型(any/tool)副作用:模型不會在 tool_use 前輸出自然語言前言——要解釋文字就改用 auto + prompt,或在 schema 裡加 reasoning 欄位。
加碼事實:切換 tool_choice 會使 message 段的 prompt cache 失效(tool 定義與 system prompt 不受影響)——「每個 request 換 tool_choice 之後成本暴增」的題目答這個。

3.2 平行 tool use 與 tool_result 格式

assistant turn(一次回應)
  ├─ tool_use #1 (id: A)
  ├─ tool_use #2 (id: B)      ← 同回合多個 = 平行
  └─ tool_use #3 (id: C)
        ↓ 你執行(順序自選:並行/序列)
下一則 user message(一則、且 tool_result 全在文字之前)
  ├─ tool_result (id: A)
  ├─ tool_result (id: B, is_error: true ← 沒跑到也要回)
  └─ tool_result (id: C)

3.3 依賴工具的順序編排

官方鐵律原句:"if some tool calls depend on previous calls... do NOT call these tools in parallel... Never use placeholders or guess missing parameters in tool calls."
辨識訊號:log 裡下游工具的參數是編出來的 / placeholder(order_id: "TBD")→ 依賴呼叫被錯誤平行化。正解永遠是「序列化依賴呼叫」,不是加 orchestration layer、不是 retry。

3.4 結構化輸出 — 方法比較表(那條 0% 就是這張表)

方法保證強度機制用在
Structured Outputs(output_config + JSON schema)確定性(constrained decoding,語法永遠合法)解碼層約束抽取/分類的「回應本體」
Strict tool usestrict: true保證 tool input 合 schema同上「動作參數」(建單、退款)
Tool use + JSON schema(經典法)強(schema 約束 tool_use block)逼輸出走 tool callexam guide 語境的標準答案
Prompt-based(「請輸出 JSON」)無保證純指令低關鍵度
Prefill(預填 {無正式保證assistant 續寫舊模型的遺留技巧

3.5 Tool 分配 — Least Privilege

討論題(讀書會 session 用)

  1. tool_choice 四個值 + thinking 相容性,先默背一遍。然後:「必須回結構化 triage 但不限定哪個工具」用哪個值?
  2. 為什麼 tool_result 分開多則訊息回,會讓模型「以後不 batch」?從模型視角解釋。
  3. 「保證輸出合 schema」有三個不同層的機制(回應本體/工具參數/經典 tool use)——各自的參數名和適用場景?
  4. Prefill 是什麼、為什麼被淘汰、考題問「最可靠」時它為什麼永遠不是答案?
  5. 挑一個你們內部系統想像做成 MCP server:哪些操作該給哪個 agent、哪些絕不給?用 least privilege 講一遍。