智能体编排案例
本章展示智能体节点与 RuleGo 其他节点组合编排的实际案例。这些案例适用于需要将 LLM 输出与业务逻辑联动的场景。
提示:大多数场景下,只配置
ai/agent节点 + 工具/skill 即可满足需求。以下案例属于高级用法,适用于小模型意图编排、多步处理管道等特定场景。
# 案例一:物联网指令路由
# 场景描述
用小模型(如 qwen3.5-2b)将用户的自然语言转换为物联网设备指令,不调用工具,输出结构化 JSON,后接路由节点分发到设备控制平台。适用于智能家居、工业设备控制等场景。
# 执行流程
用户输入
↓
[ai/agent] 小模型指令解析(maxStep=1,无工具)
↓ 输出 JSON: {"action": "turnOn", "device": "light"}
[jsTransform] 清理输出(提取 JSON)
↓
[jsFilter] 路由判断(是否有 action 字段)
├── True → [restApiCall] 发送到设备控制平台
└── False → 直接结束
↓
结束
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 完整配置
{
"ruleChain": {
"id": "iot-command-router",
"name": "物联网指令路由",
"additionalInfo": {
"description": "自然语言转设备指令 + 路由到控制平台"
}
},
"metadata": {
"firstNodeIndex": 0,
"nodes": [
{
"id": "node_agent",
"type": "ai/agent",
"name": "指令解析",
"configuration": {
"url": "${global.models.providers.default.base_url}",
"key": "${global.models.providers.default.api_key}",
"model": "${global.models.providers.default.model}",
"maxStep": 1,
"systemPrompt": "${include(global.root_dir+'/workspace/AGENTS.md')}",
"tools": [],
"params": {
"temperature": 0.3
}
}
},
{
"id": "node_clean",
"type": "jsTransform",
"name": "清理输出",
"configuration": {
"jsScript": "// 提取JSON,去除markdown代码块标记\nif(typeof msg==='string'){\n msg=msg.replace(/^```[a-z]*\\s*/i,'').replace(/\\s*```$/,'');\n var i=msg.indexOf('{');\n if(i>0) msg=msg.substring(i);\n msg=msg.trim();\n}\nreturn {msg:msg, metadata:metadata, msgType:msgType, dataType:'JSON'};"
}
},
{
"id": "node_route",
"type": "jsFilter",
"name": "路由判断",
"configuration": {
"jsScript": "// 检查是否有 action 字段\nif(typeof msg==='string'){\n try{ var o=JSON.parse(msg); return !!o.action; }\n catch(e){ return false; }\n}\nreturn typeof msg==='object' && !!msg.action;"
}
},
{
"id": "node_execute",
"type": "restApiCall",
"name": "发送指令",
"configuration": {
"requestMethod": "POST",
"restEndpointUrlPattern": "${global.iot_platform_url}/api/v1/device/command",
"headers": { "Content-Type": "application/json" },
"readTimeoutMs": 5000
}
},
{
"id": "node_end",
"type": "end",
"name": "结束"
}
],
"connections": [
{ "fromId": "node_agent", "toId": "node_clean", "type": "Success" },
{ "fromId": "node_agent", "toId": "node_end", "type": "Stream" },
{ "fromId": "node_agent", "toId": "node_end", "type": "Failure" },
{ "fromId": "node_clean", "toId": "node_route", "type": "Success" },
{ "fromId": "node_route", "toId": "node_execute", "type": "True" },
{ "fromId": "node_route", "toId": "node_end", "type": "False" },
{ "fromId": "node_execute", "toId": "node_end", "type": "Success" },
{ "fromId": "node_execute", "toId": "node_end", "type": "Failure" }
]
}
}
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 关键配置说明
| 配置 | 说明 |
|---|---|
systemPrompt | 通过 ${include()} 从外部文件加载提示词,修改文件后无需重启即可生效 |
maxStep: 1 | 只推理一次,不进入工具调用循环 |
tools: [] | 空数组,不使用工具 |
temperature: 0.3 | 低温度,输出更稳定 |
node_clean | 清理 LLM 输出的 markdown 标记,提取纯 JSON |
node_route | 根据是否有 action 字段决定是否下发指令 |
提示:
systemPrompt支持通过${include('文件路径')}从外部文件加载提示词内容,比直接内联在 JSON 中更易于维护和迭代。修改文件后智能体下次执行即可生效,无需重启服务或更新规则链配置。
对应的 workspace/AGENTS.md 文件内容:
# 任务
你是物联网指令解析器。将用户的自然语言转为设备控制JSON。
## 支持的设备
light(灯)、fan(风机)、ac(空调)、curtain(窗帘)
## 支持的动作
- turnOn(打开)
- turnOff(关闭)
- setTimer(定时)
## 输出格式
{"action": "动作", "device": "设备名"}
定时场景:{"action": "setTimer", "device": "设备名", "delay": 秒数}
## 示例
- "帮我开灯" → {"action": "turnOn", "device": "light"}
- "关掉空调" → {"action": "turnOff", "device": "ac"}
- "5分钟后关风机" → {"action": "setTimer", "device": "fan", "delay": 300}
## 约束
只输出JSON,不要解释,不要加 markdown 格式。
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
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
# 案例二:设备故障诊断 + 工单生成
# 场景描述
设备出现故障时,运维人员用自然语言描述故障现象(可能含模糊、不准确的信息),LLM 结合设备知识分析根因并给出处置建议,自动生成工单提交到运维系统。这种场景需要 LLM 的语义理解和推理能力,是规则引擎硬编码无法覆盖的。
# 执行流程
运维人员故障描述
↓
[ai/agent] 故障诊断(maxStep=1,无工具)
↓ 输出 JSON: {"rootCause": "...", "severity": "...", "suggestion": "..."}
[jsTransform] 清理输出 + 附加设备信息
↓
[jsFilter] 严重等级判断(severity 是否为 critical)
├── True(紧急)→ [restApiCall] 创建紧急工单
└── False(一般)→ [restApiCall] 创建普通工单
↓
结束
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
# 完整配置
{
"ruleChain": {
"id": "iot-fault-diagnosis",
"name": "设备故障诊断",
"additionalInfo": {
"description": "AI 故障诊断 + 按严重等级自动生成工单"
}
},
"metadata": {
"firstNodeIndex": 0,
"nodes": [
{
"id": "node_agent",
"type": "ai/agent",
"name": "故障诊断",
"configuration": {
"url": "${global.models.providers.default.base_url}",
"key": "${global.models.providers.default.api_key}",
"model": "${global.models.providers.default.model}",
"maxStep": 1,
"systemPrompt": "${include(global.root_dir+'/workspace/AGENTS.md')}",
"tools": [],
"params": {
"temperature": 0.3
}
}
},
{
"id": "node_enrich",
"type": "jsTransform",
"name": "构造工单",
"configuration": {
"jsScript": "// 清理LLM输出,附加设备信息,构造工单\nvar result = msg;\nif(typeof msg==='string'){\n msg=msg.replace(/^```[a-z]*\\s*/i,'').replace(/\\s*```$/,'');\n var i=msg.indexOf('{');\n if(i>0) msg=msg.substring(i);\n result=JSON.parse(msg);\n}\nvar ticket = {\n title: result.summary,\n description: result.rootCause + '\\n\\n处置建议:' + result.suggestion,\n severity: result.severity,\n category: result.category,\n deviceId: metadata.deviceId || '',\n reporter: metadata.reporter || '',\n createdAt: new Date().toISOString()\n};\nreturn {msg:JSON.stringify(ticket), metadata:metadata, msgType:msgType, dataType:'JSON'};"
}
},
{
"id": "node_route",
"type": "jsFilter",
"name": "是否紧急",
"configuration": {
"jsScript": "var o=typeof msg==='string'?JSON.parse(msg):msg;\nreturn o.severity==='critical';"
}
},
{
"id": "node_urgent",
"type": "restApiCall",
"name": "创建紧急工单",
"configuration": {
"requestMethod": "POST",
"restEndpointUrlPattern": "${global.iot_platform_url}/api/v1/ticket/urgent",
"headers": { "Content-Type": "application/json" },
"readTimeoutMs": 5000
}
},
{
"id": "node_normal",
"type": "restApiCall",
"name": "创建普通工单",
"configuration": {
"requestMethod": "POST",
"restEndpointUrlPattern": "${global.iot_platform_url}/api/v1/ticket/normal",
"headers": { "Content-Type": "application/json" },
"readTimeoutMs": 5000
}
},
{
"id": "node_end",
"type": "end",
"name": "结束"
}
],
"connections": [
{ "fromId": "node_agent", "toId": "node_enrich", "type": "Success" },
{ "fromId": "node_agent", "toId": "node_end", "type": "Failure" },
{ "fromId": "node_enrich", "toId": "node_route", "type": "Success" },
{ "fromId": "node_route", "toId": "node_urgent", "type": "True" },
{ "fromId": "node_route", "toId": "node_normal", "type": "False" },
{ "fromId": "node_urgent", "toId": "node_end", "type": "Success" },
{ "fromId": "node_urgent", "toId": "node_end", "type": "Failure" },
{ "fromId": "node_normal", "toId": "node_end", "type": "Success" },
{ "fromId": "node_normal", "toId": "node_end", "type": "Failure" }
]
}
}
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 关键配置说明
| 配置 | 说明 |
|---|---|
maxStep: 1 | 单次推理,不调用工具 |
systemPrompt | 通过 ${include()} 从外部文件加载诊断知识和规则 |
node_enrich | 清理 LLM 输出 + 从 metadata 附加设备/上报人信息,组装为工单格式 |
node_route | 根据 severity 字段判断是否创建紧急工单 |
node_urgent | 紧急工单走加急通道,触发值班通知 |
node_normal | 普通工单走标准流程 |
对应的 workspace/AGENTS.md 文件内容:
# 任务
你是设备故障诊断专家。根据运维人员描述的故障现象,分析可能的原因并给出处置建议。
## 输出格式
{
"category": "故障分类",
"severity": "严重等级",
"summary": "一句话概述",
"rootCause": "根因分析",
"suggestion": "处置建议"
}
## 故障分类
- power:电力故障(断电、过载、短路)
- network:通信故障(断网、信号弱、协议异常)
- mechanical:机械故障(振动异常、卡死、磨损)
- sensor:传感器故障(数据异常、漂移、失联)
- environmental:环境故障(温度/湿度超标、漏水、烟雾)
- software:软件故障(死机、配置错误、版本不兼容)
## 严重等级
- critical:影响生产安全或导致设备停机,需立即处理
- major:影响部分功能,需尽快处理
- minor:不影响主要功能,可计划处理
## 分析原则
1. 根据描述推断最可能的原因,如有多个可能按概率排序
2. 处置建议要具体可操作,不要泛泛而谈
3. 如果描述信息不足,在 rootCause 中说明需要进一步确认什么
## 约束
只输出JSON,不要解释,不要加 markdown 格式。
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
33
34
35
36
37
38
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
33
34
35
36
37
38
# 诊断示例
| 运维人员描述 | AI 诊断结果 | 路由 |
|---|---|---|
| "3号产线机械臂到位置后停不住,有点过冲,最近越来越严重" | {"category": "mechanical", "severity": "major", "rootCause": "伺服驱动器位置环增益衰减或机械传动磨损", "suggestion": "先检查伺服参数是否偏移,再检查丝杠和导轨磨损情况"} | → 普通工单 |
| "配电柜有烧焦的味道,听到滋滋声" | {"category": "power", "severity": "critical", "rootCause": "疑似接线端子松动导致电弧放电", "suggestion": "立即断电,疏散人员,联系电工检查接线"} | → 紧急工单 |
| "仓库温湿度传感器数据一直跳来跳去" | {"category": "sensor", "severity": "minor", "rootCause": "传感器老化或信号线受干扰", "suggestion": "更换传感器或检查屏蔽线接地"} | → 普通工单 |
# 编排模式总结
# 常用节点类型
| 节点类型 | 用途 | 典型场景 |
|---|---|---|
ai/agent | AI 智能体,ReAct 推理循环 | 意图分类、文本生成、工具调用 |
ai/llm | 单次 LLM 调用,无工具 | 简单文本生成、分类 |
jsFilter | JavaScript 条件过滤 | 路由判断、数据校验 |
jsTransform | JavaScript 数据转换 | 清理输出、格式转换、构造请求体 |
restApiCall | 调用外部 REST API | 执行命令、数据同步 |
end | 结束节点 | 必须有,标记流程结束 |
# 连接类型
| 类型 | 说明 |
|---|---|
Success | 同步执行成功 |
Stream | 流式输出(每个 chunk 一条消息) |
Failure | 执行失败 |
True | jsFilter 条件为真 |
False | jsFilter 条件为假 |
# 设计建议
- 小模型 + 无工具:意图分类场景用
maxStep=1+tools: [],降低成本和延迟 - 输出清理:LLM 输出常带 markdown 标记,用
jsTransform清理后再路由 - 错误处理:为关键节点添加
Failure连接,确保错误不会丢失 - 流式支持:为
ai/agent节点添加Stream连接,支持实时输出
# 相关文档
在 GitHub 上编辑此页 (opens new window)
上次更新: 2026/05/29, 03:36:52