本页内容
Sommatic 文档
打开控制台

Triage Classifier

基于策略驱动的决策规则执行分层受理分诊。

以 Markdown 查看
在以下应用中打开
AI 可用 ai.classify.triage 版本 1.0.0 执行方式: async

借助模型把一条进件归入分类资源中的一个类别和子类别,再规范化回答:概率、置信度、路由提示、分类门控以及 needs_review 标记。对模型的暂时性故障会重试。

该算子将文本归入类别 + 子类别体系,给出置信度以及跨类别的完整概率分布,生成路由提示,并同时返回适合审计和人工复核的简要说明与更详细的理由。

典型适用场景

  • 政府/法律受理分诊(PQRS、tutela、hábeas corpus 等)
  • 带策略规则的企业事件路由
  • 具有可追溯依据的多级分类体系归类

工作原理

  1. 合并上游载荷与节点配置(以配置为准)。从 knowledge_resource_id(content.structured_data.categories)加载类别;未设置时回退到内联的 taxonomy.categories。
  2. 构建输入:若 text 为非空字符串则直接使用;否则用 channel、sender、subject 和 body(或 body.data.email.body)拼出 Channel:、Sender:、Subject:、Body: 各行。
  3. 发送系统提示词,包含每个类别、其定义及展平后的子类别树,以及 general_considerations、decision_rules 和 routing_hints_catalog,要求严格 JSON,temperature: 0。
  4. 调用模型,遇到 HTTP 5xx、429 及无状态码的错误时进行有限次数重试(指数退避加随机抖动)。
  5. 将回答解析为 JSON(去除代码块标记,失败时截取第一个 { 到最后一个 })。category 与分类做不区分大小写的匹配(未知名称原样保留),subcategory 仅在属于该类别时保留。
  6. 应用分类门控:类别或子类别可声明 gate.requires_any_regex / gate.forbids_any_regex(不区分大小写)。门控失败会清空子类别(除非 on_fail.null_subcategory: false),可按 on_fail.set_category / set_subcategory 改写,并记入 gate_failed,同时强制 needs_review: true。
  7. 缺失的概率补 0 并归一化使总和为 1,confidence 取所选类别的概率,只保留目录中的路由提示,然后从 success 输出。

在工作流中

节点在工作流文件(draft_nodes[])中的写法,以及一次成功运行的 envelope。

{
  "node_id": "node-triage-intake",
  "label": "Triage intake",
  "operator_slug": "ai.classify.triage",
  "operator_version": "1.0.0",
  "config": {
    "knowledge_resource_id": "<knowledge_resource_id>",
    "subject": "{{ $json.subject }}",
    "body": "{{ $json.body }}",
    "sender": "{{ $json.from }}",
    "channel": "email",
    "general_considerations": [
      "Prefer the most specific category."
    ],
    "decision_rules": [
      "Refund requests are Billing, even when they mention a product."
    ],
    "routing_hints_catalog": [
      "finance-queue",
      "support-queue"
    ],
    "confidence_threshold": 0.7,
    "language": "en",
    "llm_provider_id": "wf-llm-provider-xxxx",
    "invocation_mode": "sync",
    "llm_retry_max_attempts": 3
  }
}

配置

knowledge_resource_id string 必填

包含分诊所用类别和子类别的知识资源(类型:taxonomy)。

general_considerations array<string> 可选

分诊时应始终考虑的高层规则。

默认值: []

decision_rules array<string> 可选

显式的决策/路由规则(具体性、优先级、例外情况)。

默认值: []

routing_hints_catalog array<string> 可选

模型可以建议的路由提示白名单(可选)。

默认值: []

confidence_threshold number 可选

置信度低于此阈值时,输出会被标记为 needs_review。

默认值: 0.7

language string 可选

说明/理由及解读所使用的语言。示例:“es”“en”。

默认值: es

llm_provider_id string 可选

