文档目录

推测式扇出

一次调用发送多个问题,包括推测式问题,再由代码决定哪些相关。

非官方中文翻译 · 内容以 英文原文 ↗ 为准 · 同步于 2026-10-15

由于 TypeSafe 支持在一次 API 调用中发送多个问题,我们建议把系统所需的全部问题放进同一次请求,再事后用代码判定哪些相关。所有问题都是并行评估的,因此增加问题对响应时间的影响通常很小。

示例:客服工单分流

假设你正在构建一个客服系统,需要对客服工单进行分流。你需要把工单归入一个类别。如果是 Bug 报告,还需要判断 Bug 的严重程度。

不必先问类别、再在后续调用里问严重程度,你可以同时问这两个。如果工单不是 Bug 报告,直接忽略 Bug 严重程度这一题的结果。

mermaid
%%{init: {"fontFamily": "Inter, sans-serif", "flowchart": {"rankSpacing": 35, "wrappingWidth": 300, "subGraphTitleMargin": {"top": 8, "bottom": 60}}}}%%
flowchart LR
    t["support ticket"]

    subgraph req["TypeSafe AI model<br/>evaluates each question<br/>against the ticket in parallel"]
        direction TB
        c["<b>Choice:</b> category"]
        b["<b>Score:</b> bug severity"]
        r["<b>Noul:</b> reproducible steps?"]
        f["<b>Noul:</b> refund requested?"]
        s["<b>Score:</b> frustration"]
        %% invisible links: without an edge these share a rank and sit side by side
        c ~~~ b ~~~ r ~~~ f ~~~ s
    end

    t -- "one request<br/>ticket + 5 questions" --> req
    req -- "one response: 5 answers<br/>decisions + probabilities" --> route{"<b>filter, combine, and route</b><br/>in your code"}
    route blue_bug@-- "bug_report" --> eng["read severity + repro steps<br/>escalate or backlog"]
    route orange_bill@-- "billing" --> bill["refund requested<br/>send to billing"]
    route purple_feat@-- "feature_request" --> feat["log it<br/>sent to devs"]
    %% Branch colours (styles.css): node classes and green_/blue_/purple_/orange_ edge ids.
    class eng neonBlue
    class bill neonOrange
    class feat neonPurple

步骤 1:推测式扇出

questions

json
{
  "model": "jev-latest",
  "state": "Hi, I placed an order (#98423) last Thursday and was charged twice. I also can't log in after the site update, and adding Apple Pay would be really helpful. This is getting frustrating.",
  "questions": {
    "category": {
      "type": "choice",
      "instructions": "Determine the broad category of this support ticket",
      "criteria": {
        "bug_report": "The user is reporting something that is broken or producing errors",
        "billing": "Charges, invoices, refunds, subscriptions",
        "feature_request": "The user is requesting new functionality",
        "account": "Login, permissions, profile, security"
      }
    },
    "bug_severity": {
      "type": "score",
      "instructions": "How severe is the reported issue",
      "criteria": [
        "Cosmetic; no impact to functionality",
        "Broken or degraded feature; workaround exists",
        "Blocking issue; no workaround exists"
      ]
    },
    "has_reproducible_steps": {
      "type": "noul",
      "instructions": "The user describes specific steps to reproduce the issue"
    },
    "refund_requested": {
      "type": "noul",
      "instructions": "The user is explicitly asking for a refund or credit"
    },
    "frustration": {
      "type": "score",
      "instructions": "How frustrated the user appears",
      "criteria": [
        "Calm, matter-of-fact",
        "Frustrated but civil",
        "Very angry"
      ]
    }
  }
}

步骤 2:用代码路由

你的代码根据分类结果决定哪些信息相关:

python
category = response.answers["category"]
bug_severity = response.answers["bug_severity"]
bug_repro = response.answers["has_reproducible_steps"]
refund = response.answers["refund_requested"]
frustration = response.answers["frustration"]

if category.choice == "bug_report":
    if bug_severity.score > 1.5 and bug_repro.noul > 0.6:
        escalate_to_engineering(ticket_id, severity="high")
    else:
        add_to_bug_backlog(ticket_id)

elif category.choice == "billing":
    if refund.noul > 0.7:
        route_to_billing_with_flag(ticket_id, refund_likely=True)
    else:
        route_to_billing(ticket_id)

elif category.choice == "feature_request":
    log_feature_request(ticket_id)

# Frustration is useful regardless of category
if frustration.score > 1.5:
    flag_for_priority_response(ticket_id)

构建完整决策树所需的一切都来自同一次调用。推测式问题在不相关时被忽略,在相关时则省去一次往返。

本文档由 Mintlify 构建和托管,Mintlify 是一个开发者文档平台。