Spring AI 集成 TypeSafe:用判断模型处理工单分流与链路决策
在 Agent 和 AI 应用开发中,大量场景其实并不需要大模型"深思熟虑"------意图识别、分类路由、数值评分这些判断任务,交给专门的判断模型(Judgment Model)会快得多、便宜得多。本文介绍如何在 Spring Boot 中通过官方 Starter 集成 TypeSafe,并用一个工单分流案例展示完整用法。
一、Maven 依赖与配置
如果要在 Spring Boot 里用,直接引入官方 Starter:
xml
<dependency>
<groupId>org.springaicommunity</groupId>
<artifactId>spring-ai-starter-typesafe</artifactId>
<version>0.2.0</version>
</dependency>
环境要求:JDK 17 和 Spring AI 2.0.1 以上。
接着把 API Key 填进 application.yml:
yaml
spring:
ai:
typesafe:
api-key: ${TYPESAFE_API_KEY}
配置好后,Spring Boot 就会自动把 TypeSafeClient 注入进容器。
二、工单分流测试案例
来看一个最典型的场景。客服系统收到了一条工单:
"Help! My payouts have been failing for 3 days."
(救命!我的提现已经连续失败 3 天了。)
我们想一次性搞清楚三件事:
- 这事急不急?
- 该派给财务、技术还是销售?
- 用户的沮丧程度大概是多少?
2.1 完整代码
java
package com.example.demo;
import java.util.Map;
import org.springaicommunity.typesafe.TypeSafeClient;
import org.springaicommunity.typesafe.question.Choice;
import org.springaicommunity.typesafe.question.Noul;
import org.springaicommunity.typesafe.question.Score;
import org.springaicommunity.typesafe.response.SystemOneResponse;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class TicketTriageRunner implements CommandLineRunner {
private final TypeSafeClient typeSafeClient;
public TicketTriageRunner(TypeSafeClient typeSafeClient) {
this.typeSafeClient = typeSafeClient;
}
@Override
public void run(String... args) {
String ticket = "Help! My payouts have been failing for 3 days.";
SystemOneResponse response = typeSafeClient.systemOne(
ticket,
Map.of(
// 是非题:是否紧急
"is_urgent", Noul.of("Does this convey urgency?"),
// 选择题:分派到哪个团队
"department", Choice.builder()
.instructions("Which team should handle this?")
.option("billing", "Payments, invoicing, refunds")
.option("technical", "Bugs, outages, integrations")
.option("sales", "Pricing, upgrades, new accounts")
.build(),
// 打分题:用户情绪
"frustration", Score.of("How frustrated is the customer?",
"Calm", "Frustrated", "Very angry")
)
);
// 取出来直接是 Java 原生类型
double urgency = response.noulValue("is_urgent"); // 0.95
String department = response.choiceValue("department"); // "billing"
double confidence = response.choice("department").confidence(); // 0.82
double frustration = response.scoreValue("frustration"); // 1.10
System.out.println("紧急度: " + urgency);
System.out.println("分流部门: " + department + ",置信度: " + confidence);
System.out.println("沮丧值: " + frustration);
}
}
2.2 三种决策类型
#mermaid-svg-jM2L3D9vBOIuqKSh{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-jM2L3D9vBOIuqKSh .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-jM2L3D9vBOIuqKSh .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-jM2L3D9vBOIuqKSh .error-icon{fill:#552222;}#mermaid-svg-jM2L3D9vBOIuqKSh .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-jM2L3D9vBOIuqKSh .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-jM2L3D9vBOIuqKSh .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-jM2L3D9vBOIuqKSh .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-jM2L3D9vBOIuqKSh .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-jM2L3D9vBOIuqKSh .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-jM2L3D9vBOIuqKSh .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-jM2L3D9vBOIuqKSh .marker{fill:#333333;stroke:#333333;}#mermaid-svg-jM2L3D9vBOIuqKSh .marker.cross{stroke:#333333;}#mermaid-svg-jM2L3D9vBOIuqKSh svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-jM2L3D9vBOIuqKSh p{margin:0;}#mermaid-svg-jM2L3D9vBOIuqKSh .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-jM2L3D9vBOIuqKSh .cluster-label text{fill:#333;}#mermaid-svg-jM2L3D9vBOIuqKSh .cluster-label span{color:#333;}#mermaid-svg-jM2L3D9vBOIuqKSh .cluster-label span p{background-color:transparent;}#mermaid-svg-jM2L3D9vBOIuqKSh .label text,#mermaid-svg-jM2L3D9vBOIuqKSh span{fill:#333;color:#333;}#mermaid-svg-jM2L3D9vBOIuqKSh .node rect,#mermaid-svg-jM2L3D9vBOIuqKSh .node circle,#mermaid-svg-jM2L3D9vBOIuqKSh .node ellipse,#mermaid-svg-jM2L3D9vBOIuqKSh .node polygon,#mermaid-svg-jM2L3D9vBOIuqKSh .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-jM2L3D9vBOIuqKSh .rough-node .label text,#mermaid-svg-jM2L3D9vBOIuqKSh .node .label text,#mermaid-svg-jM2L3D9vBOIuqKSh .image-shape .label,#mermaid-svg-jM2L3D9vBOIuqKSh .icon-shape .label{text-anchor:middle;}#mermaid-svg-jM2L3D9vBOIuqKSh .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-jM2L3D9vBOIuqKSh .rough-node .label,#mermaid-svg-jM2L3D9vBOIuqKSh .node .label,#mermaid-svg-jM2L3D9vBOIuqKSh .image-shape .label,#mermaid-svg-jM2L3D9vBOIuqKSh .icon-shape .label{text-align:center;}#mermaid-svg-jM2L3D9vBOIuqKSh .node.clickable{cursor:pointer;}#mermaid-svg-jM2L3D9vBOIuqKSh .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-jM2L3D9vBOIuqKSh .arrowheadPath{fill:#333333;}#mermaid-svg-jM2L3D9vBOIuqKSh .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-jM2L3D9vBOIuqKSh .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-jM2L3D9vBOIuqKSh .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-jM2L3D9vBOIuqKSh .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-jM2L3D9vBOIuqKSh .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-jM2L3D9vBOIuqKSh .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-jM2L3D9vBOIuqKSh .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-jM2L3D9vBOIuqKSh .cluster text{fill:#333;}#mermaid-svg-jM2L3D9vBOIuqKSh .cluster span{color:#333;}#mermaid-svg-jM2L3D9vBOIuqKSh div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-jM2L3D9vBOIuqKSh .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-jM2L3D9vBOIuqKSh rect.text{fill:none;stroke-width:0;}#mermaid-svg-jM2L3D9vBOIuqKSh .icon-shape,#mermaid-svg-jM2L3D9vBOIuqKSh .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-jM2L3D9vBOIuqKSh .icon-shape p,#mermaid-svg-jM2L3D9vBOIuqKSh .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-jM2L3D9vBOIuqKSh .icon-shape .label rect,#mermaid-svg-jM2L3D9vBOIuqKSh .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-jM2L3D9vBOIuqKSh .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-jM2L3D9vBOIuqKSh .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-jM2L3D9vBOIuqKSh :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} TypeSafe 三种决策类型
Noul
是非题:0-1 概率
Choice
选择题:预定义选项
Score
打分题:0-1 分数
is_urgent = 0.95
department = billing
confidence = 0.82
frustration = 1.10
| 类型 | 用途 | 本案例中的问题 |
|---|---|---|
| Noul | 是/否概率判断 | "Does this convey urgency?" |
| Choice | 从预定义选项选一个 | "Which team should handle this?" |
| Score | 打一个 0-1 之间的分数 | "How frustrated is the customer?" |
三、Jev 决策模型的优势
3.1 快得离谱
最直接的感受就是快 。因为不用等大模型一个个往外蹦字,三个问题并发算下来,通常也就两三百毫秒 ,消耗的 Token 只有几十个。
3.2 返回值设计解决工程痛点
真正解决工程痛点的是它的返回值设计:
#mermaid-svg-MwDkOqG1o8hmEF3X{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-MwDkOqG1o8hmEF3X .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-MwDkOqG1o8hmEF3X .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-MwDkOqG1o8hmEF3X .error-icon{fill:#552222;}#mermaid-svg-MwDkOqG1o8hmEF3X .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-MwDkOqG1o8hmEF3X .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-MwDkOqG1o8hmEF3X .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-MwDkOqG1o8hmEF3X .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-MwDkOqG1o8hmEF3X .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-MwDkOqG1o8hmEF3X .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-MwDkOqG1o8hmEF3X .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-MwDkOqG1o8hmEF3X .marker{fill:#333333;stroke:#333333;}#mermaid-svg-MwDkOqG1o8hmEF3X .marker.cross{stroke:#333333;}#mermaid-svg-MwDkOqG1o8hmEF3X svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-MwDkOqG1o8hmEF3X p{margin:0;}#mermaid-svg-MwDkOqG1o8hmEF3X .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-MwDkOqG1o8hmEF3X .cluster-label text{fill:#333;}#mermaid-svg-MwDkOqG1o8hmEF3X .cluster-label span{color:#333;}#mermaid-svg-MwDkOqG1o8hmEF3X .cluster-label span p{background-color:transparent;}#mermaid-svg-MwDkOqG1o8hmEF3X .label text,#mermaid-svg-MwDkOqG1o8hmEF3X span{fill:#333;color:#333;}#mermaid-svg-MwDkOqG1o8hmEF3X .node rect,#mermaid-svg-MwDkOqG1o8hmEF3X .node circle,#mermaid-svg-MwDkOqG1o8hmEF3X .node ellipse,#mermaid-svg-MwDkOqG1o8hmEF3X .node polygon,#mermaid-svg-MwDkOqG1o8hmEF3X .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-MwDkOqG1o8hmEF3X .rough-node .label text,#mermaid-svg-MwDkOqG1o8hmEF3X .node .label text,#mermaid-svg-MwDkOqG1o8hmEF3X .image-shape .label,#mermaid-svg-MwDkOqG1o8hmEF3X .icon-shape .label{text-anchor:middle;}#mermaid-svg-MwDkOqG1o8hmEF3X .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-MwDkOqG1o8hmEF3X .rough-node .label,#mermaid-svg-MwDkOqG1o8hmEF3X .node .label,#mermaid-svg-MwDkOqG1o8hmEF3X .image-shape .label,#mermaid-svg-MwDkOqG1o8hmEF3X .icon-shape .label{text-align:center;}#mermaid-svg-MwDkOqG1o8hmEF3X .node.clickable{cursor:pointer;}#mermaid-svg-MwDkOqG1o8hmEF3X .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-MwDkOqG1o8hmEF3X .arrowheadPath{fill:#333333;}#mermaid-svg-MwDkOqG1o8hmEF3X .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-MwDkOqG1o8hmEF3X .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-MwDkOqG1o8hmEF3X .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-MwDkOqG1o8hmEF3X .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-MwDkOqG1o8hmEF3X .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-MwDkOqG1o8hmEF3X .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-MwDkOqG1o8hmEF3X .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-MwDkOqG1o8hmEF3X .cluster text{fill:#333;}#mermaid-svg-MwDkOqG1o8hmEF3X .cluster span{color:#333;}#mermaid-svg-MwDkOqG1o8hmEF3X div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-MwDkOqG1o8hmEF3X .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-MwDkOqG1o8hmEF3X rect.text{fill:none;stroke-width:0;}#mermaid-svg-MwDkOqG1o8hmEF3X .icon-shape,#mermaid-svg-MwDkOqG1o8hmEF3X .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-MwDkOqG1o8hmEF3X .icon-shape p,#mermaid-svg-MwDkOqG1o8hmEF3X .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-MwDkOqG1o8hmEF3X .icon-shape .label rect,#mermaid-svg-MwDkOqG1o8hmEF3X .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-MwDkOqG1o8hmEF3X .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-MwDkOqG1o8hmEF3X .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-MwDkOqG1o8hmEF3X :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} > 0.8
0.6 - 0.8
< 0.6
拿到 department = billing
同时拿到 confidence = 0.82
置信度判断
系统自动派单
派单时标记
建议人工确认
转给通用客服
很多时候大模型分类翻车,不是因为它完全选错,而是它在两个选项之间犹豫,最后硬猜了一个。有了置信度,你的业务代码就很好写了:
| 置信度区间 | 处理策略 |
|---|---|
| > 0.8 | 系统自动派单 |
| 0.6 - 0.8 | 派单时打个标记,建议人工确认 |
| < 0.6 | 转给通用客服 |
这种确定性在以前纯靠 Prompt 很难稳妥做到。
四、更多用法:挂到 Spring AI 常用链路上
除了这种单点判断,官方还提供了 typesafe-spring-ai 扩展模块,把 Jev 挂到了 Spring AI 的常用链路上。
#mermaid-svg-9tFn99IYfwVm88uh{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-9tFn99IYfwVm88uh .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-9tFn99IYfwVm88uh .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-9tFn99IYfwVm88uh .error-icon{fill:#552222;}#mermaid-svg-9tFn99IYfwVm88uh .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-9tFn99IYfwVm88uh .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-9tFn99IYfwVm88uh .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-9tFn99IYfwVm88uh .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-9tFn99IYfwVm88uh .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-9tFn99IYfwVm88uh .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-9tFn99IYfwVm88uh .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-9tFn99IYfwVm88uh .marker{fill:#333333;stroke:#333333;}#mermaid-svg-9tFn99IYfwVm88uh .marker.cross{stroke:#333333;}#mermaid-svg-9tFn99IYfwVm88uh svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-9tFn99IYfwVm88uh p{margin:0;}#mermaid-svg-9tFn99IYfwVm88uh .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-9tFn99IYfwVm88uh .cluster-label text{fill:#333;}#mermaid-svg-9tFn99IYfwVm88uh .cluster-label span{color:#333;}#mermaid-svg-9tFn99IYfwVm88uh .cluster-label span p{background-color:transparent;}#mermaid-svg-9tFn99IYfwVm88uh .label text,#mermaid-svg-9tFn99IYfwVm88uh span{fill:#333;color:#333;}#mermaid-svg-9tFn99IYfwVm88uh .node rect,#mermaid-svg-9tFn99IYfwVm88uh .node circle,#mermaid-svg-9tFn99IYfwVm88uh .node ellipse,#mermaid-svg-9tFn99IYfwVm88uh .node polygon,#mermaid-svg-9tFn99IYfwVm88uh .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-9tFn99IYfwVm88uh .rough-node .label text,#mermaid-svg-9tFn99IYfwVm88uh .node .label text,#mermaid-svg-9tFn99IYfwVm88uh .image-shape .label,#mermaid-svg-9tFn99IYfwVm88uh .icon-shape .label{text-anchor:middle;}#mermaid-svg-9tFn99IYfwVm88uh .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-9tFn99IYfwVm88uh .rough-node .label,#mermaid-svg-9tFn99IYfwVm88uh .node .label,#mermaid-svg-9tFn99IYfwVm88uh .image-shape .label,#mermaid-svg-9tFn99IYfwVm88uh .icon-shape .label{text-align:center;}#mermaid-svg-9tFn99IYfwVm88uh .node.clickable{cursor:pointer;}#mermaid-svg-9tFn99IYfwVm88uh .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-9tFn99IYfwVm88uh .arrowheadPath{fill:#333333;}#mermaid-svg-9tFn99IYfwVm88uh .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-9tFn99IYfwVm88uh .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-9tFn99IYfwVm88uh .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-9tFn99IYfwVm88uh .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-9tFn99IYfwVm88uh .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-9tFn99IYfwVm88uh .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-9tFn99IYfwVm88uh .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-9tFn99IYfwVm88uh .cluster text{fill:#333;}#mermaid-svg-9tFn99IYfwVm88uh .cluster span{color:#333;}#mermaid-svg-9tFn99IYfwVm88uh div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-9tFn99IYfwVm88uh .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-9tFn99IYfwVm88uh rect.text{fill:none;stroke-width:0;}#mermaid-svg-9tFn99IYfwVm88uh .icon-shape,#mermaid-svg-9tFn99IYfwVm88uh .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-9tFn99IYfwVm88uh .icon-shape p,#mermaid-svg-9tFn99IYfwVm88uh .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-9tFn99IYfwVm88uh .icon-shape .label rect,#mermaid-svg-9tFn99IYfwVm88uh .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-9tFn99IYfwVm88uh .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-9tFn99IYfwVm88uh .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-9tFn99IYfwVm88uh :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Spring AI 链路
通过
拦截
工具调用返回离谱数据
用户输入
安全守门员
JevGuardrailAdvisor
大模型推理
工具调用
ChatClient 自省重试
JevSelfRefineAdvisor
RAG 过滤与重排
JevDocumentFilter + Reranker
最终输出
拒绝越狱/违规输入
4.1 ChatClient 自省重试
用 JevSelfRefineAdvisor 充当裁判。比如工具调用返回了离谱数据,在把结果交给用户前先拦截,打回让模型重试。
4.2 安全守门员
配置 JevGuardrailAdvisor。遇到越狱或者违规输入,在进大模型之前直接拦下来,一次几十毫秒,省下无谓的模型调用费。
4.3 RAG 过滤与重排
在检索之后、喂给大模型之前,用 JevDocumentFilter 剔除无关内容和注入风险,再用 JevDocumentReranker 重排。
五、总结
大模型适合用来写文章、做复杂推理或者跟用户聊天。但要是系统里充斥着大量的意图识别、分类路由和数值评分,真没必要让 Chat Model 去受罪。
#mermaid-svg-fUC8n2BqA04uY2hR{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-fUC8n2BqA04uY2hR .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-fUC8n2BqA04uY2hR .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-fUC8n2BqA04uY2hR .error-icon{fill:#552222;}#mermaid-svg-fUC8n2BqA04uY2hR .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-fUC8n2BqA04uY2hR .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-fUC8n2BqA04uY2hR .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-fUC8n2BqA04uY2hR .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-fUC8n2BqA04uY2hR .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-fUC8n2BqA04uY2hR .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-fUC8n2BqA04uY2hR .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-fUC8n2BqA04uY2hR .marker{fill:#333333;stroke:#333333;}#mermaid-svg-fUC8n2BqA04uY2hR .marker.cross{stroke:#333333;}#mermaid-svg-fUC8n2BqA04uY2hR svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-fUC8n2BqA04uY2hR p{margin:0;}#mermaid-svg-fUC8n2BqA04uY2hR .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-fUC8n2BqA04uY2hR .cluster-label text{fill:#333;}#mermaid-svg-fUC8n2BqA04uY2hR .cluster-label span{color:#333;}#mermaid-svg-fUC8n2BqA04uY2hR .cluster-label span p{background-color:transparent;}#mermaid-svg-fUC8n2BqA04uY2hR .label text,#mermaid-svg-fUC8n2BqA04uY2hR span{fill:#333;color:#333;}#mermaid-svg-fUC8n2BqA04uY2hR .node rect,#mermaid-svg-fUC8n2BqA04uY2hR .node circle,#mermaid-svg-fUC8n2BqA04uY2hR .node ellipse,#mermaid-svg-fUC8n2BqA04uY2hR .node polygon,#mermaid-svg-fUC8n2BqA04uY2hR .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-fUC8n2BqA04uY2hR .rough-node .label text,#mermaid-svg-fUC8n2BqA04uY2hR .node .label text,#mermaid-svg-fUC8n2BqA04uY2hR .image-shape .label,#mermaid-svg-fUC8n2BqA04uY2hR .icon-shape .label{text-anchor:middle;}#mermaid-svg-fUC8n2BqA04uY2hR .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-fUC8n2BqA04uY2hR .rough-node .label,#mermaid-svg-fUC8n2BqA04uY2hR .node .label,#mermaid-svg-fUC8n2BqA04uY2hR .image-shape .label,#mermaid-svg-fUC8n2BqA04uY2hR .icon-shape .label{text-align:center;}#mermaid-svg-fUC8n2BqA04uY2hR .node.clickable{cursor:pointer;}#mermaid-svg-fUC8n2BqA04uY2hR .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-fUC8n2BqA04uY2hR .arrowheadPath{fill:#333333;}#mermaid-svg-fUC8n2BqA04uY2hR .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-fUC8n2BqA04uY2hR .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-fUC8n2BqA04uY2hR .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-fUC8n2BqA04uY2hR .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-fUC8n2BqA04uY2hR .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-fUC8n2BqA04uY2hR .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-fUC8n2BqA04uY2hR .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-fUC8n2BqA04uY2hR .cluster text{fill:#333;}#mermaid-svg-fUC8n2BqA04uY2hR .cluster span{color:#333;}#mermaid-svg-fUC8n2BqA04uY2hR div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-fUC8n2BqA04uY2hR .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-fUC8n2BqA04uY2hR rect.text{fill:none;stroke-width:0;}#mermaid-svg-fUC8n2BqA04uY2hR .icon-shape,#mermaid-svg-fUC8n2BqA04uY2hR .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-fUC8n2BqA04uY2hR .icon-shape p,#mermaid-svg-fUC8n2BqA04uY2hR .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-fUC8n2BqA04uY2hR .icon-shape .label rect,#mermaid-svg-fUC8n2BqA04uY2hR .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-fUC8n2BqA04uY2hR .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-fUC8n2BqA04uY2hR .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-fUC8n2BqA04uY2hR :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 任务类型
写文章 / 复杂推理 / 聊天
意图识别 / 分类路由 / 数值评分
大模型 System 2
Jev System 1
深思熟虑
快速判断
| 对比维度 | 大模型 | Jev 判断模型 |
|---|---|---|
| 响应速度 | 慢(逐字生成) | 快(两三百毫秒) |
| Token 消耗 | 高 | 低(几十个) |
| 返回值 | 文本 | 结构化结果 + 置信度 |
| 适用任务 | 生成、推理、对话 | 意图识别、分类路由、数值评分 |
换成 Jev 这种快思考模型,代码简单,接口也稳得多。