`LlmProviderModel` 记录的 `id`(例如 `wf-llm-provider-*`)。编排器将调用委托给后端:sync 模式调用 `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke`,stream 模式调用 `POST /chat/conversation/execute/stream-ephemeral`(SSE)。后端根据该记录解析 endpoint + api-key + deployment,并路由到相应的适配器(Azure OpenAI、Azure Foundry、OpenAI、AWS Bedrock、Google Vertex、Link Loom Cloud、Generic)。在 webapp 的 `/cognitive-assets/llm-provider/*` 中管理。

invocation_mode string 可选

LLM 调用的传输方式。`sync` 发起一个短 HTTP 请求并阻塞直到收到完整响应(适合快速推理:分类、短文本生成)。`stream` 在 token 到达时通过 SSE 逐步接收(长文本生成或输出可能超出 HTTP 超时时必须使用)。默认为 `sync`。

默认值: sync

可选值: syncstream

timeout_ms integer 可选

等待调用完成的最长时间(stream 模式下为分块之间的空闲超时)。sync 默认 30000,stream 默认 600000。

llm_retry_max_attempts integer 可选

LLM 调用遇到瞬时故障(HTTP 5xx、429、网络/超时)时的总尝试次数。设为 1 即禁用重试。未设置时依次回退到 execution.maxTries 和 3。硬上限为 5。

默认值: 3

llm_retry_backoff_ms integer 可选

LLM 重试之间指数退避的基础延迟(等待时间 = base * 2^(attempt-1) + 抖动,上限为 llm_retry_max_wait_ms)。未设置时依次回退到 execution.waitBetweenTries 和 1500。

默认值: 1500

llm_retry_max_wait_ms integer 可选

LLM 重试之间单次退避等待的上限。硬上限为 30000。

默认值: 20000

支持通用执行设置:重试(retryOnFail、maxTries、waitBetweenTries)与超时。

代码中的行为

除 schema 描述之外,实现代码对这些键的实际处理。

llm_retry_max_attempts
总尝试次数,硬上限 5。未设置时:execution.retryOnFail 为 false 则为 1,否则取 execution.maxTries,再否则为 3。
llm_retry_backoff_ms
基础等待时间,每次重试翻倍并加上最多 250 毫秒的随机抖动。未设置时使用 execution.waitBetweenTries,否则为 1500。
llm_retry_max_wait_ms
单次等待上限,默认 20000,硬上限 30000。
execution
与其他节点不同,这里会把 retryOnFail、maxTries 和 waitBetweenTries 作为模型调用的备用重试策略。
taxonomy
未声明。旧版内联分类 { categories: [...] },仅在 knowledge_resource_id 为空时使用。
text, subject, body, sender, channel
不在配置 schema 中,但会先从配置读取,再从上游载荷读取。
confidence_threshold
仅在模型未给出 needs_review 时使用:此时 needs_review 为 confidence < confidence_threshold。模型给出的 needs_review 优先,但门控失败时总会强制为 true。
timeout_ms
仅限 stream 模式:片段之间的空闲超时,默认 600000。在 sync 模式下不会作用于请求。

输出端口

success 默认

模型返回了带类别的有效 JSON。needs_review 表示是否需要人工复核。

数据
{
  "category": "Billing",
  "subcategory": "Refund",
  "confidence": 0.82,
  "probabilities": {
    "Billing": 0.82,
    "Technical": 0.12,
    "Sales": 0.06
  },
  "routing_hints": [
    "finance-queue"
  ],
  "notes": "Explicit refund request with an order number.",
  "justification": "The sender asks to reverse a charge on a paid order. Billing is more specific than Sales because no new purchase is discussed.",
  "needs_review": false,
  "gate_failed": [],
  "raw": null,
  "port": "success"
}
error

缺少输入或分类、模型调用在重试后仍失败,或回答不是可用的 JSON。

