foliko 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +4 -1
- package/.cli_default_systemPrompt.md +291 -0
- package/CLAUDE.md +3 -0
- package/README.md +20 -3
- package/docs/architecture.md +34 -2
- package/docs/extensions.md +199 -0
- package/docs/migration.md +100 -0
- package/docs/public-api.md +280 -24
- package/docs/usage.md +122 -30
- package/package.json +1 -1
- package/plugins/core/audit/index.js +1 -1
- package/plugins/core/default/bootstrap.js +44 -19
- package/plugins/core/python-loader/index.js +43 -25
- package/plugins/core/scheduler/index.js +1 -0
- package/plugins/core/skill-manager/PROMPT.md +6 -0
- package/plugins/core/skill-manager/index.js +402 -115
- package/plugins/core/sub-agent/PROMPT.md +10 -0
- package/plugins/core/sub-agent/index.js +36 -3
- package/plugins/core/think/index.js +1 -0
- package/plugins/core/workflow/context.js +941 -0
- package/plugins/core/workflow/engine.js +66 -0
- package/plugins/core/workflow/examples/01-basic.js +42 -0
- package/plugins/core/workflow/examples/01-basic.json +30 -0
- package/plugins/core/workflow/examples/02-choice.js +75 -0
- package/plugins/core/workflow/examples/02-choice.json +59 -0
- package/plugins/core/workflow/examples/03-chain-style.js +114 -0
- package/plugins/core/workflow/examples/03-each.json +41 -0
- package/plugins/core/workflow/examples/04-parallel.js +52 -0
- package/plugins/core/workflow/examples/04-parallel.json +51 -0
- package/plugins/core/workflow/examples/05-chain-style.json +68 -0
- package/plugins/core/workflow/examples/05-each.js +65 -0
- package/plugins/core/workflow/examples/06-script.js +82 -0
- package/plugins/core/workflow/examples/07-module-export.js +43 -0
- package/plugins/core/workflow/examples/08-default-export.js +29 -0
- package/plugins/core/workflow/examples/09-next-with-args.js +50 -0
- package/plugins/core/workflow/examples/10-logger.js +34 -0
- package/plugins/core/workflow/examples/11-storage.js +68 -0
- package/plugins/core/workflow/examples/simple.js +77 -0
- package/plugins/core/workflow/examples/simple.json +75 -0
- package/plugins/core/workflow/index.js +204 -78
- package/plugins/core/workflow/js-runner.js +318 -0
- package/plugins/core/workflow/json-runner.js +323 -0
- package/plugins/core/workflow/stages/action.js +211 -0
- package/plugins/core/workflow/stages/choice.js +74 -0
- package/plugins/core/workflow/stages/delay.js +73 -0
- package/plugins/core/workflow/stages/each.js +123 -0
- package/plugins/core/workflow/stages/parallel.js +69 -0
- package/plugins/core/workflow/stages/try.js +142 -0
- package/plugins/executors/data-splitter/PROMPT.md +13 -0
- package/plugins/executors/data-splitter/index.js +8 -6
- package/plugins/executors/extension/extension-registry.js +145 -0
- package/plugins/executors/extension/index.js +405 -437
- package/plugins/executors/extension/prompt-builder.js +359 -0
- package/plugins/executors/extension/skill-helper.js +143 -0
- package/plugins/messaging/feishu/index.js +5 -3
- package/plugins/messaging/qq/index.js +6 -4
- package/plugins/messaging/telegram/index.js +6 -3
- package/plugins/messaging/weixin/index.js +5 -3
- package/plugins/tools/PROMPT.md +26 -0
- package/plugins/tools/index.js +6 -5
- package/sandbox/check-context.js +5 -0
- package/sandbox/test-context.js +27 -0
- package/sandbox/test-fixes.js +40 -0
- package/sandbox/test-hello-js.js +46 -0
- package/skills/foliko/AGENTS.md +196 -43
- package/skills/foliko/SKILL.md +157 -28
- package/skills/mcp/SKILL.md +77 -118
- package/skills/plugins/SKILL.md +89 -3
- package/skills/python/SKILL.md +57 -39
- package/skills/skill-guide/SKILL.md +42 -34
- package/skills/workflows/SKILL.md +753 -436
- package/src/agent/chat.js +56 -28
- package/src/agent/main.js +39 -14
- package/src/agent/prompt-registry.js +56 -16
- package/src/agent/prompts/PROMPT.md +3 -0
- package/src/agent/sub.js +1 -1
- package/src/cli/ui/chat-ui-old.js +5 -2
- package/src/cli/ui/chat-ui.js +9 -5
- package/src/common/constants.js +12 -0
- package/src/common/error-capture.js +91 -0
- package/src/common/json-safe.js +20 -0
- package/src/common/logger.js +2 -2
- package/src/context/compressor.js +6 -2
- package/src/executors/mcp-executor.js +105 -125
- package/src/framework/framework.js +78 -12
- package/src/index.js +4 -0
- package/src/plugin/base.js +908 -5
- package/src/plugin/manager.js +124 -9
- package/src/tool/schema.js +32 -9
- package/src/utils/sandbox.js +1 -1
- package/website/index.html +821 -0
- package/skills/workflows/workflow-troubleshooting/DEBUGGING.md +0 -197
- package/skills/workflows/workflow-troubleshooting/SKILL.md +0 -391
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
# 工作流开发调试指南
|
|
2
|
-
|
|
3
|
-
## 快速测试工作流
|
|
4
|
-
|
|
5
|
-
### 1. 使用 execute_workflow 直接测试
|
|
6
|
-
|
|
7
|
-
```javascript
|
|
8
|
-
execute_workflow({
|
|
9
|
-
workflow: {
|
|
10
|
-
name: 'test-workflow',
|
|
11
|
-
description: '测试工作流',
|
|
12
|
-
steps: [
|
|
13
|
-
{
|
|
14
|
-
id: 'step1',
|
|
15
|
-
type: 'tool',
|
|
16
|
-
tool: 'py_execute',
|
|
17
|
-
args: {
|
|
18
|
-
code: "print('Hello from Python!')",
|
|
19
|
-
},
|
|
20
|
-
outputVariable: 'result',
|
|
21
|
-
},
|
|
22
|
-
],
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
### 2. JSON 格式注意事项
|
|
28
|
-
|
|
29
|
-
- ✅ 使用双引号包裹字符串
|
|
30
|
-
- ✅ 确保 JSON 语法正确
|
|
31
|
-
- ❌ 避免在 JSON 中使用未转义的特殊字符
|
|
32
|
-
- ❌ 不要在 code 中混用单引号和双引号
|
|
33
|
-
|
|
34
|
-
### 3. 常见错误
|
|
35
|
-
|
|
36
|
-
```
|
|
37
|
-
Unexpected identifier 'xxx'
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
- 原因:JSON 格式错误,可能是引号或逗号问题
|
|
41
|
-
- 解决:检查 JSON 语法
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
Unexpected end of JSON input
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
- 原因:模板字符串 `${}` 在 JSON 中导致解析错误
|
|
48
|
-
- 解决:不要在 JSON 中使用模板变量,改用纯 Python 代码
|
|
49
|
-
|
|
50
|
-
## 工作流重载问题
|
|
51
|
-
|
|
52
|
-
### 问题
|
|
53
|
-
|
|
54
|
-
添加新工作流后,`workflow_reload` 不会重新加载同名工作流。
|
|
55
|
-
|
|
56
|
-
### 解决
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
# 方法1:使用不同的文件名
|
|
60
|
-
news-dashboard-v3.json # 不会被 v2 覆盖
|
|
61
|
-
|
|
62
|
-
# 方法2:重启插件
|
|
63
|
-
reload_plugins() # 重载所有插件
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
## Python 执行最佳实践
|
|
67
|
-
|
|
68
|
-
### 1. 错误处理
|
|
69
|
-
|
|
70
|
-
```python
|
|
71
|
-
try:
|
|
72
|
-
req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0'})
|
|
73
|
-
with urllib.request.urlopen(req, timeout=10) as resp:
|
|
74
|
-
data = resp.read().decode('utf-8')
|
|
75
|
-
print('SUCCESS')
|
|
76
|
-
except Exception as e:
|
|
77
|
-
print(f'ERROR: {e}')
|
|
78
|
-
# fallback 逻辑
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
### 2. 输出格式
|
|
82
|
-
|
|
83
|
-
```python
|
|
84
|
-
# 简单输出
|
|
85
|
-
print('Status: OK')
|
|
86
|
-
print(f'Count: {len(items)}')
|
|
87
|
-
|
|
88
|
-
# JSON 输出
|
|
89
|
-
import json
|
|
90
|
-
print('---JSON_START---')
|
|
91
|
-
print(json.dumps(data, ensure_ascii=False))
|
|
92
|
-
print('---JSON_END---')
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
### 3. 超时设置
|
|
96
|
-
|
|
97
|
-
```python
|
|
98
|
-
with urllib.request.urlopen(req, timeout=30) as resp: # 30秒超时
|
|
99
|
-
...
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## 工作流步骤类型
|
|
103
|
-
|
|
104
|
-
| 类型 | 用途 | 示例 |
|
|
105
|
-
| ----------- | --------------- | ------------------------------------- |
|
|
106
|
-
| `tool` | 调用工具 | `py_execute`, `shell_exec`, `get_time` |
|
|
107
|
-
| `script` | 执行 JavaScript | 数据处理、变量操作 |
|
|
108
|
-
| `condition` | 条件分支 | if/else 逻辑 |
|
|
109
|
-
| `loop` | 循环执行 | 遍历列表 |
|
|
110
|
-
| `delay` | 延时等待 | 等待指定时间 |
|
|
111
|
-
| `message` | 消息通知 | 发送通知 |
|
|
112
|
-
| `think` | LLM 思考 | 反思/分析 |
|
|
113
|
-
|
|
114
|
-
## 工具输出变量
|
|
115
|
-
|
|
116
|
-
### 正确用法
|
|
117
|
-
|
|
118
|
-
```json
|
|
119
|
-
{
|
|
120
|
-
"id": "step1",
|
|
121
|
-
"type": "tool",
|
|
122
|
-
"tool": "get_time",
|
|
123
|
-
"outputVariable": "current_time"
|
|
124
|
-
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
### 访问输出
|
|
128
|
-
|
|
129
|
-
```javascript
|
|
130
|
-
// 在 script 步骤中
|
|
131
|
-
context.input.current_time
|
|
132
|
-
|
|
133
|
-
// 在下一个 tool 步骤中
|
|
134
|
-
${step1.current_time}
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
## 调试技巧
|
|
138
|
-
|
|
139
|
-
### 1. 打印中间变量
|
|
140
|
-
|
|
141
|
-
```python
|
|
142
|
-
print('Debug - data:', data)
|
|
143
|
-
print('Debug - length:', len(data))
|
|
144
|
-
```
|
|
145
|
-
|
|
146
|
-
### 2. 保存到文件
|
|
147
|
-
|
|
148
|
-
```python
|
|
149
|
-
with open('debug.log', 'w') as f:
|
|
150
|
-
f.write(str(data))
|
|
151
|
-
```
|
|
152
|
-
|
|
153
|
-
### 3. 逐步执行
|
|
154
|
-
|
|
155
|
-
```javascript
|
|
156
|
-
{
|
|
157
|
-
"steps": [
|
|
158
|
-
{ "id": "step1", ... }, // 先测试 step1
|
|
159
|
-
{ "id": "step2", ... } // 确认 step1 成功后添加
|
|
160
|
-
]
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
## 性能优化
|
|
165
|
-
|
|
166
|
-
### 1. 合并步骤
|
|
167
|
-
|
|
168
|
-
```javascript
|
|
169
|
-
// ❌ 多个小步骤
|
|
170
|
-
{ "id": "step1", "tool": "py_execute", "code": "a = 1" }
|
|
171
|
-
{ "id": "step2", "tool": "py_execute", "code": "b = 2" }
|
|
172
|
-
|
|
173
|
-
// ✅ 单个大步骤
|
|
174
|
-
{ "id": "step1", "tool": "py_execute", "code": "a = 1; b = 2; print(a + b)" }
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
### 2. 减少变量传递
|
|
178
|
-
|
|
179
|
-
```javascript
|
|
180
|
-
// ❌ 多步骤传递
|
|
181
|
-
{ "outputVariable": "data1" }
|
|
182
|
-
{ "outputVariable": "data2" }
|
|
183
|
-
|
|
184
|
-
// ✅ 单步骤完成
|
|
185
|
-
{ "outputVariable": "final_result" }
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
### 3. 超时设置
|
|
189
|
-
|
|
190
|
-
```json
|
|
191
|
-
{
|
|
192
|
-
"args": {
|
|
193
|
-
"code": "...",
|
|
194
|
-
"timeout": 60000 // 60秒超时
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
```
|
|
@@ -1,391 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: workflow-troubleshooting
|
|
3
|
-
description: 工作流故障排除与修复指南。当工作流执行失败、fetch 工具不可用、模板变量问题时调用此技能。
|
|
4
|
-
allowed-tools: python-executor, shell, read_file, write_file, execute_workflow, fetch
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# 工作流故障排除指南
|
|
8
|
-
|
|
9
|
-
## 常见问题与解决方案
|
|
10
|
-
|
|
11
|
-
### 1. fetch 工具可用 ✅
|
|
12
|
-
|
|
13
|
-
**好消息**: 工作流引擎**支持** `fetch` 工具!可以直接在 steps 中使用:
|
|
14
|
-
|
|
15
|
-
```yaml
|
|
16
|
-
steps:
|
|
17
|
-
- type: tool
|
|
18
|
-
name: fetch
|
|
19
|
-
params:
|
|
20
|
-
url: 'https://news.baidu.com'
|
|
21
|
-
timeout: 10000
|
|
22
|
-
output: 'baidu_news'
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
**优势**:
|
|
26
|
-
|
|
27
|
-
- 原生支持,无需额外 sandbox 配置
|
|
28
|
-
- 语法简洁
|
|
29
|
-
- 自动处理超时和错误
|
|
30
|
-
|
|
31
|
-
### 2. 多个 fetch 步骤串联
|
|
32
|
-
|
|
33
|
-
**已验证可用**:
|
|
34
|
-
|
|
35
|
-
```yaml
|
|
36
|
-
steps:
|
|
37
|
-
- type: tool
|
|
38
|
-
name: fetch
|
|
39
|
-
params:
|
|
40
|
-
url: 'https://news.baidu.com'
|
|
41
|
-
output: 'baidu_news'
|
|
42
|
-
|
|
43
|
-
- type: tool
|
|
44
|
-
name: fetch
|
|
45
|
-
params:
|
|
46
|
-
url: 'https://feeds.bbci.co.uk/news/world/rss.xml'
|
|
47
|
-
output: 'bbc_news'
|
|
48
|
-
|
|
49
|
-
- type: tool
|
|
50
|
-
name: fetch
|
|
51
|
-
params:
|
|
52
|
-
url: 'https://www.reddit.com/r/popular/hot.json?limit=20'
|
|
53
|
-
output: 'reddit_news'
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### 3. Python 脚本获取结果
|
|
57
|
-
|
|
58
|
-
**正确方式**: Python 脚本返回 JSON 格式字符串
|
|
59
|
-
|
|
60
|
-
```python
|
|
61
|
-
import json
|
|
62
|
-
import requests
|
|
63
|
-
|
|
64
|
-
result = {"news": ["标题1", "标题2"]}
|
|
65
|
-
print(json.dumps(result)) # 输出 JSON 字符串
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### 4. webhook 类型步骤
|
|
69
|
-
|
|
70
|
-
**警告**: `webhook` 类型需要 HTTP 服务支持,否则会失败。
|
|
71
|
-
|
|
72
|
-
- 如需接收外部数据,使用 `web_register_webhook` 注册路由
|
|
73
|
-
- 测试时改用 `tool` + `fetch` 组合
|
|
74
|
-
|
|
75
|
-
### 5. 变量传递问题
|
|
76
|
-
|
|
77
|
-
- **原因**: sandbox 环境无法访问主环境变量
|
|
78
|
-
- **解决方案**:
|
|
79
|
-
- 使用上下文变量 `$.context.xxx`
|
|
80
|
-
- 或直接在脚本中硬编码(测试用)
|
|
81
|
-
|
|
82
|
-
## 调试技巧
|
|
83
|
-
|
|
84
|
-
1. **先单独测试每个步骤** - 用简单输入验证
|
|
85
|
-
2. **检查工作流定义语法** - YAML/JSON 格式正确性
|
|
86
|
-
3. **使用简单输入测试变量传递**
|
|
87
|
-
4. **fetch 失败时**: 加 `timeout` 参数,加 `proxy: true` 重试
|
|
88
|
-
|
|
89
|
-
## 成功案例
|
|
90
|
-
|
|
91
|
-
### 真实新闻聚合工作流
|
|
92
|
-
|
|
93
|
-
```yaml
|
|
94
|
-
name: 'news-fetcher'
|
|
95
|
-
steps:
|
|
96
|
-
- type: 'context'
|
|
97
|
-
key: 'current_time'
|
|
98
|
-
value: '$.time.current'
|
|
99
|
-
|
|
100
|
-
- type: 'tool'
|
|
101
|
-
name: 'fetch'
|
|
102
|
-
params:
|
|
103
|
-
url: 'https://news.baidu.com'
|
|
104
|
-
timeout: 15000
|
|
105
|
-
output: 'baidu_news'
|
|
106
|
-
|
|
107
|
-
- type: 'tool'
|
|
108
|
-
name: 'fetch'
|
|
109
|
-
params:
|
|
110
|
-
url: 'https://feeds.bbci.co.uk/news/world/rss.xml'
|
|
111
|
-
timeout: 15000
|
|
112
|
-
output: 'bbc_news'
|
|
113
|
-
|
|
114
|
-
- type: 'tool'
|
|
115
|
-
name: 'fetch'
|
|
116
|
-
params:
|
|
117
|
-
url: 'https://www.reddit.com/r/popular/hot.json?limit=20'
|
|
118
|
-
timeout: 15000
|
|
119
|
-
output: 'reddit_news'
|
|
120
|
-
|
|
121
|
-
- type: 'python'
|
|
122
|
-
script: |
|
|
123
|
-
import json
|
|
124
|
-
# 处理新闻数据...
|
|
125
|
-
result = {"status": "success", "sources": ["baidu", "bbc", "reddit"]}
|
|
126
|
-
print(json.dumps(result))
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### 网络不稳定时加代理
|
|
130
|
-
|
|
131
|
-
```yaml
|
|
132
|
-
- type: 'tool'
|
|
133
|
-
name: 'fetch'
|
|
134
|
-
params:
|
|
135
|
-
url: 'https://feeds.bbci.co.uk/news/world/rss.xml'
|
|
136
|
-
timeout: 15000
|
|
137
|
-
proxy: true # 失败时自动启用
|
|
138
|
-
output: 'bbc_news'
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
## 复杂工作流步骤类型测试 ✅
|
|
142
|
-
|
|
143
|
-
以下步骤类型已通过完整测试验证:
|
|
144
|
-
|
|
145
|
-
### 1. parallel (并行执行) ✅
|
|
146
|
-
|
|
147
|
-
多个任务同时执行,提高效率:
|
|
148
|
-
|
|
149
|
-
```json
|
|
150
|
-
{
|
|
151
|
-
"type": "parallel",
|
|
152
|
-
"steps": [
|
|
153
|
-
{ "type": "tool", "name": "get_time", "output": "current_time" },
|
|
154
|
-
{
|
|
155
|
-
"type": "tool",
|
|
156
|
-
"name": "storage_set",
|
|
157
|
-
"params": { "key": "test", "value": "ok" },
|
|
158
|
-
"output": "storage_result"
|
|
159
|
-
},
|
|
160
|
-
{
|
|
161
|
-
"type": "tool",
|
|
162
|
-
"name": "fetch",
|
|
163
|
-
"params": { "url": "https://news.baidu.com" },
|
|
164
|
-
"output": "news"
|
|
165
|
-
}
|
|
166
|
-
]
|
|
167
|
-
}
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
### 2. condition (条件分支) ✅
|
|
171
|
-
|
|
172
|
-
支持 if/else 逻辑判断:
|
|
173
|
-
|
|
174
|
-
```json
|
|
175
|
-
{
|
|
176
|
-
"type": "condition",
|
|
177
|
-
"if": { "key": "$.context.storage_result", "equals": "success" },
|
|
178
|
-
"then": [
|
|
179
|
-
{
|
|
180
|
-
"type": "tool",
|
|
181
|
-
"name": "notification_send",
|
|
182
|
-
"params": { "title": "成功", "message": "条件成立" }
|
|
183
|
-
}
|
|
184
|
-
],
|
|
185
|
-
"else": [
|
|
186
|
-
{
|
|
187
|
-
"type": "tool",
|
|
188
|
-
"name": "notification_send",
|
|
189
|
-
"params": { "title": "失败", "message": "条件不成立" }
|
|
190
|
-
}
|
|
191
|
-
]
|
|
192
|
-
}
|
|
193
|
-
```
|
|
194
|
-
|
|
195
|
-
**支持的操作符**:`equals`, `not_equals`, `contains`, `greater_than`, `less_than`, `exists`, `not_exists`
|
|
196
|
-
|
|
197
|
-
### 3. loop (循环执行) ✅
|
|
198
|
-
|
|
199
|
-
支持指定次数的循环:
|
|
200
|
-
|
|
201
|
-
```json
|
|
202
|
-
{
|
|
203
|
-
"type": "loop",
|
|
204
|
-
"count": 3,
|
|
205
|
-
"steps": [
|
|
206
|
-
{
|
|
207
|
-
"type": "tool",
|
|
208
|
-
"name": "notification_send",
|
|
209
|
-
"params": { "title": "循环", "message": "第 {{index}} 次" }
|
|
210
|
-
}
|
|
211
|
-
]
|
|
212
|
-
}
|
|
213
|
-
```
|
|
214
|
-
|
|
215
|
-
### 4. switch (多分支) ✅
|
|
216
|
-
|
|
217
|
-
类似 switch-case 的多条件分支:
|
|
218
|
-
|
|
219
|
-
```json
|
|
220
|
-
{
|
|
221
|
-
"type": "switch",
|
|
222
|
-
"value": "$.context.status",
|
|
223
|
-
"cases": [
|
|
224
|
-
{
|
|
225
|
-
"value": "success",
|
|
226
|
-
"steps": [{ "type": "tool", "name": "notification_send", "params": { "title": "成功" } }]
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
"value": "error",
|
|
230
|
-
"steps": [{ "type": "tool", "name": "notification_send", "params": { "title": "错误" } }]
|
|
231
|
-
}
|
|
232
|
-
],
|
|
233
|
-
"default": [{ "type": "tool", "name": "notification_send", "params": { "title": "默认" } }]
|
|
234
|
-
}
|
|
235
|
-
```
|
|
236
|
-
|
|
237
|
-
### 5. try-catch (错误处理) ✅
|
|
238
|
-
|
|
239
|
-
捕获步骤执行中的错误,防止中断:
|
|
240
|
-
|
|
241
|
-
```json
|
|
242
|
-
{
|
|
243
|
-
"type": "try",
|
|
244
|
-
"steps": [{ "type": "tool", "name": "email_unread_count" }],
|
|
245
|
-
"catch": [
|
|
246
|
-
{
|
|
247
|
-
"type": "tool",
|
|
248
|
-
"name": "notification_send",
|
|
249
|
-
"params": { "title": "捕获错误", "message": "邮件服务超时,使用备用方案" }
|
|
250
|
-
}
|
|
251
|
-
]
|
|
252
|
-
}
|
|
253
|
-
```
|
|
254
|
-
|
|
255
|
-
### 6. delay (延迟执行) ✅
|
|
256
|
-
|
|
257
|
-
在步骤之间添加延迟:
|
|
258
|
-
|
|
259
|
-
```json
|
|
260
|
-
{
|
|
261
|
-
"type": "delay",
|
|
262
|
-
"ms": 500
|
|
263
|
-
}
|
|
264
|
-
```
|
|
265
|
-
|
|
266
|
-
### 7. nested workflow (嵌套工作流) ✅
|
|
267
|
-
|
|
268
|
-
在主工作流中调用子工作流:
|
|
269
|
-
|
|
270
|
-
```json
|
|
271
|
-
{
|
|
272
|
-
"type": "workflow",
|
|
273
|
-
"name": "workflow_file-backup",
|
|
274
|
-
"input": {}
|
|
275
|
-
}
|
|
276
|
-
```
|
|
277
|
-
|
|
278
|
-
### 8. context (上下文变量) ✅
|
|
279
|
-
|
|
280
|
-
在步骤间传递数据:
|
|
281
|
-
|
|
282
|
-
```json
|
|
283
|
-
{
|
|
284
|
-
"type": "context",
|
|
285
|
-
"key": "workflow_status",
|
|
286
|
-
"value": "completed"
|
|
287
|
-
}
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
## 复杂工作流完整示例
|
|
291
|
-
|
|
292
|
-
```json
|
|
293
|
-
{
|
|
294
|
-
"name": "complex-workflow-demo",
|
|
295
|
-
"input": {},
|
|
296
|
-
"steps": [
|
|
297
|
-
{
|
|
298
|
-
"type": "parallel",
|
|
299
|
-
"steps": [
|
|
300
|
-
{ "type": "tool", "name": "get_time", "output": "time" },
|
|
301
|
-
{
|
|
302
|
-
"type": "tool",
|
|
303
|
-
"name": "storage_set",
|
|
304
|
-
"params": { "key": "status", "value": "started" },
|
|
305
|
-
"output": "storage"
|
|
306
|
-
},
|
|
307
|
-
{ "type": "tool", "name": "storage_list", "output": "namespaces" }
|
|
308
|
-
]
|
|
309
|
-
},
|
|
310
|
-
{
|
|
311
|
-
"type": "condition",
|
|
312
|
-
"if": { "key": "$.context.storage", "exists": true },
|
|
313
|
-
"then": [
|
|
314
|
-
{
|
|
315
|
-
"type": "tool",
|
|
316
|
-
"name": "notification_send",
|
|
317
|
-
"params": { "title": "开始", "message": "工作流启动" }
|
|
318
|
-
}
|
|
319
|
-
]
|
|
320
|
-
},
|
|
321
|
-
{ "type": "delay", "ms": 300 },
|
|
322
|
-
{
|
|
323
|
-
"type": "loop",
|
|
324
|
-
"count": 2,
|
|
325
|
-
"steps": [
|
|
326
|
-
{
|
|
327
|
-
"type": "tool",
|
|
328
|
-
"name": "notification_send",
|
|
329
|
-
"params": { "title": "循环", "message": "第 {{index}} 次" }
|
|
330
|
-
}
|
|
331
|
-
]
|
|
332
|
-
},
|
|
333
|
-
{
|
|
334
|
-
"type": "switch",
|
|
335
|
-
"value": "$.context.storage",
|
|
336
|
-
"cases": [
|
|
337
|
-
{
|
|
338
|
-
"value": "started",
|
|
339
|
-
"steps": [
|
|
340
|
-
{
|
|
341
|
-
"type": "tool",
|
|
342
|
-
"name": "notification_send",
|
|
343
|
-
"params": { "title": "状态", "message": "已开始" }
|
|
344
|
-
}
|
|
345
|
-
]
|
|
346
|
-
}
|
|
347
|
-
],
|
|
348
|
-
"default": [
|
|
349
|
-
{
|
|
350
|
-
"type": "tool",
|
|
351
|
-
"name": "notification_send",
|
|
352
|
-
"params": { "title": "状态", "message": "默认状态" }
|
|
353
|
-
}
|
|
354
|
-
]
|
|
355
|
-
},
|
|
356
|
-
{
|
|
357
|
-
"type": "try",
|
|
358
|
-
"steps": [{ "type": "tool", "name": "email_unread_count" }],
|
|
359
|
-
"catch": [
|
|
360
|
-
{
|
|
361
|
-
"type": "tool",
|
|
362
|
-
"name": "notification_send",
|
|
363
|
-
"params": { "title": "错误处理", "message": "捕获异常完成" }
|
|
364
|
-
}
|
|
365
|
-
]
|
|
366
|
-
},
|
|
367
|
-
{ "type": "workflow", "name": "workflow_file-backup", "input": {} },
|
|
368
|
-
{
|
|
369
|
-
"type": "tool",
|
|
370
|
-
"name": "notification_send",
|
|
371
|
-
"params": { "title": "完成", "message": "复杂工作流执行成功" }
|
|
372
|
-
}
|
|
373
|
-
]
|
|
374
|
-
}
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
## 关键结论
|
|
378
|
-
|
|
379
|
-
| 场景 | 推荐方案 |
|
|
380
|
-
| ------------ | ---------------------------- |
|
|
381
|
-
| 获取网络数据 | ✅ `fetch` 工具 |
|
|
382
|
-
| 本地脚本处理 | ✅ `python` 类型 + JSON 输出 |
|
|
383
|
-
| 接收外部请求 | `webhook` 类型(需服务运行) |
|
|
384
|
-
| 串行任务 | ✅ 多个 `tool`/`python` 步骤 |
|
|
385
|
-
| 并行任务 | ✅ `parallel` 类型 |
|
|
386
|
-
| 条件分支 | ✅ `condition` 类型 |
|
|
387
|
-
| 循环执行 | ✅ `loop` 类型 |
|
|
388
|
-
| 多分支选择 | ✅ `switch` 类型 |
|
|
389
|
-
| 错误处理 | ✅ `try-catch` 类型 |
|
|
390
|
-
| 延迟等待 | ✅ `delay` 类型 |
|
|
391
|
-
| 子工作流调用 | ✅ `workflow` 类型 |
|