意图识别
ai/intent 组件:v0.36.0+ 使用 LLM 对用户输入进行意图分类,并将识别结果作为 Relation Type 路由到匹配的下游节点,实现基于 AI 的智能路由。
对延迟和成本敏感的场景,可以使用 本地意图识别 替代。
# 配置
| 字段 | 类型 | 说明 | 默认值 |
|---|---|---|---|
| url | string | OpenAI API 兼容的请求地址 | https://ai.gitee.com/v1 |
| key | string | API Key | |
| model | string | 模型名称 | Qwen2.5-72B-Instruct |
| input | string | 用户输入表达式,支持 ${msg.key} 和 ${metadata.key}。为空时使用 msg.GetData() | |
| intents | []Intent | 预定义意图列表(至少定义一个) | |
| defaultIntent | string | 默认意图(无法识别时使用) | default |
| systemPrompt | string | 自定义系统提示词,支持 ${include()} 引用文件。为空时使用内置默认提示词 | |
| temperature | float32 | 模型温度参数 | 0.1 |
| maxTokens | int | 最大输出长度,0 表示使用模型默认值 | 0 |
# Intent 结构
| 字段 | 类型 | 说明 |
|---|---|---|
| name | string | 意图名称(作为 Relation Type 路由) |
| description | string | 意图描述(帮助 LLM 区分不同意图) |
# 执行结果
- 识别结果写入
msg.Metadata["intent"],不修改msg.Data(原始消息透传下游) - 通过
TellNext(msg, intentName)路由到匹配的连接类型 - 识别结果不在预定义列表中时,使用
defaultIntent
# 配置示例
{
"id": "node_intent",
"type": "ai/intent",
"name": "意图分类",
"configuration": {
"url": "https://ai.gitee.com/v1",
"key": "sk-xxx",
"model": "Qwen2.5-72B-Instruct",
"temperature": 0.1,
"intents": [
{"name": "query", "description": "用户查询信息或提问"},
{"name": "action", "description": "用户请求执行某个操作"},
{"name": "complaint", "description": "用户投诉或表达不满"},
{"name": "greeting", "description": "用户问候或打招呼"}
],
"defaultIntent": "unknown"
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 应用示例
智能客服路由:
{
"ruleChain": {"id": "smart-router", "name": "智能路由", "root": true},
"metadata": {
"firstNodeIndex": 0,
"nodes": [
{
"id": "node_intent", "type": "ai/intent", "name": "意图识别",
"configuration": {
"url": "https://ai.gitee.com/v1", "key": "sk-xxx",
"model": "Qwen2.5-72B-Instruct", "temperature": 0.1,
"intents": [
{"name": "query", "description": "查询信息"},
{"name": "action", "description": "执行操作"},
{"name": "complaint", "description": "投诉反馈"}
],
"defaultIntent": "unknown"
}
},
{"id": "node_query", "type": "ai/llm", "name": "回答查询",
"configuration": {"url": "...", "key": "...", "model": "...", "systemPrompt": "回答用户问题"}},
{"id": "node_action", "type": "restApiCall", "name": "执行操作",
"configuration": {"url": "http://api/action", "requestMethod": "POST"}},
{"id": "node_complaint", "type": "restApiCall", "name": "转人工",
"configuration": {"url": "http://api/ticket", "requestMethod": "POST"}}
],
"connections": [
{"fromId": "node_intent", "toId": "node_query", "type": "query"},
{"fromId": "node_intent", "toId": "node_action", "type": "action"},
{"fromId": "node_intent", "toId": "node_complaint", "type": "complaint"}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
在 GitHub 上编辑此页 (opens new window)
上次更新: 2026/05/28, 01:50:04