数据
{
  "error": "Model did not return valid JSON output"
}

在表达式中

后续节点可通过 $("Triage Classifier").item.json.<路径> 读取此节点输出中的内容(请把 Triage Classifier 换成你的节点标签)。Editor 标记工作流编辑器在 Previous Nodes 中提示的路径(输出契约);Worker 标记 worker 实际通过 success 返回的路径,依据“端口”一节所示的输出。

表达式EditorWorker
$("Triage Classifier").item.json.categorystring= "Billing"选定的主类别。
$("Triage Classifier").item.json.subcategorystring | null= "Refund"适用时为选定的子类别,否则为 null。
$("Triage Classifier").item.json.confidencenumber= 0.82所选类别的置信度得分(0-1)。
$("Triage Classifier").item.json.probabilitiesobject= {…}各类别的概率分布。各值之和应约等于 1。
$("Triage Classifier").item.json.routing_hintsarray= […] (1)用于引导下游工作流的建议路由目标/提示。
$("Triage Classifier").item.json.notesstring= "Explicit refund request with an order number."简洁的 1-2 行说明,引用关键信号和规则。
$("Triage Classifier").item.json.justificationstring= "The sender asks to reverse a charge on a pai…"较详细的理由,说明推理过程和规则优先级。
$("Triage Classifier").item.json.needs_reviewboolean= false当置信度低于 confidence_threshold、输出校验较弱,或分类体系层级关卡未通过时为 true。
$("Triage Classifier").item.json.gate_failedarray= […] (0)输入未满足的层级关卡。分类体系中的类别或子类别可以声明 gate({ requires_any_regex, forbids_any_regex, on_fail });输入文本不满足时,所选子类别会被置空并强制 needs_review。没有关卡失败时为空数组。
$("Triage Classifier").item.json.rawobject= null供应商的原始响应,用于审计/调试(可选)。
$("Triage Classifier").item.json.probabilities.Billingnumber编辑器不提示= 0.82—
$("Triage Classifier").item.json.probabilities.Technicalnumber编辑器不提示= 0.12—
$("Triage Classifier").item.json.probabilities.Salesnumber编辑器不提示= 0.06—
$("Triage Classifier").item.json.portstring编辑器不提示= "success"—

— Worker: worker 会返回它,但编辑器不会提示:请手动输入。对象内部的键可能取决于你的数据或配置(例如每个标签一个键)。

错误

消息 端口 原因与处理
Missing input content (text/subject/body) error text、channel、sender、subject、body 均无内容。
No categories found for triage classification. Ensure the linked knowledge resource contains at least one category. error 分类资源中没有 structured_data.categories。
Model did not return valid JSON output error 回答无法解析为 JSON 对象。Missing 'category' in output 表示 JSON 中没有类别。
Knowledge resource not found: <knowledge_resource_id> error 该 id 不对应任何知识资源。已删除的资源会报 Knowledge resource "<name>" has been deleted. Update the node config to reference an active resource.
[TriageClassifier] Missing 'llm_provider_id' in node config (LlmProviderModel.id, e.g. 'wf-llm-provider-*'). The legacy 'model_id' alias is no longer supported — update the node config to use 'llm_provider_id'. error llm_provider_id 为空或不是字符串。请选择具备 chat 能力的 LLM 提供方记录。
LLM Invocation Error: <backend message> error 后端拒绝了调用:提供方记录不存在或未激活、提供方报错、配额或内容过滤。请检查提供方记录和后端日志。
LLM Invocation Error: empty response from backend (<transport error>) error sync 模式:对后端的 HTTP 调用失败(网络错误、非 2xx 状态或超时)。长提示词常会触发请求超时,请改用 invocation_mode: "stream"。
RemoteApiService.stream: idle timeout after <timeout_ms>ms error stream 模式:在 timeout_ms 内未收到任何片段。若流式请求本身失败,消息为 RemoteApiService.stream: HTTP <status> — <body>。

