foliko 1.1.6 → 1.1.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/.agent/data/email/processed-emails.json +1 -0
- package/.agent/data/plugins-state.json +5 -1
- package/.agent/data/web/web-config.json +5 -0
- package/.agent/memory/feedback/mnt7jrlt-d67qs7.md +15 -0
- package/.agent/memory/feedback/mnt88ja3-al4fuy.md +9 -0
- package/.agent/plugins/test-plugin.py +108 -0
- package/.agent/sessions/cli_default.json +514 -5298
- package/.claude/settings.local.json +2 -1
- package/SPEC.md +735 -696
- package/output/zen_silence.png +0 -0
- package/package.json +2 -2
- package/plugins/ambient-agent/EventWatcher.js +33 -37
- package/plugins/ambient-agent/ExplorerLoop.js +338 -36
- package/plugins/ambient-agent/GoalManager.js +7 -3
- package/plugins/ambient-agent/StateStore.js +30 -1
- package/plugins/ambient-agent/constants.js +15 -1
- package/plugins/ambient-agent/index.js +26 -33
- package/plugins/coordinator-plugin.js +3 -3
- package/plugins/default-plugins.js +2 -2
- package/plugins/email/index.js +150 -36
- package/plugins/email/monitor.js +79 -5
- package/plugins/email/reply.js +15 -25
- package/plugins/extension-executor-plugin.js +160 -31
- package/plugins/file-system-plugin.js +57 -24
- package/plugins/memory-plugin.js +176 -64
- package/plugins/python-plugin-loader.js +79 -9
- package/plugins/scheduler-plugin.js +64 -24
- package/plugins/think-plugin.js +7 -2
- package/plugins/web-plugin.js +263 -4
- package/skills/ambient-agent/SKILL.md +342 -314
- package/src/core/agent-chat.js +64 -9
- package/src/core/agent.js +118 -59
- package/src/core/tool-registry.js +5 -5
- package/src/executors/mcp-executor.js +188 -26
- package/src/utils/id.js +5 -0
- package/system.md +3480 -0
- package/.agent/data/ambient/goals.json +0 -50
- package/.agent/data/ambient/memories.json +0 -7
- package/.agent/memory/core.md +0 -1
- package/.agent/memory/feedback/mnrsiuoc-e1ru74.md +0 -9
- package/.agent/memory/feedback/mnrt2mmz-98az6n.md +0 -9
- package/.agent/memory/feedback/mnrtqrhm-kxsicz.md +0 -9
- package/.agent/memory/feedback/mnrts8vg-i0ngzp.md +0 -15
- package/.agent/memory/feedback/mnrtt7jt-c0trb2.md +0 -9
- package/.agent/memory/feedback/mnruc2f0-5s52la.md +0 -16
- package/.agent/memory/feedback/mnrumbmx-63sa0v.md +0 -9
- package/.agent/memory/project/mnn93ogy-ypjn27.md +0 -9
- package/.agent/memory/project/mnn98fqy-5nhc1u.md +0 -25
- package/.agent/memory/project/mnrp7p5n-8enm2a.md +0 -31
- package/.agent/memory/project/mnrp9ifb-yynks0.md +0 -40
- package/.agent/memory/project/mnrpb3b8-f617s4.md +0 -25
- package/.agent/memory/project/mnrrmqgg-focprv.md +0 -9
- package/.agent/memory/project/mnrtykbh-6atsor.md +0 -9
- package/.agent/memory/project/mnru9jiu-kgau16.md +0 -35
- package/.agent/memory/reference/mnq3oenw-46haj6.md +0 -63
- package/.agent/memory/reference/mnq5qxm2-mjoooh.md +0 -116
- package/.agent/memory/reference/mnrnvpwo-rcqv9m.md +0 -52
- package/.agent/memory/reference/mnrovxvz-zy9xqm.md +0 -25
- package/.agent/memory/reference/mnroxabj-1b3930.md +0 -68
- package/.agent/memory/reference/mnrpjtlp-mnb9od.md +0 -35
- package/.agent/memory/reference/mnrps1x3-6b8xfm.md +0 -28
- package/.agent/memory/reference/mnrpt9ov-15er5w.md +0 -22
- package/.agent/memory/reference/mnrq82dn-y9tv9e.md +0 -50
- package/.agent/memory/reference/mnrqnr5v-v75drf.md +0 -34
- package/.agent/memory/reference/mnrrfzys-urudaf.md +0 -31
- package/.agent/memory/reference/mnrrocha-t0027n.md +0 -21
- package/.agent/memory/reference/mnrukklc-bxndsb.md +0 -35
- package/.agent/memory/user/mnm67t9m-x8rekk.md +0 -9
- package/.agent/memory/user/mnn5mmqh-w6aktx.md +0 -11
- package/.agent/memory/user/mnnbfhhn-dk1bd1.md +0 -22
- package/.agent/memory/user/mnrt39t8-8eosy0.md +0 -9
- package/foliko-cloud-rising.png +0 -0
- package/foliko-dawn-of-ai.png +0 -0
- package/foliko-mindful-observation.png +0 -0
- package/foliko-stellar-dreams.png +0 -0
- package/foliko-zen-jing.png +0 -0
- package/foliko-zen-kong.png +0 -0
- package/foliko-zen-wu.png +0 -0
- package/zen_karesansui.png +0 -0
|
@@ -1,314 +1,342 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: ambient-agent
|
|
3
|
-
description: Ambient Agent - 持续后台运行的智能代理,用于主动监控事件和执行操作
|
|
4
|
-
allowed-tools: ambient_goals,ambient_status,ambient_think,ambient_remember,ambient_control
|
|
5
|
-
---
|
|
6
|
-
|
|
7
|
-
# Ambient Agent
|
|
8
|
-
|
|
9
|
-
Ambient Agent 是一个持续后台运行的智能代理,监控事件并主动执行操作。
|
|
10
|
-
|
|
11
|
-
## 核心概念
|
|
12
|
-
|
|
13
|
-
### Goal(目标)
|
|
14
|
-
|
|
15
|
-
目标是对话式 LLM 派发的任务,包含:
|
|
16
|
-
|
|
17
|
-
- `title` - 目标标题
|
|
18
|
-
- `description` - 目标描述
|
|
19
|
-
- `priority` - 优先级 1-10
|
|
20
|
-
- `actions` - 要执行的操作列表
|
|
21
|
-
- `conditions` - 激活条件(如监听特定事件)
|
|
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
|
-
title: '
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
//
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
//
|
|
110
|
-
await
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
await
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
//
|
|
168
|
-
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
##
|
|
172
|
-
|
|
173
|
-
Ambient Agent
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
-
|
|
230
|
-
-
|
|
231
|
-
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
{
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
1
|
+
---
|
|
2
|
+
name: ambient-agent
|
|
3
|
+
description: Ambient Agent - 持续后台运行的智能代理,用于主动监控事件和执行操作
|
|
4
|
+
allowed-tools: ambient_goals,ambient_status,ambient_think,ambient_remember,ambient_control
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Ambient Agent
|
|
8
|
+
|
|
9
|
+
Ambient Agent 是一个持续后台运行的智能代理,监控事件并主动执行操作。
|
|
10
|
+
|
|
11
|
+
## 核心概念
|
|
12
|
+
|
|
13
|
+
### Goal(目标)
|
|
14
|
+
|
|
15
|
+
目标是对话式 LLM 派发的任务,包含:
|
|
16
|
+
|
|
17
|
+
- `title` - 目标标题
|
|
18
|
+
- `description` - 目标描述
|
|
19
|
+
- `priority` - 优先级 1-10
|
|
20
|
+
- `actions` - 要执行的操作列表
|
|
21
|
+
- `conditions` - 激活条件(如监听特定事件)
|
|
22
|
+
- `persistent` - 是否持久化(默认 true,false 为一次性任务)
|
|
23
|
+
- `state` - 状态:`pending` | `active` | `completed` | `failed`
|
|
24
|
+
|
|
25
|
+
### Action(操作)
|
|
26
|
+
|
|
27
|
+
操作是目标的最小执行单元,有三种类型:
|
|
28
|
+
|
|
29
|
+
| 类型 | 说明 | 参数 |
|
|
30
|
+
| --------- | -------- | --------------------------------------- |
|
|
31
|
+
| `tool` | 调用工具 | `name` 工具名, `args` 参数 |
|
|
32
|
+
| `message` | 发送消息 | `content` 消息内容 |
|
|
33
|
+
| `think` | 触发思考 | `topic` 主题, `mode` 模式, `depth` 深度 |
|
|
34
|
+
|
|
35
|
+
每个 action 有 `completed` 标记,执行完成后标记为 true。
|
|
36
|
+
|
|
37
|
+
### Event(事件)
|
|
38
|
+
|
|
39
|
+
目标可以监听以下框架事件:
|
|
40
|
+
|
|
41
|
+
| 事件 | 触发时机 | 数据结构 |
|
|
42
|
+
| -------------------------- | ----------------- | ------------------------------------------------------------------------------- | ---- |
|
|
43
|
+
| `email:received` | 收到新邮件 | `{uid, messageId, from, to, subject, text, body, html, attachments, timestamp}` |
|
|
44
|
+
| `webhook:received` | 收到 Webhook 请求 | `{path, method, query, body, timestamp}` |
|
|
45
|
+
| `webhook:processed` | Webhook 处理完成 | `{path, method, query, body, response, timestamp}` |
|
|
46
|
+
| `scheduler:task_created` | 定时任务创建 | `{taskId, taskName, type, scheduleTime, cronExpression}` |
|
|
47
|
+
| `scheduler:reminder` | 定时提醒触发 | `{taskId, message, time}` |
|
|
48
|
+
| `scheduler:task_completed` | 定时任务完成 | `{taskId, result}` |
|
|
49
|
+
| `scheduler:task_failed` | 定时任务失败 | `{taskId, error}` |
|
|
50
|
+
| `think:thought_completed` | 思考完成 | `{mode, topic, thought, depth}` |
|
|
51
|
+
| `tool:result` | 工具执行成功 | `{name, args, result, source}` (source: tool | mcp) |
|
|
52
|
+
| `tool:error` | 工具执行错误 | `{name, args, error, source}` (source: tool | mcp) |
|
|
53
|
+
| `tool:call` | 工具被调用 | `{name, args, source}` (source: tool | mcp) |
|
|
54
|
+
| `agent:message` | Agent 发送消息 | `{content, sessionId, userMessage}` |
|
|
55
|
+
| `worker:completed` | Worker 完成 | `{workerId, name, result, notification}` |
|
|
56
|
+
| `worker:error` | Worker 错误 | `{workerId, name, error, notification}` |
|
|
57
|
+
| `subagent:chat:end` | 子 Agent 聊天结束 | `{parentAgent, subAgent, subAgentName, result}` |
|
|
58
|
+
|
|
59
|
+
## 工具
|
|
60
|
+
|
|
61
|
+
### ambient_goals - 目标管理
|
|
62
|
+
|
|
63
|
+
```javascript
|
|
64
|
+
// 列出所有目标
|
|
65
|
+
await ambient_goals({ action: 'list' })
|
|
66
|
+
|
|
67
|
+
// 创建持久化目标(默认)- 事件驱动,执行完等待下一事件
|
|
68
|
+
await ambient_goals({
|
|
69
|
+
action: 'create',
|
|
70
|
+
title: '监控邮件',
|
|
71
|
+
description: '收到邮件后自动回复',
|
|
72
|
+
priority: 8,
|
|
73
|
+
persistent: true, // 默认 true,持久化目标
|
|
74
|
+
actions: [
|
|
75
|
+
{ id: 'auto-reply', type: 'tool', name: 'email_auto_reply', args: {...} }
|
|
76
|
+
],
|
|
77
|
+
conditions: {
|
|
78
|
+
events: ['email:received']
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
// 创建一次性目标 - 执行完自动完成,不等待新事件
|
|
83
|
+
await ambient_goals({
|
|
84
|
+
action: 'create',
|
|
85
|
+
title: '处理定时提醒',
|
|
86
|
+
description: '提醒到达后执行一次操作',
|
|
87
|
+
priority: 8,
|
|
88
|
+
persistent: false, // 一次性任务
|
|
89
|
+
actions: [
|
|
90
|
+
{ id: 'process', type: 'tool', name: 'some_tool', args: {...} }
|
|
91
|
+
],
|
|
92
|
+
conditions: {
|
|
93
|
+
events: ['scheduler:reminder']
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
// 更新目标
|
|
98
|
+
await ambient_goals({
|
|
99
|
+
action: 'update',
|
|
100
|
+
goalId: 'xxx-xxx',
|
|
101
|
+
title: '新标题',
|
|
102
|
+
persistent: false, // 改为一次性
|
|
103
|
+
actions: [...] // 新操作列表
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
// 删除目标
|
|
107
|
+
await ambient_goals({ action: 'delete', goalId: 'xxx-xxx' })
|
|
108
|
+
|
|
109
|
+
// 激活目标
|
|
110
|
+
await ambient_goals({ action: 'activate', goalId: 'xxx-xxx' })
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### ambient_status - 获取状态
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
await ambient_status({});
|
|
117
|
+
// 返回: { running, tickCount, activeGoals, pendingGoals, recentActivities }
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### ambient_think - 触发思考
|
|
121
|
+
|
|
122
|
+
```javascript
|
|
123
|
+
await ambient_think({
|
|
124
|
+
goalId: 'xxx-xxx', // 可选,关联目标
|
|
125
|
+
mode: 'reflect', // reflect | brainstorm | plan | analyze
|
|
126
|
+
topic: '反思主题', // 可选
|
|
127
|
+
depth: 2, // 可选,1-5
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### ambient_remember - 记忆管理
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
// 存储记忆
|
|
135
|
+
await ambient_remember({
|
|
136
|
+
action: 'store',
|
|
137
|
+
key: 'user-preference',
|
|
138
|
+
content: '用户喜欢在早上收到摘要',
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// 检索最近记忆
|
|
142
|
+
await ambient_remember({
|
|
143
|
+
action: 'retrieve',
|
|
144
|
+
limit: 10,
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// 搜索记忆
|
|
148
|
+
await ambient_remember({
|
|
149
|
+
action: 'search',
|
|
150
|
+
query: '邮件',
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### ambient_control - 控制循环
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
// 暂停
|
|
158
|
+
await ambient_control({ action: 'pause' });
|
|
159
|
+
|
|
160
|
+
// 恢复
|
|
161
|
+
await ambient_control({ action: 'resume' });
|
|
162
|
+
|
|
163
|
+
// 调整参数
|
|
164
|
+
await ambient_control({
|
|
165
|
+
action: 'adjust',
|
|
166
|
+
tickInterval: 10000, // 新 tick 间隔(毫秒)
|
|
167
|
+
cooldownPeriod: 5000, // 新冷却时间(毫秒)
|
|
168
|
+
});
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## action 与 step 的关系
|
|
172
|
+
|
|
173
|
+
Ambient Agent 的 action 与 Workflow Engine 的 step 共用 `StepExecutor` 执行:
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
action.type → step.type
|
|
177
|
+
───────────────────────
|
|
178
|
+
tool → tool
|
|
179
|
+
message → message
|
|
180
|
+
think → think
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
这意味着:
|
|
184
|
+
|
|
185
|
+
- 变量引用语法一致:`${variableName}`(Ambient Agent 使用 `${}`)
|
|
186
|
+
- sessionId 传递机制一致
|
|
187
|
+
- 错误处理方式一致
|
|
188
|
+
|
|
189
|
+
## action 执行上下文
|
|
190
|
+
|
|
191
|
+
当 action 执行时,可用的上下文:
|
|
192
|
+
|
|
193
|
+
```javascript
|
|
194
|
+
// context.variables 中可用
|
|
195
|
+
context.variables._event; // 触发的事件数据(如果有)
|
|
196
|
+
context.variables._action; // 当前执行的 action 对象
|
|
197
|
+
context.variables.loopIndex; // 循环索引(如果被 loop 执行)
|
|
198
|
+
|
|
199
|
+
// context.input 中可用
|
|
200
|
+
context.input; // 工作流/目标输入参数
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## 变量引用语法
|
|
204
|
+
|
|
205
|
+
Ambient Agent 使用 `${}` 语法在 action 参数中引用变量:
|
|
206
|
+
|
|
207
|
+
### 1. 事件数据引用 `${event.xxx}`
|
|
208
|
+
|
|
209
|
+
当 goal 监听事件时,事件数据可通过 `${event.xxx}` 直接引用:
|
|
210
|
+
|
|
211
|
+
```javascript
|
|
212
|
+
{
|
|
213
|
+
id: 'auto-reply',
|
|
214
|
+
type: 'tool',
|
|
215
|
+
name: 'email_auto_reply',
|
|
216
|
+
args: {
|
|
217
|
+
to: '${event.from}',
|
|
218
|
+
subject: '${event.subject}',
|
|
219
|
+
body: '${event.text}',
|
|
220
|
+
from: ''
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
**注意**:`email:received` 事件的数据结构:
|
|
226
|
+
|
|
227
|
+
- `event.from` - 发件人地址
|
|
228
|
+
- `event.subject` - 邮件主题
|
|
229
|
+
- `event.text` - 邮件正文(纯文本)
|
|
230
|
+
- `event.body` - 邮件正文(可能含 HTML)
|
|
231
|
+
- `event.messageId` - 邮件消息 ID
|
|
232
|
+
|
|
233
|
+
### 2. 多步骤引用 `${actionId.output.field}`
|
|
234
|
+
|
|
235
|
+
当有多个顺序执行的 action 时,后续 action 可以引用前一个 action 的输出:
|
|
236
|
+
|
|
237
|
+
```javascript
|
|
238
|
+
actions: [
|
|
239
|
+
{
|
|
240
|
+
id: 'read-email',
|
|
241
|
+
type: 'tool',
|
|
242
|
+
name: 'email_read',
|
|
243
|
+
args: { limit: 1, unreadOnly: true },
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
id: 'process',
|
|
247
|
+
type: 'tool',
|
|
248
|
+
name: 'some_processor',
|
|
249
|
+
args: {
|
|
250
|
+
// 引用 read-email 输出的 emails 数组的第一个元素的 from 字段
|
|
251
|
+
sender: '${read-email.output.emails[0].from}',
|
|
252
|
+
},
|
|
253
|
+
},
|
|
254
|
+
];
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### 3. 变量解析规则
|
|
258
|
+
|
|
259
|
+
`${}` 语法支持嵌套属性访问:
|
|
260
|
+
|
|
261
|
+
- `${event.from}` - 直接字段
|
|
262
|
+
- `${actionId.output.field}` - 嵌套字段
|
|
263
|
+
- `${event.data.xxx}` - data 对象内的字段(兼容性别名)
|
|
264
|
+
|
|
265
|
+
## 创建目标的最佳实践
|
|
266
|
+
|
|
267
|
+
1. **明确目标标题** - 让用户清楚知道目标意图
|
|
268
|
+
2. **设置合适优先级** - 高优先级目标会被优先处理
|
|
269
|
+
3. **操作要原子化** - 每个 action 只做一件事
|
|
270
|
+
4. **选择合适的持久化模式** - 需要持续监控用 `persistent: true`,一次性任务用 `persistent: false`
|
|
271
|
+
5. **检查循环** - 同一 action 连续失败 3 次会判定为循环
|
|
272
|
+
|
|
273
|
+
## 示例:创建邮件自动回复目标
|
|
274
|
+
|
|
275
|
+
`email:received` 事件的数据结构:
|
|
276
|
+
|
|
277
|
+
- `event.from` - 发件人地址
|
|
278
|
+
- `event.subject` - 邮件主题
|
|
279
|
+
- `event.text` - 邮件正文(纯文本)
|
|
280
|
+
- `event.body` - 邮件正文(与 text 相同)
|
|
281
|
+
- `event.messageId` - 邮件消息 ID
|
|
282
|
+
- `event.uid` - 邮件 UID(数字)
|
|
283
|
+
|
|
284
|
+
```javascript
|
|
285
|
+
await ambient_goals({
|
|
286
|
+
action: 'create',
|
|
287
|
+
title: '邮件自动回复',
|
|
288
|
+
description: '收到邮件后自动回复发件人',
|
|
289
|
+
priority: 8,
|
|
290
|
+
persistent: false, // 一次性任务,回复完成后不再等待新邮件
|
|
291
|
+
actions: [
|
|
292
|
+
{
|
|
293
|
+
id: 'auto-reply',
|
|
294
|
+
type: 'tool',
|
|
295
|
+
name: 'email_auto_reply',
|
|
296
|
+
args: {
|
|
297
|
+
to: '${event.from}',
|
|
298
|
+
subject: '${event.subject}',
|
|
299
|
+
body: '${event.text}',
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
],
|
|
303
|
+
conditions: {
|
|
304
|
+
events: ['email:received'],
|
|
305
|
+
},
|
|
306
|
+
});
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
**错误示例**(缺少参数):
|
|
310
|
+
|
|
311
|
+
```javascript
|
|
312
|
+
// ❌ 错误 - 没有传递必需参数
|
|
313
|
+
{ type: 'tool', name: 'email_auto_reply', args: {} }
|
|
314
|
+
|
|
315
|
+
// ✅ 正确 - 从事件中提取参数
|
|
316
|
+
{ type: 'tool', name: 'email_auto_reply', args: {
|
|
317
|
+
to: '${event.from}',
|
|
318
|
+
subject: '${event.subject}',
|
|
319
|
+
body: '${event.text}',
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
**注意**:`email_auto_reply` 需要 `to`、`subject`、`body` 三个必需参数,必须从 `${event.xxx}` 提取。由于 `email:received` 事件已携带邮件数据,不需要额外的 `email_read` 步骤来读取邮件。
|
|
325
|
+
|
|
326
|
+
## 生命周期
|
|
327
|
+
|
|
328
|
+
```
|
|
329
|
+
Goal 创建 → [条件满足] → ACTIVE → 执行 actions → COMPLETED/FAILED
|
|
330
|
+
↑ ↓
|
|
331
|
+
└────── 重新激活 ← ─────────────┘(仅 persistent=true)
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
- **pending** - 待激活,满足条件后自动变为 active
|
|
335
|
+
- **active** - 执行中,循环处理 actions
|
|
336
|
+
- **completed** - 所有 actions 执行完毕(一次性任务执行完后直接完成)
|
|
337
|
+
- **failed** - 达到最大尝试次数或检测到循环
|
|
338
|
+
|
|
339
|
+
**persistent 行为**:
|
|
340
|
+
|
|
341
|
+
- `persistent: true`(默认)- 事件驱动目标,actions 执行完后等待下一事件再次执行
|
|
342
|
+
- `persistent: false` - 一次性目标,所有 actions 执行完后直接完成,不等待新事件
|