foliko 1.0.68 → 1.0.69

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.
@@ -0,0 +1,314 @@
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
+ **好消息**: 工作流引擎**支持** `fetch` 工具!可以直接在 steps 中使用:
13
+
14
+ ```yaml
15
+ steps:
16
+ - type: tool
17
+ name: fetch
18
+ params:
19
+ url: "https://news.baidu.com"
20
+ timeout: 10000
21
+ output: "baidu_news"
22
+ ```
23
+
24
+ **优势**:
25
+ - 原生支持,无需额外 sandbox 配置
26
+ - 语法简洁
27
+ - 自动处理超时和错误
28
+
29
+ ### 2. 多个 fetch 步骤串联
30
+ **已验证可用**:
31
+
32
+ ```yaml
33
+ steps:
34
+ - type: tool
35
+ name: fetch
36
+ params:
37
+ url: "https://news.baidu.com"
38
+ output: "baidu_news"
39
+
40
+ - type: tool
41
+ name: fetch
42
+ params:
43
+ url: "https://feeds.bbci.co.uk/news/world/rss.xml"
44
+ output: "bbc_news"
45
+
46
+ - type: tool
47
+ name: fetch
48
+ params:
49
+ url: "https://www.reddit.com/r/popular/hot.json?limit=20"
50
+ output: "reddit_news"
51
+ ```
52
+
53
+ ### 3. Python 脚本获取结果
54
+ **正确方式**: Python 脚本返回 JSON 格式字符串
55
+
56
+ ```python
57
+ import json
58
+ import requests
59
+
60
+ result = {"news": ["标题1", "标题2"]}
61
+ print(json.dumps(result)) # 输出 JSON 字符串
62
+ ```
63
+
64
+ ### 4. webhook 类型步骤
65
+ **警告**: `webhook` 类型需要 HTTP 服务支持,否则会失败。
66
+ - 如需接收外部数据,使用 `web_register_webhook` 注册路由
67
+ - 测试时改用 `tool` + `fetch` 组合
68
+
69
+ ### 5. 变量传递问题
70
+ - **原因**: sandbox 环境无法访问主环境变量
71
+ - **解决方案**:
72
+ - 使用上下文变量 `$.context.xxx`
73
+ - 或直接在脚本中硬编码(测试用)
74
+
75
+ ## 调试技巧
76
+
77
+ 1. **先单独测试每个步骤** - 用简单输入验证
78
+ 2. **检查工作流定义语法** - YAML/JSON 格式正确性
79
+ 3. **使用简单输入测试变量传递**
80
+ 4. **fetch 失败时**: 加 `timeout` 参数,加 `proxy: true` 重试
81
+
82
+ ## 成功案例
83
+
84
+ ### 真实新闻聚合工作流
85
+ ```yaml
86
+ name: "news-fetcher"
87
+ steps:
88
+ - type: "context"
89
+ key: "current_time"
90
+ value: "$.time.current"
91
+
92
+ - type: "tool"
93
+ name: "fetch"
94
+ params:
95
+ url: "https://news.baidu.com"
96
+ timeout: 15000
97
+ output: "baidu_news"
98
+
99
+ - type: "tool"
100
+ name: "fetch"
101
+ params:
102
+ url: "https://feeds.bbci.co.uk/news/world/rss.xml"
103
+ timeout: 15000
104
+ output: "bbc_news"
105
+
106
+ - type: "tool"
107
+ name: "fetch"
108
+ params:
109
+ url: "https://www.reddit.com/r/popular/hot.json?limit=20"
110
+ timeout: 15000
111
+ output: "reddit_news"
112
+
113
+ - type: "python"
114
+ script: |
115
+ import json
116
+ # 处理新闻数据...
117
+ result = {"status": "success", "sources": ["baidu", "bbc", "reddit"]}
118
+ print(json.dumps(result))
119
+ ```
120
+
121
+ ### 网络不稳定时加代理
122
+ ```yaml
123
+ - type: "tool"
124
+ name: "fetch"
125
+ params:
126
+ url: "https://feeds.bbci.co.uk/news/world/rss.xml"
127
+ timeout: 15000
128
+ proxy: true # 失败时自动启用
129
+ output: "bbc_news"
130
+ ```
131
+
132
+ ## 复杂工作流步骤类型测试 ✅
133
+
134
+ 以下步骤类型已通过完整测试验证:
135
+
136
+ ### 1. parallel (并行执行) ✅
137
+ 多个任务同时执行,提高效率:
138
+
139
+ ```json
140
+ {
141
+ "type": "parallel",
142
+ "steps": [
143
+ {"type": "tool", "name": "get_time", "output": "current_time"},
144
+ {"type": "tool", "name": "storage_set", "params": {"key": "test", "value": "ok"}, "output": "storage_result"},
145
+ {"type": "tool", "name": "fetch", "params": {"url": "https://news.baidu.com"}, "output": "news"}
146
+ ]
147
+ }
148
+ ```
149
+
150
+ ### 2. condition (条件分支) ✅
151
+ 支持 if/else 逻辑判断:
152
+
153
+ ```json
154
+ {
155
+ "type": "condition",
156
+ "if": {"key": "$.context.storage_result", "equals": "success"},
157
+ "then": [
158
+ {"type": "tool", "name": "notification_send", "params": {"title": "成功", "message": "条件成立"}}
159
+ ],
160
+ "else": [
161
+ {"type": "tool", "name": "notification_send", "params": {"title": "失败", "message": "条件不成立"}}
162
+ ]
163
+ }
164
+ ```
165
+
166
+ **支持的操作符**:`equals`, `not_equals`, `contains`, `greater_than`, `less_than`, `exists`, `not_exists`
167
+
168
+ ### 3. loop (循环执行) ✅
169
+ 支持指定次数的循环:
170
+
171
+ ```json
172
+ {
173
+ "type": "loop",
174
+ "count": 3,
175
+ "steps": [
176
+ {"type": "tool", "name": "notification_send", "params": {"title": "循环", "message": "第 {{index}} 次"}}
177
+ ]
178
+ }
179
+ ```
180
+
181
+ ### 4. switch (多分支) ✅
182
+ 类似 switch-case 的多条件分支:
183
+
184
+ ```json
185
+ {
186
+ "type": "switch",
187
+ "value": "$.context.status",
188
+ "cases": [
189
+ {"value": "success", "steps": [{"type": "tool", "name": "notification_send", "params": {"title": "成功"}}]},
190
+ {"value": "error", "steps": [{"type": "tool", "name": "notification_send", "params": {"title": "错误"}}]}
191
+ ],
192
+ "default": [
193
+ {"type": "tool", "name": "notification_send", "params": {"title": "默认"}}
194
+ ]
195
+ }
196
+ ```
197
+
198
+ ### 5. try-catch (错误处理) ✅
199
+ 捕获步骤执行中的错误,防止中断:
200
+
201
+ ```json
202
+ {
203
+ "type": "try",
204
+ "steps": [
205
+ {"type": "tool", "name": "email_unread_count"}
206
+ ],
207
+ "catch": [
208
+ {"type": "tool", "name": "notification_send", "params": {"title": "捕获错误", "message": "邮件服务超时,使用备用方案"}}
209
+ ]
210
+ }
211
+ ```
212
+
213
+ ### 6. delay (延迟执行) ✅
214
+ 在步骤之间添加延迟:
215
+
216
+ ```json
217
+ {
218
+ "type": "delay",
219
+ "ms": 500
220
+ }
221
+ ```
222
+
223
+ ### 7. nested workflow (嵌套工作流) ✅
224
+ 在主工作流中调用子工作流:
225
+
226
+ ```json
227
+ {
228
+ "type": "workflow",
229
+ "name": "workflow_file-backup",
230
+ "input": {}
231
+ }
232
+ ```
233
+
234
+ ### 8. context (上下文变量) ✅
235
+ 在步骤间传递数据:
236
+
237
+ ```json
238
+ {
239
+ "type": "context",
240
+ "key": "workflow_status",
241
+ "value": "completed"
242
+ }
243
+ ```
244
+
245
+ ## 复杂工作流完整示例
246
+
247
+ ```json
248
+ {
249
+ "name": "complex-workflow-demo",
250
+ "input": {},
251
+ "steps": [
252
+ {
253
+ "type": "parallel",
254
+ "steps": [
255
+ {"type": "tool", "name": "get_time", "output": "time"},
256
+ {"type": "tool", "name": "storage_set", "params": {"key": "status", "value": "started"}, "output": "storage"},
257
+ {"type": "tool", "name": "storage_list", "output": "namespaces"}
258
+ ]
259
+ },
260
+ {
261
+ "type": "condition",
262
+ "if": {"key": "$.context.storage", "exists": true},
263
+ "then": [
264
+ {"type": "tool", "name": "notification_send", "params": {"title": "开始", "message": "工作流启动"}}
265
+ ]
266
+ },
267
+ {"type": "delay", "ms": 300},
268
+ {
269
+ "type": "loop",
270
+ "count": 2,
271
+ "steps": [
272
+ {"type": "tool", "name": "notification_send", "params": {"title": "循环", "message": "第 {{index}} 次"}}
273
+ ]
274
+ },
275
+ {
276
+ "type": "switch",
277
+ "value": "$.context.storage",
278
+ "cases": [
279
+ {"value": "started", "steps": [{"type": "tool", "name": "notification_send", "params": {"title": "状态", "message": "已开始"}}]}
280
+ ],
281
+ "default": [
282
+ {"type": "tool", "name": "notification_send", "params": {"title": "状态", "message": "默认状态"}}
283
+ ]
284
+ },
285
+ {
286
+ "type": "try",
287
+ "steps": [
288
+ {"type": "tool", "name": "email_unread_count"}
289
+ ],
290
+ "catch": [
291
+ {"type": "tool", "name": "notification_send", "params": {"title": "错误处理", "message": "捕获异常完成"}}
292
+ ]
293
+ },
294
+ {"type": "workflow", "name": "workflow_file-backup", "input": {}},
295
+ {"type": "tool", "name": "notification_send", "params": {"title": "完成", "message": "复杂工作流执行成功"}}
296
+ ]
297
+ }
298
+ ```
299
+
300
+ ## 关键结论
301
+
302
+ | 场景 | 推荐方案 |
303
+ |------|----------|
304
+ | 获取网络数据 | ✅ `fetch` 工具 |
305
+ | 本地脚本处理 | ✅ `python` 类型 + JSON 输出 |
306
+ | 接收外部请求 | `webhook` 类型(需服务运行) |
307
+ | 串行任务 | ✅ 多个 `tool`/`python` 步骤 |
308
+ | 并行任务 | ✅ `parallel` 类型 |
309
+ | 条件分支 | ✅ `condition` 类型 |
310
+ | 循环执行 | ✅ `loop` 类型 |
311
+ | 多分支选择 | ✅ `switch` 类型 |
312
+ | 错误处理 | ✅ `try-catch` 类型 |
313
+ | 延迟等待 | ✅ `delay` 类型 |
314
+ | 子工作流调用 | ✅ `workflow` 类型 |