输入契约

text string 可选

要分类的主要文本内容。

subject string 可选

可选的主题行(邮件/表单)。

body string 可选

可选的正文内容。

sender string 可选

可选的发送方(邮箱/域名/标识符)。

channel string 可选

可选的渠道标识(email、form、api 等)。

metadata object 可选

可选的任意元数据(请求头、标签等)。

输出契约

category string 必填

选定的主类别。

subcategory string | null 必填

适用时为选定的子类别,否则为 null。

confidence number 必填

所选类别的置信度得分(0-1)。

probabilities object 必填

各类别的概率分布。各值之和应约等于 1。

routing_hints array<string> 可选

用于引导下游工作流的建议路由目标/提示。

notes string 可选

简洁的 1-2 行说明,引用关键信号和规则。

justification string 可选

较详细的理由,说明推理过程和规则优先级。

needs_review boolean 可选

当置信度低于 confidence_threshold、输出校验较弱,或分类体系层级关卡未通过时为 true。

gate_failed array<object> 可选

输入未满足的层级关卡。分类体系中的类别或子类别可以声明 `gate`({ requires_any_regex, forbids_any_regex, on_fail });输入文本不满足时,所选子类别会被置空并强制 needs_review。没有关卡失败时为空数组。

raw object 可选

供应商的原始响应,用于审计/调试(可选)。

契约(JSON Schema)

与编排器声明完全一致的定义。All 是完整的 *.definition.js;可与上方各节对照,找出文档与 schema 之间的差异。发布前可用它校验节点。

