foliko 1.0.64 → 1.0.66
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 +145 -142
- package/cli/src/commands/chat.js +4 -1
- package/package.json +1 -1
- package/plugins/ai-plugin.js +2 -1
- package/plugins/ambient-agent-plugin.js +160 -48
- package/plugins/email.js +170 -18
- package/plugins/file-system-plugin.js +2 -2
- package/skills/ambient-agent/SKILL.md +234 -0
- package/skills/workflow-guide/SKILL.md +139 -73
- package/src/capabilities/workflow-engine.js +435 -127
- package/src/core/agent-chat.js +26 -4
- package/src/core/agent.js +1 -1
- package/src/core/framework.js +3 -3
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: workflow-guide
|
|
3
3
|
description: 工作流与多步任务指南。当用户说"创建工作流"、"多步任务"、"自动化流程"时立即调用。
|
|
4
|
-
allowed-tools:
|
|
4
|
+
allowed-tools: execute_workflow,reloadWorkflows
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 工作流(Workflow)开发指南
|
|
8
8
|
|
|
9
9
|
## 概述
|
|
10
10
|
|
|
11
|
-
工作流引擎用于处理多步骤任务,通过 `execute_workflow`
|
|
11
|
+
工作流引擎用于处理多步骤任务,通过 `execute_workflow` 工具执行。工作流由多个步骤组成,支持脚本、条件分支、循环、延时、工具调用等类型。
|
|
12
12
|
|
|
13
13
|
## 工作流存放位置
|
|
14
14
|
|
|
@@ -46,7 +46,7 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash, execute_workflow, reloadWork
|
|
|
46
46
|
{
|
|
47
47
|
"tool": "execute_workflow",
|
|
48
48
|
"args": {
|
|
49
|
-
"workflow": "
|
|
49
|
+
"workflow": "my-workflow", // 工作流名称(自动从 .agent/workflows/ 加载)
|
|
50
50
|
"input": { "变量名": "值" }
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -62,26 +62,83 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash, execute_workflow, reloadWork
|
|
|
62
62
|
}
|
|
63
63
|
```
|
|
64
64
|
|
|
65
|
+
## 重要注意事项
|
|
66
|
+
|
|
67
|
+
1. **script 必须用 return 返回值**:`script` 是函数体,不是表达式
|
|
68
|
+
2. **JSON 中不能使用多行字符串**:所有 script 内容写成单行,用分号分隔
|
|
69
|
+
3. **JSON 中不能有注释**:注释会导致 JSON 解析失败
|
|
70
|
+
|
|
65
71
|
## 工作流步骤类型
|
|
66
72
|
|
|
67
73
|
### 1. script - 脚本步骤
|
|
68
74
|
|
|
69
|
-
执行 JavaScript
|
|
75
|
+
执行 JavaScript 脚本,**必须用 return 返回值**:
|
|
70
76
|
|
|
71
77
|
```json
|
|
72
78
|
{
|
|
73
79
|
"type": "script",
|
|
74
80
|
"name": "步骤名称",
|
|
75
81
|
"outputVariable": "result",
|
|
76
|
-
"script": "context.variables.x
|
|
82
|
+
"script": "var x=10; context.variables.count=x+1; return context.variables.count;"
|
|
77
83
|
}
|
|
78
84
|
```
|
|
79
85
|
|
|
80
|
-
|
|
86
|
+
**正确写法**:
|
|
87
|
+
```json
|
|
88
|
+
{ "script": "return context.variables.value + 1;" }
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**错误写法**(缺少 return):
|
|
92
|
+
```json
|
|
93
|
+
{ "script": "context.variables.value + 1;" }
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- `outputVariable`: 可选,将返回值存入 `context.variables`
|
|
81
97
|
- `context.variables`: 所有步骤共享的变量对象
|
|
82
|
-
- `context.
|
|
98
|
+
- `context.lastResult`: 上一步的输出结果
|
|
83
99
|
|
|
84
|
-
### 2.
|
|
100
|
+
### 2. tool - 工具调用步骤
|
|
101
|
+
|
|
102
|
+
在工作流中调用框架注册的工具:
|
|
103
|
+
|
|
104
|
+
```json
|
|
105
|
+
{
|
|
106
|
+
"type": "tool",
|
|
107
|
+
"name": "发送通知",
|
|
108
|
+
"tool": "notification_send",
|
|
109
|
+
"args": {
|
|
110
|
+
"title": "标题",
|
|
111
|
+
"message": "内容"
|
|
112
|
+
},
|
|
113
|
+
"outputVariable": "result"
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
**参数说明**:
|
|
118
|
+
|
|
119
|
+
| 字段 | 类型 | 必填 | 说明 |
|
|
120
|
+
|------|------|------|------|
|
|
121
|
+
| `tool` | string | 是 | 工具名称 |
|
|
122
|
+
| `args` | object | 否 | 工具参数 |
|
|
123
|
+
| `outputVariable` | string | 否 | 结果保存到的变量名 |
|
|
124
|
+
|
|
125
|
+
**args 中支持变量引用**:
|
|
126
|
+
|
|
127
|
+
使用 `{{variableName}}` 语法引用 context.variables 中的变量:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"type": "tool",
|
|
132
|
+
"name": "发送通知",
|
|
133
|
+
"tool": "notification_send",
|
|
134
|
+
"args": {
|
|
135
|
+
"title": "IP 信息",
|
|
136
|
+
"message": "当前公网IP: {{currentIp}}"
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### 3. loop - 循环步骤
|
|
85
142
|
|
|
86
143
|
重复执行一组步骤:
|
|
87
144
|
|
|
@@ -100,7 +157,7 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash, execute_workflow, reloadWork
|
|
|
100
157
|
- `maxIterations`: 最大迭代次数
|
|
101
158
|
- `loopVariable`: 循环计数器变量名(从 0 开始)
|
|
102
159
|
|
|
103
|
-
###
|
|
160
|
+
### 4. condition - 条件分支
|
|
104
161
|
|
|
105
162
|
根据条件选择执行分支:
|
|
106
163
|
|
|
@@ -123,7 +180,7 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash, execute_workflow, reloadWork
|
|
|
123
180
|
}
|
|
124
181
|
```
|
|
125
182
|
|
|
126
|
-
###
|
|
183
|
+
### 5. delay - 延时步骤
|
|
127
184
|
|
|
128
185
|
等待指定毫秒数:
|
|
129
186
|
|
|
@@ -135,85 +192,63 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash, execute_workflow, reloadWork
|
|
|
135
192
|
}
|
|
136
193
|
```
|
|
137
194
|
|
|
138
|
-
###
|
|
195
|
+
### 6. sequential - 顺序步骤
|
|
139
196
|
|
|
140
|
-
|
|
197
|
+
将多个步骤组合为顺序执行(可嵌套使用):
|
|
141
198
|
|
|
142
199
|
```json
|
|
143
200
|
{
|
|
144
|
-
"type": "
|
|
145
|
-
"name": "
|
|
146
|
-
"steps": [
|
|
201
|
+
"type": "sequential",
|
|
202
|
+
"name": "顺序执行",
|
|
203
|
+
"steps": [
|
|
204
|
+
{ "type": "script", "name": "步骤1", "script": "return 1;" },
|
|
205
|
+
{ "type": "script", "name": "步骤2", "script": "return 2;" }
|
|
206
|
+
]
|
|
147
207
|
}
|
|
148
208
|
```
|
|
149
209
|
|
|
210
|
+
## sessionId 传递
|
|
211
|
+
|
|
212
|
+
工作流执行时会自动获取当前 sessionId,所有 tool 调用都会使用该 sessionId,确保通知发送到当前会话。
|
|
213
|
+
|
|
150
214
|
## 完整示例
|
|
151
215
|
|
|
152
|
-
###
|
|
216
|
+
### 示例:获取IP并发送通知
|
|
153
217
|
|
|
154
218
|
```json
|
|
155
219
|
{
|
|
156
|
-
"name": "
|
|
157
|
-
"description": "
|
|
220
|
+
"name": "get-ip-notify",
|
|
221
|
+
"description": "获取本机IP并发送通知",
|
|
158
222
|
"steps": [
|
|
159
223
|
{
|
|
160
|
-
"type": "
|
|
161
|
-
"name": "
|
|
162
|
-
"
|
|
163
|
-
"
|
|
224
|
+
"type": "tool",
|
|
225
|
+
"name": "获取IP信息",
|
|
226
|
+
"tool": "fetch",
|
|
227
|
+
"args": {
|
|
228
|
+
"url": "https://api.ipify.org?format=json",
|
|
229
|
+
"proxy": true
|
|
230
|
+
},
|
|
231
|
+
"outputVariable": "ipResult"
|
|
164
232
|
},
|
|
165
233
|
{
|
|
166
234
|
"type": "script",
|
|
167
|
-
"name": "
|
|
168
|
-
"outputVariable": "
|
|
169
|
-
"script": "
|
|
235
|
+
"name": "提取IP",
|
|
236
|
+
"outputVariable": "currentIp",
|
|
237
|
+
"script": "var r=context.variables.ipResult; return (r&&r.success&&r.body)?(typeof r.body==='object'?r.body.ip:r.body.trim()):'获取失败';"
|
|
170
238
|
},
|
|
171
239
|
{
|
|
172
|
-
"type": "
|
|
173
|
-
"name": "
|
|
174
|
-
"
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
{
|
|
180
|
-
"type": "script",
|
|
181
|
-
"name": "模拟天气查询",
|
|
182
|
-
"outputVariable": "weather",
|
|
183
|
-
"script": "return '今天天气晴,温度 25°C';"
|
|
184
|
-
}
|
|
185
|
-
]
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
"name": "不需要查询天气",
|
|
189
|
-
"condition": "true",
|
|
190
|
-
"steps": [
|
|
191
|
-
{
|
|
192
|
-
"type": "script",
|
|
193
|
-
"name": "跳过天气",
|
|
194
|
-
"outputVariable": "weather",
|
|
195
|
-
"script": "return '好的,有需要随时叫我!';"
|
|
196
|
-
}
|
|
197
|
-
]
|
|
198
|
-
}
|
|
199
|
-
]
|
|
240
|
+
"type": "tool",
|
|
241
|
+
"name": "发送通知",
|
|
242
|
+
"tool": "notification_send",
|
|
243
|
+
"args": {
|
|
244
|
+
"title": "IP 信息",
|
|
245
|
+
"message": "当前公网IP: {{currentIp}}"
|
|
246
|
+
}
|
|
200
247
|
}
|
|
201
248
|
]
|
|
202
249
|
}
|
|
203
250
|
```
|
|
204
251
|
|
|
205
|
-
调用:
|
|
206
|
-
|
|
207
|
-
```json
|
|
208
|
-
{
|
|
209
|
-
"tool": "execute_workflow",
|
|
210
|
-
"args": {
|
|
211
|
-
"workflow": "<上面 JSON 转字符串>",
|
|
212
|
-
"input": { "username": "张三", "queryWeather": true }
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
```
|
|
216
|
-
|
|
217
252
|
### 示例:循环处理任务列表
|
|
218
253
|
|
|
219
254
|
```json
|
|
@@ -225,7 +260,7 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash, execute_workflow, reloadWork
|
|
|
225
260
|
"type": "script",
|
|
226
261
|
"name": "初始化列表",
|
|
227
262
|
"outputVariable": "items",
|
|
228
|
-
"script": "context.variables.items
|
|
263
|
+
"script": "context.variables.items=['任务A','任务B','任务C']; return context.variables.items;"
|
|
229
264
|
},
|
|
230
265
|
{
|
|
231
266
|
"type": "loop",
|
|
@@ -237,7 +272,7 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash, execute_workflow, reloadWork
|
|
|
237
272
|
"type": "script",
|
|
238
273
|
"name": "处理任务",
|
|
239
274
|
"outputVariable": "processed",
|
|
240
|
-
"script": "
|
|
275
|
+
"script": "var item=context.variables.items[context.variables.i]; context.variables.processed=(context.variables.processed||[]); context.variables.processed.push(item+'_完成'); return item;"
|
|
241
276
|
}
|
|
242
277
|
]
|
|
243
278
|
}
|
|
@@ -247,12 +282,13 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash, execute_workflow, reloadWork
|
|
|
247
282
|
|
|
248
283
|
## 注意事项
|
|
249
284
|
|
|
250
|
-
1. **
|
|
251
|
-
2. **
|
|
252
|
-
3. **
|
|
253
|
-
4.
|
|
254
|
-
5.
|
|
255
|
-
6.
|
|
285
|
+
1. **script 必须 return**:`script` 是函数体,必须用 return 返回值
|
|
286
|
+
2. **JSON 中 script 单行写**:用分号分隔多个语句,不要换行
|
|
287
|
+
3. **JSON 中不能有注释**:注释会导致 JSON 解析失败
|
|
288
|
+
4. **context.variables** 在所有步骤间共享,可存储中间结果
|
|
289
|
+
5. **context.input** 是工作流的输入参数
|
|
290
|
+
6. 循环变量 `i` 从 0 开始计数
|
|
291
|
+
7. 条件分支的 `condition` 是 JavaScript 表达式字符串
|
|
256
292
|
|
|
257
293
|
## 最佳实践
|
|
258
294
|
|
|
@@ -261,3 +297,33 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash, execute_workflow, reloadWork
|
|
|
261
297
|
3. 循环前确保有合理的 `maxIterations` 限制
|
|
262
298
|
4. 条件分支要有兜底的 `condition: "true"` 分支
|
|
263
299
|
5. 复杂的业务逻辑优先使用脚本步骤
|
|
300
|
+
6. **script 必须 return**:`script` 是函数体,必须用 return 返回值
|
|
301
|
+
7. **JSON 中 script 单行写**:用分号分隔多个语句,不要换行
|
|
302
|
+
|
|
303
|
+
**错误示例**:
|
|
304
|
+
```json
|
|
305
|
+
// ❌ 错误 - script 没有 return
|
|
306
|
+
{ "type": "script", "script": "context.variables.count + 1;" }
|
|
307
|
+
|
|
308
|
+
// ❌ 错误 - JSON 多行字符串
|
|
309
|
+
{
|
|
310
|
+
"script": "
|
|
311
|
+
const a = 10;
|
|
312
|
+
return a + 1;
|
|
313
|
+
"
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ❌ 错误 - JSON 中有注释
|
|
317
|
+
{
|
|
318
|
+
"script": "return 1; // 这是注释"
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
**正确示例**:
|
|
323
|
+
```json
|
|
324
|
+
// ✅ 正确
|
|
325
|
+
{ "type": "script", "outputVariable": "count", "script": "return (context.variables.count||0) + 1;" }
|
|
326
|
+
|
|
327
|
+
// ✅ 正确 - 复杂逻辑拆成多步
|
|
328
|
+
{ "type": "script", "script": "context.variables.a=10; context.variables.b=20; return context.variables.a+context.variables.b;" }
|
|
329
|
+
```
|