{
  "slug": "ai.classify.triage",
  "name": "Triage Classifier",
  "category": "ai",
  "version": "1.0.0",
  "description": "Performs hierarchical intake triage with policy-driven decision rules.\n\nThis operator classifies text into a **category + subcategory** taxonomy, produces **confidence** and a full **probability distribution** across categories, generates **routing hints**, and returns both **notes** and a longer **justification** suitable for audits and human review.\n\n**Typical use cases**\n- Government / legal intake triage (PQRS, tutela, hábeas corpus, etc.)\n- Enterprise incident routing with policy rules\n- Multi-level taxonomy classification with traceable rationale",
  "capabilities": [
    "ai",
    "classification",
    "nlp",
    "taxonomy",
    "triage",
    "routing",
    "explainability"
  ],
  "knowledge_binding": {
    "enabled": true,
    "resource_types": [
      "taxonomy"
    ],
    "field": "knowledge_resource_id",
    "label": "Classification Taxonomy"
  },
  "config_schema": {
    "type": "object",
    "required": [
      "knowledge_resource_id"
    ],
    "properties": {
      "knowledge_resource_id": {
        "type": "string",
        "title": "Classification Taxonomy",
        "description": "Knowledge resource (type: taxonomy) containing the categories and subcategories for triage.",
        "x-ui-widget": "knowledge-resource-picker",
        "x-knowledge-resource-types": [
          "taxonomy"
        ]
      },
      "general_considerations": {
        "type": "array",
        "title": "General Considerations",
        "description": "High-level rules that should always be considered during triage.",
        "items": {
          "type": "string"
        },
        "default": []
      },
      "decision_rules": {
        "type": "array",
        "title": "Decision Rules",
        "description": "Explicit decision/routing rules (specificity, precedence, exceptions).",
        "items": {
          "type": "string"
        },
        "default": []
      },
      "routing_hints_catalog": {
        "type": "array",
        "title": "Routing Hints Catalog",
        "description": "Allowed routing hints that the model may suggest (optional).",
        "items": {
          "type": "string"
        },
        "default": []
      },
      "confidence_threshold": {
        "type": "number",
        "title": "Confidence Threshold",
        "description": "If confidence is below this threshold, the output will be flagged as needs_review.",
        "default": 0.7,
        "minimum": 0,
        "maximum": 1
      },
      "language": {
        "type": "string",
        "title": "Language",
        "description": "Language used for notes/justification and interpretation. Example: \"es\", \"en\".",
        "default": "es"
      },
      "llm_provider_id": {
        "type": "string",
        "title": "LLM Provider",
        "description": "The `id` of a `LlmProviderModel` record (e.g. `wf-llm-provider-*`). The orchestrator delegates to the backend: `POST /cognitive-infrastructure/cognitive-assets/llm-provider/invoke` for sync mode, or `POST /chat/conversation/execute/stream-ephemeral` (SSE) for stream mode. The backend resolves endpoint + api-key + deployment from the record and routes to the correct adapter (Azure OpenAI, Azure Foundry, OpenAI, AWS Bedrock, Google Vertex, Link Loom Cloud, Generic). Managed in the webapp at `/cognitive-assets/llm-provider/*`.",
        "x-ui-widget": "llm-provider-picker",
        "x-llm-provider-capabilities": [
          "chat"
        ]
      },
      "invocation_mode": {
        "type": "string",
        "title": "Invocation Mode",
        "description": "Transport for the LLM call. `sync` opens a short HTTP request and blocks until the full response arrives (ideal for fast inferences: classification, short generation). `stream` consumes tokens via SSE as they arrive (required for long generations or outputs that would exceed the HTTP timeout). Default `sync`.",
        "enum": [
          "sync",
          "stream"
        ],
        "default": "sync"
      },
      "timeout_ms": {
        "type": "integer",
        "title": "Timeout (ms)",
        "description": "Maximum time to wait for the invocation to complete (or, in stream mode, the idle timeout between chunks). Default 30000 for sync, 600000 for stream.",
        "minimum": 1000
      },
      "llm_retry_max_attempts": {
        "type": "integer",
        "title": "LLM Retry — Max Attempts",
        "description": "Total attempts for the LLM call on transient failures (HTTP 5xx, 429, network/timeout). 1 disables retry. Falls back to execution.maxTries, then 3. Hard-capped at 5.",
        "minimum": 1,
        "maximum": 5,
        "default": 3
      },
      "llm_retry_backoff_ms": {
        "type": "integer",
        "title": "LLM Retry — Base Backoff (ms)",
        "description": "Base delay for exponential backoff between LLM retries (wait = base * 2^(attempt-1) + jitter, capped by llm_retry_max_wait_ms). Falls back to execution.waitBetweenTries, then 1500.",
        "minimum": 0,
        "default": 1500
      },
      "llm_retry_max_wait_ms": {
        "type": "integer",
        "title": "LLM Retry — Max Wait (ms)",
        "description": "Ceiling for a single backoff wait between LLM retries. Hard-capped at 30000.",
        "minimum": 0,
        "default": 20000
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    }
  },
  "input_contract_schema": {
    "type": "object",
    "description": "Incoming content and optional metadata used for intake triage.",
    "properties": {
      "text": {
        "type": "string",
        "description": "Primary text content to classify."
      },
      "subject": {
        "type": "string",
        "description": "Optional subject line (email/form)."
      },
      "body": {
        "type": "string",
        "description": "Optional body content."
      },
      "sender": {
        "type": "string",
        "description": "Optional sender (email/domain/identifier)."
      },
      "channel": {
        "type": "string",
        "description": "Optional channel identifier (email, form, api, etc.)."
      },
      "metadata": {
        "type": "object",
        "description": "Optional arbitrary metadata (headers, tags, etc.).",
        "additionalProperties": true
      }
    }
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "category": {
        "type": "string",
        "description": "Selected primary category."
      },
      "subcategory": {
        "type": [
          "string",
          "null"
        ],
        "description": "Selected subcategory when applicable, else null."
      },
      "confidence": {
        "type": "number",
        "description": "Confidence score (0-1) for the selected category."
      },
      "probabilities": {
        "type": "object",
        "description": "Probability distribution across categories. Values should sum approximately to 1.",
        "additionalProperties": {
          "type": "number"
        }
      },
      "routing_hints": {
        "type": "array",
        "description": "Suggested routing targets / hints to guide downstream workflows.",
        "items": {
          "type": "string"
        }
      },
      "notes": {
        "type": "string",
        "description": "Concise 1-2 line explanation referencing key signals and rules."
      },
      "justification": {
        "type": "string",
        "description": "Longer justification explaining reasoning and rule precedence."
      },
      "needs_review": {
        "type": "boolean",
        "description": "True when confidence is below confidence_threshold, output validation is weak, or a taxonomy hierarchy gate failed."
      },
      "gate_failed": {
        "type": "array",
        "description": "Hierarchy gates that the input did NOT satisfy. A category or subcategory in the taxonomy may declare a `gate` ({ requires_any_regex, forbids_any_regex, on_fail }); when the input text does not satisfy it, the chosen subcategory is nulled and needs_review is forced. Empty array when no gate failed.",
        "items": {
          "type": "object",
          "properties": {
            "level": {
              "type": "string",
              "description": "'category' | 'subcategory'"
            },
            "name": {
              "type": "string"
            },
            "reason": {
              "type": "string"
            }
          }
        }
      },
      "raw": {
        "type": "object",
        "description": "Raw provider response for audit/debug (optional).",
        "additionalProperties": true
      }
    },
    "required": [
      "category",
      "subcategory",
      "confidence",
      "probabilities"
    ]
  },
  "ports": [
    {
      "port_id": "success",
      "label": "Classified",
      "is_default": true
    },
    {
      "port_id": "error",
      "label": "Error"
    }
  ],
  "execution_mode": "async",
  "tags": [
    "ai",
    "classifier",
    "triage",
    "taxonomy",
    "routing"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}

执行

执行方式
async
有状态
否
重试(retryOnFail)
是
能力
aiclassificationnlptaxonomytriageroutingexplainability
标签
aiclassifiertriagetaxonomyrouting

说明与限制

  • 缺少 llm_provider_id 以及其他没有 HTTP 状态码的错误也会被重试,因此配置错误会耗尽所有尝试及等待后才失败。
  • gate_failed 中每项为 { level, name, reason };reason 是固定的西班牙语字符串,例如 requires_any_regex: ninguno coincidió 或 forbids_any_regex coincidió: <pattern>。无效的正则会被忽略。
  • language(默认 es)只决定提示词中的语言说明行。
  • 该 worker 将字段直接放在返回值顶层而非 data 内,因此引擎把整个返回值存为节点输出:port 和 raw 会与结果字段一起出现在 $json 中。
  • 模型调用经由 Sommatic AI 后端完成,后端根据 llm_provider_id 指定的提供方记录解析端点、凭据和部署;编排器从不持有提供方密钥。invocation_mode: "sync"(默认)等待完整回答;"stream" 以 SSE 事件读取回答并拼接各片段。
  • timeout_ms 仅在 stream 模式下生效,表示片段之间允许的最长空闲时间(默认 600000)。在 sync 模式下该值只写入日志,不会作用于 HTTP 请求,因此以平台默认请求超时为准。
  • 在 stream 模式下,后端端点不应用采样参数,因此固定的 temperature: 0 仅在 sync 模式下生效。
  • 每次运行都会从后端读取知识资源(超时 10 秒)。状态不是 active 的资源仍会被使用,并在日志中记录警告。

已对照编排器代码核实 · 31e874b · 2026-11-26

安装智能体工具

为你的编程智能体接入 Sommatic AI 官方文档:技能包、文档 MCP 服务器与 Markdown 页面,无需再抓取网页。

仅安装技能包,不会自动更新;需要时重新运行即可。

npx skills add https://docs.sommatic.ai
智能体如何读取本文档