myagent-ai 1.24.6 → 1.25.1
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/package.json +1 -1
- package/skills/admin-manager/SKILL.md +560 -0
- package/skills/system_skill.py +6 -2
- package/web/api_server.py +85 -26
package/package.json
CHANGED
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: admin-manager
|
|
3
|
+
description: |
|
|
4
|
+
后台管理技能 — 赋能 AI 助手通过 API 完成所有后台管理操作,包括大模型管理、Agent 管理、组织架构管理、部门管理等。
|
|
5
|
+
适用于配置助手和管理场景,让 AI 可以直接帮用户管理整个 MyAgent 系统。
|
|
6
|
+
metadata:
|
|
7
|
+
category: admin
|
|
8
|
+
version: "1.0.0"
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# 后台管理技能 (Admin Manager)
|
|
12
|
+
|
|
13
|
+
你拥有完整的后台管理权限,可以通过调用 MyAgent 的 RESTful API 来管理整个系统。
|
|
14
|
+
以下是你可用的所有管理操作指南。
|
|
15
|
+
|
|
16
|
+
## 重要规则
|
|
17
|
+
|
|
18
|
+
- **所有管理操作必须通过 API 完成**,禁止直接修改数据库文件或配置文件。
|
|
19
|
+
- 操作前应先通过 GET 请求了解当前状态,确认操作安全后再执行修改。
|
|
20
|
+
- 对于删除操作,务必先确认用户意图,避免误删。
|
|
21
|
+
- 所有 API 的基础 URL 为 `http://localhost:8767`(即当前服务地址),以下省略前缀。
|
|
22
|
+
- 调用 API 使用 `requests` 库或 `httpx` 库,推荐使用 `requests`。
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 一、大模型管理 (Model Management)
|
|
27
|
+
|
|
28
|
+
模型库管理支持添加、编辑、删除、测试大模型配置。每个模型可以独立配置 provider、API Key、base URL 等参数。
|
|
29
|
+
|
|
30
|
+
### 1.1 列出所有模型
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
GET /api/models
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
返回模型列表,每个模型包含: `id`, `name`, `provider`, `api_type`, `model`, `base_url`, `api_key`, `max_tokens`, `temperature`, `context_window`, `input_modes`, `reasoning`, `enabled`, `is_global_fallback`。
|
|
37
|
+
|
|
38
|
+
### 1.2 添加模型
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
POST /api/models
|
|
42
|
+
Content-Type: application/json
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
"id": "my-gpt4o", // 唯一标识符,必填
|
|
46
|
+
"name": "我的 GPT-4o", // 显示名称
|
|
47
|
+
"provider": "openai", // openai | anthropic | ollama | zhipu | deepseek | moonshot | qwen | modelscope | custom
|
|
48
|
+
"api_type": "openai-completions", // openai-completions | openai-chat | anthropic | ollama | custom
|
|
49
|
+
"model": "gpt-4o", // API 调用使用的实际模型字符串
|
|
50
|
+
"base_url": "https://api.openai.com/v1", // 自定义 API 地址
|
|
51
|
+
"api_key": "sk-...", // 专用 API Key(留空则使用全局默认)
|
|
52
|
+
"max_tokens": 4096,
|
|
53
|
+
"temperature": 0.1,
|
|
54
|
+
"context_window": 128000, // 上下文窗口大小
|
|
55
|
+
"input_modes": ["text", "image"], // 支持的输入模式: text, image, video, audio
|
|
56
|
+
"reasoning": false, // 是否支持推理(如 o1 系列)
|
|
57
|
+
"enabled": true, // 是否启用
|
|
58
|
+
"is_global_fallback": true // 是否作为全局兜底模型
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 1.3 更新模型
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
PUT /api/models/{model_id}
|
|
66
|
+
Content-Type: application/json
|
|
67
|
+
|
|
68
|
+
{ 同添加模型的字段,只需传要修改的字段 }
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### 1.4 删除模型
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
DELETE /api/models/{model_id}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### 1.5 测试模型连接
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
POST /api/llm/test
|
|
81
|
+
Content-Type: application/json
|
|
82
|
+
|
|
83
|
+
{
|
|
84
|
+
"model": "gpt-4o",
|
|
85
|
+
"base_url": "https://api.openai.com/v1",
|
|
86
|
+
"provider": "openai",
|
|
87
|
+
"temperature": 0.1,
|
|
88
|
+
"api_key": "sk-...",
|
|
89
|
+
"input_modes": ["text", "image"]
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### 常用 Provider 配置参考
|
|
94
|
+
|
|
95
|
+
| Provider | base_url | 说明 |
|
|
96
|
+
|----------|----------|------|
|
|
97
|
+
| openai | https://api.openai.com/v1 | OpenAI 官方 |
|
|
98
|
+
| custom (ModelScope) | https://api-inference.modelscope.cn/v1 | 阿里 ModelScope(推荐免费额度大)|
|
|
99
|
+
| custom (DeepSeek) | https://api.deepseek.com/v1 | DeepSeek |
|
|
100
|
+
| custom (Moonshot) | https://api.moonshot.cn/v1 | Kimi/Moonshot |
|
|
101
|
+
| zhipu | https://open.bigmodel.cn/api/paas/v4 | 智谱 GLM |
|
|
102
|
+
| ollama | http://localhost:11434 | 本地 Ollama |
|
|
103
|
+
| anthropic | - | Anthropic Claude |
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 二、Agent 管理 (Agent Management)
|
|
108
|
+
|
|
109
|
+
Agent 是 MyAgent 的核心概念,每个 Agent 拥有独立的人格、知识库、会话历史和权限配置。
|
|
110
|
+
|
|
111
|
+
### 2.1 列出所有 Agent
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
GET /api/agents
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
返回所有 Agent 的扁平列表,包含: `path`, `id`, `name`, `description`, `avatar_color`, `avatar_emoji`, `avatar_image`, `execution_mode`, `enabled`, `system`, `system_prompt`, `model`, `model_id`, `backup_model_ids`, `parent`, `platform`, `department`, `work_dir`, `created_at`, `updated_at`, `session_count`。
|
|
118
|
+
|
|
119
|
+
### 2.2 获取单个 Agent 详情
|
|
120
|
+
|
|
121
|
+
```
|
|
122
|
+
GET /api/agents/{agent_path}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
除了基本信息外,还返回 `soul`, `identity`, `user` 等人格文件内容。
|
|
126
|
+
|
|
127
|
+
### 2.3 创建 Agent
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
POST /api/agents
|
|
131
|
+
Content-Type: application/json
|
|
132
|
+
|
|
133
|
+
{
|
|
134
|
+
"name": "翻译助手", // 名称,必填
|
|
135
|
+
"description": "专业翻译AI助手", // 描述
|
|
136
|
+
"avatar_emoji": "🌐", // 头像 emoji
|
|
137
|
+
"avatar_color": "#4f46e5", // 头像颜色
|
|
138
|
+
"execution_mode": "sandbox", // sandbox(沙盒) | local(本机)
|
|
139
|
+
"model_id": "gpt-4o", // 绑定的模型 ID(留空用全局默认)
|
|
140
|
+
"backup_model_ids": ["claude-3.5-sonnet"], // 备用模型列表
|
|
141
|
+
"system_prompt": "你是一个专业翻译助手...", // 系统提示词
|
|
142
|
+
"work_dir": "", // 自定义工作目录
|
|
143
|
+
"department": "技术部" // 所属部门路径
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 2.4 更新 Agent
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
PUT /api/agents/{agent_path}
|
|
151
|
+
Content-Type: application/json
|
|
152
|
+
|
|
153
|
+
{ 只需传要修改的字段,支持: name, description, avatar_emoji, avatar_color, avatar_image,
|
|
154
|
+
model_id, backup_model_ids, work_dir, system_prompt, execution_mode, enabled, department }
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 2.5 删除 Agent
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
DELETE /api/agents/{agent_path}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**注意**: 删除会同时清理工作目录、会话历史、记忆数据和所有子 Agent,不可撤销!
|
|
164
|
+
|
|
165
|
+
### 2.6 创建子 Agent
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
POST /api/agents/{parent_path}/children
|
|
169
|
+
Content-Type: application/json
|
|
170
|
+
|
|
171
|
+
{
|
|
172
|
+
"name": "子助手名称",
|
|
173
|
+
"description": "子助手描述",
|
|
174
|
+
"system_prompt": "子助手系统提示词"
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 2.7 管理 Agent 人格
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
# 获取 soul.md
|
|
182
|
+
GET /api/agents/{agent_path}/soul
|
|
183
|
+
|
|
184
|
+
# 设置 soul.md
|
|
185
|
+
PUT /api/agents/{agent_path}/soul
|
|
186
|
+
Content-Type: application/json
|
|
187
|
+
{ "soul": "# Agent名称\n\n## 性格\n..." }
|
|
188
|
+
|
|
189
|
+
# 获取 identity.md
|
|
190
|
+
GET /api/agents/{agent_path}/identity
|
|
191
|
+
|
|
192
|
+
# 设置 identity.md
|
|
193
|
+
PUT /api/agents/{agent_path}/identity
|
|
194
|
+
Content-Type: application/json
|
|
195
|
+
{ "identity": "# 身份\n..." }
|
|
196
|
+
|
|
197
|
+
# 获取 user.md
|
|
198
|
+
GET /api/agents/{agent_path}/user
|
|
199
|
+
|
|
200
|
+
# 设置 user.md
|
|
201
|
+
PUT /api/agents/{agent_path}/user
|
|
202
|
+
Content-Type: application/json
|
|
203
|
+
{ "user": "# 用户信息\n..." }
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### 2.8 管理 Agent 知识库
|
|
207
|
+
|
|
208
|
+
```
|
|
209
|
+
# 列出知识库文件
|
|
210
|
+
GET /api/agents/{agent_path}/knowledge
|
|
211
|
+
|
|
212
|
+
# 读取知识库文件
|
|
213
|
+
GET /api/agents/{agent_path}/knowledge/file?path=xxx.md
|
|
214
|
+
|
|
215
|
+
# 上传知识库文件
|
|
216
|
+
POST /api/agents/{agent_path}/knowledge/upload
|
|
217
|
+
Content-Type: multipart/form-data (files 字段)
|
|
218
|
+
|
|
219
|
+
# 删除知识库文件
|
|
220
|
+
DELETE /api/agents/{agent_path}/knowledge?path=xxx.md
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### 2.9 查看 Agent 会话
|
|
224
|
+
|
|
225
|
+
```
|
|
226
|
+
# 列出 Agent 的所有会话
|
|
227
|
+
GET /api/agents/{agent_path}/sessions
|
|
228
|
+
|
|
229
|
+
# 查看会话消息
|
|
230
|
+
GET /api/sessions/{session_id}/messages?limit=100
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
### 2.10 查看 Agent 权限
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
# 获取 Agent 权限
|
|
237
|
+
GET /api/permissions/{agent_path}
|
|
238
|
+
|
|
239
|
+
# 设置 Agent 权限
|
|
240
|
+
PUT /api/permissions/{agent_path}
|
|
241
|
+
Content-Type: application/json
|
|
242
|
+
{ "command": true, "web_control": false, ... }
|
|
243
|
+
|
|
244
|
+
# 重置为默认权限
|
|
245
|
+
DELETE /api/permissions/{agent_path}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## 三、组织管理 (Organization Management)
|
|
251
|
+
|
|
252
|
+
### 3.1 获取/更新组织配置
|
|
253
|
+
|
|
254
|
+
```
|
|
255
|
+
# 获取组织配置
|
|
256
|
+
GET /api/organization
|
|
257
|
+
|
|
258
|
+
# 更新组织配置
|
|
259
|
+
PUT /api/organization
|
|
260
|
+
Content-Type: application/json
|
|
261
|
+
{ "enabled": true, "knowledge_admin": "manager" }
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
### 3.2 获取/更新组织信息
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
# 获取组织信息
|
|
268
|
+
GET /api/organization/info
|
|
269
|
+
|
|
270
|
+
# 更新组织信息
|
|
271
|
+
PUT /api/organization/info
|
|
272
|
+
Content-Type: application/json
|
|
273
|
+
{ "name": "我的公司", "description": "...", "contact": "...", "website": "..." }
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### 3.3 管理组织知识库
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
# 列出知识库文件
|
|
280
|
+
GET /api/organization/knowledge
|
|
281
|
+
|
|
282
|
+
# 读取知识库文件
|
|
283
|
+
GET /api/organization/knowledge/file?path=xxx.md
|
|
284
|
+
|
|
285
|
+
# 上传知识库文件
|
|
286
|
+
POST /api/organization/knowledge/upload
|
|
287
|
+
Content-Type: multipart/form-data
|
|
288
|
+
|
|
289
|
+
# 删除知识库文件
|
|
290
|
+
DELETE /api/organization/knowledge?path=xxx.md
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## 四、部门管理 (Department Management)
|
|
296
|
+
|
|
297
|
+
部门支持无限层级嵌套,每个部门可以有成员(Agent)、负责人、知识库和自动创建的群聊。
|
|
298
|
+
|
|
299
|
+
### 4.1 获取部门树
|
|
300
|
+
|
|
301
|
+
```
|
|
302
|
+
GET /api/departments
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
返回树形结构,每个部门节点包含: `path`, `name`, `emoji`, `description`, `head`, `agents`, `agent_count`, `chat_group_id`, `children`。
|
|
306
|
+
|
|
307
|
+
### 4.2 创建部门
|
|
308
|
+
|
|
309
|
+
```
|
|
310
|
+
POST /api/departments
|
|
311
|
+
Content-Type: application/json
|
|
312
|
+
|
|
313
|
+
{
|
|
314
|
+
"name": "技术部", // 部门名称,必填
|
|
315
|
+
"emoji": "💻", // 部门 emoji
|
|
316
|
+
"description": "负责技术研发", // 描述
|
|
317
|
+
"parent": "" // 父部门路径(空字符串=顶级部门)
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### 4.3 获取部门详情
|
|
322
|
+
|
|
323
|
+
```
|
|
324
|
+
GET /api/departments/{dept_path}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### 4.4 更新部门基本信息
|
|
328
|
+
|
|
329
|
+
```
|
|
330
|
+
PUT /api/departments/{dept_path}
|
|
331
|
+
Content-Type: application/json
|
|
332
|
+
{ "name": "新名称", "emoji": "🚀" }
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### 4.5 更新部门详细信息(描述、负责人等)
|
|
336
|
+
|
|
337
|
+
```
|
|
338
|
+
PUT /api/departments/{dept_path}/info
|
|
339
|
+
Content-Type: application/json
|
|
340
|
+
{ "description": "新的部门描述", "head_name": "agent_name" }
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### 4.6 删除部门
|
|
344
|
+
|
|
345
|
+
```
|
|
346
|
+
DELETE /api/departments/{dept_path}
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
**注意**: 会递归删除所有子部门、自动解散关联的群聊,不可撤销!
|
|
350
|
+
|
|
351
|
+
### 4.7 管理部门成员
|
|
352
|
+
|
|
353
|
+
```
|
|
354
|
+
# 添加/移除成员
|
|
355
|
+
PUT /api/departments/{dept_path}/agents
|
|
356
|
+
Content-Type: application/json
|
|
357
|
+
{ "agents": ["coder", "translator"], "action": "add" } // action: add | remove | set
|
|
358
|
+
|
|
359
|
+
# 设置部门负责人
|
|
360
|
+
PUT /api/departments/{dept_path}/head
|
|
361
|
+
Content-Type: application/json
|
|
362
|
+
{ "head": "agent_name" }
|
|
363
|
+
```
|
|
364
|
+
|
|
365
|
+
### 4.8 管理部门知识库
|
|
366
|
+
|
|
367
|
+
```
|
|
368
|
+
# 列出知识库文件
|
|
369
|
+
GET /api/departments/{dept_path}/knowledge
|
|
370
|
+
|
|
371
|
+
# 读取知识库文件
|
|
372
|
+
GET /api/departments/{dept_path}/knowledge/file?path=xxx.md
|
|
373
|
+
|
|
374
|
+
# 上传知识库文件
|
|
375
|
+
POST /api/departments/{dept_path}/knowledge/upload
|
|
376
|
+
Content-Type: multipart/form-data
|
|
377
|
+
|
|
378
|
+
# 删除知识库文件
|
|
379
|
+
DELETE /api/departments/{dept_path}/knowledge?path=xxx.md
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
---
|
|
383
|
+
|
|
384
|
+
## 五、群聊管理 (Group Chat Management)
|
|
385
|
+
|
|
386
|
+
### 5.1 列出所有群聊
|
|
387
|
+
|
|
388
|
+
```
|
|
389
|
+
GET /api/groups
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
### 5.2 创建群聊
|
|
393
|
+
|
|
394
|
+
```
|
|
395
|
+
POST /api/groups
|
|
396
|
+
Content-Type: application/json
|
|
397
|
+
{
|
|
398
|
+
"name": "群聊名称",
|
|
399
|
+
"description": "群聊描述",
|
|
400
|
+
"avatar_emoji": "👥",
|
|
401
|
+
"owner": "agent_path"
|
|
402
|
+
}
|
|
403
|
+
```
|
|
404
|
+
|
|
405
|
+
### 5.3 群成员管理
|
|
406
|
+
|
|
407
|
+
```
|
|
408
|
+
# 添加成员
|
|
409
|
+
POST /api/groups/{group_id}/members
|
|
410
|
+
Content-Type: application/json
|
|
411
|
+
{ "agent_path": "agent_name", "role": "member" }
|
|
412
|
+
|
|
413
|
+
# 移除成员
|
|
414
|
+
DELETE /api/groups/{group_id}/members/{agent_path}
|
|
415
|
+
|
|
416
|
+
# 设置成员角色
|
|
417
|
+
PUT /api/groups/{group_id}/members/{agent_path}/role
|
|
418
|
+
Content-Type: application/json
|
|
419
|
+
{ "role": "owner" } // owner | admin | member
|
|
420
|
+
|
|
421
|
+
# 设置成员禁言
|
|
422
|
+
PUT /api/groups/{group_id}/members/{agent_path}/mute
|
|
423
|
+
Content-Type: application/json
|
|
424
|
+
{ "muted": true }
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
---
|
|
428
|
+
|
|
429
|
+
## 六、全局 LLM 配置 (Global LLM Config)
|
|
430
|
+
|
|
431
|
+
### 6.1 获取当前 LLM 配置
|
|
432
|
+
|
|
433
|
+
```
|
|
434
|
+
GET /api/llm
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### 6.2 更新全局 LLM 配置
|
|
438
|
+
|
|
439
|
+
```
|
|
440
|
+
PUT /api/llm
|
|
441
|
+
Content-Type: application/json
|
|
442
|
+
{
|
|
443
|
+
"provider": "openai",
|
|
444
|
+
"api_key": "sk-...",
|
|
445
|
+
"base_url": "https://api.openai.com/v1",
|
|
446
|
+
"model": "gpt-4o",
|
|
447
|
+
"temperature": 0.1,
|
|
448
|
+
"max_tokens": 4096,
|
|
449
|
+
"context_window": 128000
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
### 6.3 获取用量统计
|
|
454
|
+
|
|
455
|
+
```
|
|
456
|
+
GET /api/llm/usage
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
---
|
|
460
|
+
|
|
461
|
+
## 七、权限管理 (Permissions)
|
|
462
|
+
|
|
463
|
+
### 7.1 获取全局权限配置
|
|
464
|
+
|
|
465
|
+
```
|
|
466
|
+
GET /api/permissions
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
### 7.2 设置全局默认权限
|
|
470
|
+
|
|
471
|
+
```
|
|
472
|
+
PUT /api/permissions/defaults
|
|
473
|
+
Content-Type: application/json
|
|
474
|
+
{ "command": true, "web_control": false, ... }
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
---
|
|
478
|
+
|
|
479
|
+
## 八、配置导入导出 (Config Import/Export)
|
|
480
|
+
|
|
481
|
+
### 8.1 导出配置
|
|
482
|
+
|
|
483
|
+
```
|
|
484
|
+
POST /api/config/export
|
|
485
|
+
Content-Type: application/json
|
|
486
|
+
{ "include_secrets": false } // 是否包含 API Key 等敏感信息
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
### 8.2 导入配置
|
|
490
|
+
|
|
491
|
+
```
|
|
492
|
+
POST /api/config/import
|
|
493
|
+
Content-Type: application/json
|
|
494
|
+
{ ...config_data..., "overwrite": false } // false=合并, true=完全覆盖
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
### 8.3 热重载配置
|
|
498
|
+
|
|
499
|
+
```
|
|
500
|
+
POST /api/config/reload
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
---
|
|
504
|
+
|
|
505
|
+
## 九、记忆管理 (Memory)
|
|
506
|
+
|
|
507
|
+
### 9.1 搜索记忆
|
|
508
|
+
|
|
509
|
+
```
|
|
510
|
+
GET /api/memory/search?keyword=xxx&limit=20
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
### 9.2 获取记忆统计
|
|
514
|
+
|
|
515
|
+
```
|
|
516
|
+
GET /api/memory/stats
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### 9.3 清理过期记忆
|
|
520
|
+
|
|
521
|
+
```
|
|
522
|
+
POST /api/memory/cleanup
|
|
523
|
+
```
|
|
524
|
+
|
|
525
|
+
---
|
|
526
|
+
|
|
527
|
+
## 十、典型管理场景
|
|
528
|
+
|
|
529
|
+
### 场景1: 首次配置 LLM
|
|
530
|
+
|
|
531
|
+
1. 推荐使用 ModelScope 免费 API:
|
|
532
|
+
- provider: `custom`
|
|
533
|
+
- base_url: `https://api-inference.modelscope.cn/v1`
|
|
534
|
+
- 推荐模型: `stepfun-ai/Step-3.5-Flash`
|
|
535
|
+
2. 添加模型到模型库: `POST /api/models`
|
|
536
|
+
3. 设置为全局默认: `PUT /api/llm`
|
|
537
|
+
4. 测试连接: `POST /api/llm/test`
|
|
538
|
+
|
|
539
|
+
### 场景2: 创建多 Agent 团队
|
|
540
|
+
|
|
541
|
+
1. 创建部门: `POST /api/departments` (如 "技术部"、"市场部")
|
|
542
|
+
2. 创建多个 Agent: `POST /api/agents` (如 "代码专家"、"翻译助手")
|
|
543
|
+
3. 分配 Agent 到部门: `PUT /api/departments/{path}/agents`
|
|
544
|
+
4. 设置部门负责人: `PUT /api/departments/{path}/head`
|
|
545
|
+
5. 为每个 Agent 配置独立的人格和知识库
|
|
546
|
+
|
|
547
|
+
### 场景3: Agent 个性化配置
|
|
548
|
+
|
|
549
|
+
1. 创建 Agent 并设置 system_prompt
|
|
550
|
+
2. 通过 soul.md 定义 Agent 的性格特征
|
|
551
|
+
3. 通过 identity.md 定义 Agent 的身份背景
|
|
552
|
+
4. 上传专业知识到知识库
|
|
553
|
+
5. 绑定专用模型以获得最佳效果
|
|
554
|
+
|
|
555
|
+
### 场景4: 模型切换与故障转移
|
|
556
|
+
|
|
557
|
+
1. 在模型库中添加多个模型
|
|
558
|
+
2. 为关键 Agent 设置 model_id 和 backup_model_ids
|
|
559
|
+
3. 设置 is_global_fallback 标记兜底模型
|
|
560
|
+
4. 当主模型不可用时,系统自动切换到备用模型
|
package/skills/system_skill.py
CHANGED
|
@@ -209,8 +209,12 @@ class EnvironmentGetSkill(Skill):
|
|
|
209
209
|
if key:
|
|
210
210
|
value = os.environ.get(key)
|
|
211
211
|
if value is None:
|
|
212
|
-
return SkillResult(
|
|
213
|
-
|
|
212
|
+
return SkillResult(
|
|
213
|
+
success=True,
|
|
214
|
+
data={"key": key, "value": None, "exists": False},
|
|
215
|
+
message=f"环境变量 {key} 不存在(当前进程未设置)",
|
|
216
|
+
)
|
|
217
|
+
return SkillResult(success=True, data={"key": key, "value": value, "exists": True})
|
|
214
218
|
else:
|
|
215
219
|
# 返回所有(过滤敏感信息)
|
|
216
220
|
sensitive = {"PASSWORD", "SECRET", "TOKEN", "KEY", "CREDENTIAL", "API_KEY"}
|
package/web/api_server.py
CHANGED
|
@@ -146,13 +146,72 @@ async def _read_multipart_files(request):
|
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
|
|
149
|
-
CONFIG_HELPER_PROMPT = """你是 MyAgent
|
|
149
|
+
CONFIG_HELPER_PROMPT = """你是 MyAgent 的智能配置助手,拥有完整的后台管理权限。你的名字叫"配置助手"。
|
|
150
150
|
|
|
151
151
|
## 你的核心职责
|
|
152
|
-
1.
|
|
153
|
-
2.
|
|
154
|
-
3.
|
|
155
|
-
4.
|
|
152
|
+
1. **后台管理**:通过 API 直接管理大模型、Agent、组织、部门、群聊等所有系统资源
|
|
153
|
+
2. **引导新用户**:首次使用时,友好地介绍 MyAgent 的功能,帮助用户完成初始配置
|
|
154
|
+
3. **配置管理**:帮助用户修改配置(LLM模型、执行引擎、权限等)
|
|
155
|
+
4. **Agent 管理**:创建、编辑、删除 Agent,配置人格、知识库、权限等
|
|
156
|
+
5. **组织架构**:管理部门体系,分配成员,维护组织知识库
|
|
157
|
+
6. **问题解答**:回答用户关于 MyAgent 使用的问题
|
|
158
|
+
|
|
159
|
+
## 管理权限
|
|
160
|
+
你拥有完整的后台管理权限,可以直接通过调用本地 API 来管理整个系统。
|
|
161
|
+
所有 API 基础地址: `http://localhost:8767`
|
|
162
|
+
调用方式: 使用 Python `requests` 库发起 HTTP 请求。
|
|
163
|
+
|
|
164
|
+
## 后台管理 API 速查
|
|
165
|
+
|
|
166
|
+
### 大模型管理
|
|
167
|
+
- **列出模型**: `GET /api/models`
|
|
168
|
+
- **添加模型**: `POST /api/models` — 参数: `id`(必填), `name`, `provider`(openai/anthropic/ollama/zhipu/deepseek/moonshot/qwen/modelscope/custom), `api_type`, `model`, `base_url`, `api_key`, `max_tokens`, `temperature`, `context_window`, `input_modes`(["text","image","video","audio"]), `reasoning`, `enabled`, `is_global_fallback`
|
|
169
|
+
- **更新模型**: `PUT /api/models/{model_id}` — 同上字段,只需传修改项
|
|
170
|
+
- **删除模型**: `DELETE /api/models/{model_id}`
|
|
171
|
+
- **测试模型**: `POST /api/llm/test` — 参数: `model`, `base_url`, `provider`, `api_key`, `input_modes`
|
|
172
|
+
- **全局LLM配置**: `GET/PUT /api/llm` — 设置全局默认模型
|
|
173
|
+
- **用量统计**: `GET /api/llm/usage`
|
|
174
|
+
|
|
175
|
+
### Agent 管理
|
|
176
|
+
- **列出Agent**: `GET /api/agents`
|
|
177
|
+
- **创建Agent**: `POST /api/agents` — 参数: `name`(必填), `description`, `avatar_emoji`, `avatar_color`, `execution_mode`(sandbox/local), `model_id`, `backup_model_ids`, `system_prompt`, `work_dir`, `department`
|
|
178
|
+
- **获取Agent**: `GET /api/agents/{path}`
|
|
179
|
+
- **更新Agent**: `PUT /api/agents/{path}` — 支持所有创建字段及 `enabled`
|
|
180
|
+
- **删除Agent**: `DELETE /api/agents/{path}` — 会同时删除子Agent、会话、工作目录,不可撤销!
|
|
181
|
+
- **创建子Agent**: `POST /api/agents/{parent}/children`
|
|
182
|
+
- **Agent人格**: `GET/PUT /api/agents/{path}/soul`, `identity`, `user`
|
|
183
|
+
- **Agent知识库**: `GET /api/agents/{path}/knowledge`, `POST .../knowledge/upload`, `DELETE .../knowledge?path=`
|
|
184
|
+
- **Agent会话**: `GET /api/agents/{path}/sessions`
|
|
185
|
+
- **Agent权限**: `GET/PUT/DELETE /api/permissions/{path}`
|
|
186
|
+
|
|
187
|
+
### 组织管理
|
|
188
|
+
- **组织配置**: `GET/PUT /api/organization` — `enabled`, `knowledge_admin`
|
|
189
|
+
- **组织信息**: `GET/PUT /api/organization/info` — `name`, `description`, `contact`, `website`
|
|
190
|
+
- **组织知识库**: `GET /api/organization/knowledge`, `POST .../knowledge/upload`, `DELETE .../knowledge?path=`
|
|
191
|
+
|
|
192
|
+
### 部门管理
|
|
193
|
+
- **部门树**: `GET /api/departments`
|
|
194
|
+
- **创建部门**: `POST /api/departments` — 参数: `name`(必填), `emoji`, `description`, `parent`
|
|
195
|
+
- **部门详情**: `GET /api/departments/{path}`
|
|
196
|
+
- **更新部门**: `PUT /api/departments/{path}` — `name`, `emoji`
|
|
197
|
+
- **更新部门详情**: `PUT /api/departments/{path}/info` — `description`, `head_name`
|
|
198
|
+
- **删除部门**: `DELETE /api/departments/{path}` — 递归删除子部门和群聊,不可撤销!
|
|
199
|
+
- **部门成员**: `PUT /api/departments/{path}/agents` — `agents`(list), `action`(add/remove/set)
|
|
200
|
+
- **部门负责人**: `PUT /api/departments/{path}/head` — `head`(agent_name)
|
|
201
|
+
- **部门知识库**: `GET /api/departments/{path}/knowledge`, `POST .../knowledge/upload`, `DELETE .../knowledge?path=`
|
|
202
|
+
|
|
203
|
+
### 群聊管理
|
|
204
|
+
- **列出群聊**: `GET /api/groups`
|
|
205
|
+
- **创建群聊**: `POST /api/groups` — `name`, `description`, `avatar_emoji`, `owner`
|
|
206
|
+
- **群成员管理**: `POST/DELETE /api/groups/{gid}/members/{agent_path}`
|
|
207
|
+
- **成员角色**: `PUT /api/groups/{gid}/members/{agent_path}/role`
|
|
208
|
+
- **成员禁言**: `PUT /api/groups/{gid}/members/{agent_path}/mute`
|
|
209
|
+
|
|
210
|
+
### 系统配置
|
|
211
|
+
- **完整配置**: `GET /api/config`
|
|
212
|
+
- **热重载**: `POST /api/config/reload`
|
|
213
|
+
- **导出配置**: `POST /api/config/export` — `include_secrets`
|
|
214
|
+
- **导入配置**: `POST /api/config/import` — `overwrite`
|
|
156
215
|
|
|
157
216
|
## 工作方式
|
|
158
217
|
|
|
@@ -165,31 +224,30 @@ CONFIG_HELPER_PROMPT = """你是 MyAgent 的智能配置助手,专门帮助用
|
|
|
165
224
|
- provider: custom
|
|
166
225
|
- base_url: https://api-inference.modelscope.cn/v1
|
|
167
226
|
- 推荐模型:stepfun-ai/Step-3.5-Flash
|
|
168
|
-
- 也支持 OpenAI、Anthropic、Ollama(本地)、智谱GLM 等
|
|
227
|
+
- 也支持 OpenAI、Anthropic、Ollama(本地)、智谱GLM、DeepSeek、Moonshot 等
|
|
169
228
|
4. 配置完成后,建议用户先从单个 Agent 开始使用
|
|
170
229
|
5. 介绍核心功能:代码执行、文件操作、网络搜索、技能系统
|
|
171
230
|
|
|
172
|
-
###
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
231
|
+
### 日常管理
|
|
232
|
+
当用户要求管理操作时,你应该:
|
|
233
|
+
1. 先通过 GET 请求了解当前状态
|
|
234
|
+
2. 确认用户意图后,通过 POST/PUT/DELETE 执行操作
|
|
235
|
+
3. 操作完成后,向用户确认结果
|
|
236
|
+
|
|
237
|
+
### 典型场景
|
|
238
|
+
- **用户说"帮我添加一个模型"**: 调用 `POST /api/models` 添加,然后 `POST /api/llm/test` 测试
|
|
239
|
+
- **用户说"创建一个翻译助手"**: 调用 `POST /api/agents` 创建,配置 system_prompt 和 model_id
|
|
240
|
+
- **用户说"建一个技术部"**: 调用 `POST /api/departments` 创建部门
|
|
241
|
+
- **用户说"把翻译助手加到技术部"**: 调用 `PUT /api/departments/{path}/agents` 分配成员
|
|
176
242
|
|
|
177
243
|
## 重要规则
|
|
178
|
-
-
|
|
179
|
-
-
|
|
180
|
-
-
|
|
181
|
-
-
|
|
182
|
-
-
|
|
244
|
+
- **必须通过 API 操作**:所有管理操作必须通过 HTTP API 完成,禁止直接修改数据库文件或配置文件。
|
|
245
|
+
- **禁止编写代码创建 Agent/部门**:禁止通过编写 `.py` 文件或修改 `__init__.py` 来尝试在源码层级创建。
|
|
246
|
+
- **配置优先原则**:MyAgent 是配置驱动的。创建 Agent 用 `POST /api/agents`,创建部门用 `POST /api/departments`。
|
|
247
|
+
- **删除前确认**:删除 Agent 和部门是不可逆操作,执行前务必确认用户意图。
|
|
248
|
+
- **操作前先查询**:修改前先 GET 了解当前状态,避免误操作。
|
|
183
249
|
- 使用中文回复,保持简洁友好。
|
|
184
250
|
|
|
185
|
-
## 组织与 Agent 管理 API 指南
|
|
186
|
-
当你需要帮助用户管理组织结构时,请优先使用以下 API(通过 `requests` 或 `http` 调用):
|
|
187
|
-
- **创建 Agent**: `POST /api/agents` (参数: `name`, `description`, `system_prompt`, `model_id`)
|
|
188
|
-
- **创建子 Agent**: `POST /api/agents/{parent}/children` (参数: `name`, `description`, `system_prompt`)
|
|
189
|
-
- **创建部门**: `POST /api/departments` (参数: `name`, `parent`)
|
|
190
|
-
- **配置 Agent 灵魂/身份**: `PUT /api/agents/{name}/soul` 和 `PUT /api/agents/{name}/identity`
|
|
191
|
-
- **分配 Agent 到部门**: `PUT /api/departments/{path}/agents` (参数: `agents`: list of names)
|
|
192
|
-
|
|
193
251
|
## 知识库
|
|
194
252
|
你内置了 MyAgent 完整的配置使用说明文档。当用户询问时不确定的功能时,必须先参考知识库。
|
|
195
253
|
"""
|
|
@@ -4190,7 +4248,8 @@ window.addEventListener('beforeunload', function() {{
|
|
|
4190
4248
|
# [v1.24.1] 兼容两种会话 ID 格式:
|
|
4191
4249
|
# 旧格式: {agent}_web_{timestamp} → session_id LIKE 'default_%'
|
|
4192
4250
|
# 新格式: sess_{uuid} → 通过用户消息 metadata 中的 agent_path 关联
|
|
4193
|
-
|
|
4251
|
+
# [v1.24.6] 修复: json.dumps 默认在冒号后加空格 (": "),LIKE 模式需匹配
|
|
4252
|
+
metadata_agent_pattern = '%"agent_path": "' + agent + '"%'
|
|
4194
4253
|
# 先找出属于该 agent 的所有 session_id(子查询),再统计消息数
|
|
4195
4254
|
rows = conn.execute(
|
|
4196
4255
|
"SELECT m.session_id, COUNT(*) as cnt, MAX(m.created_at) as last FROM memories m "
|
|
@@ -4240,7 +4299,7 @@ window.addEventListener('beforeunload', function() {{
|
|
|
4240
4299
|
if not self.core.memory:
|
|
4241
4300
|
return web.json_response({"agent": name, "sessions": []})
|
|
4242
4301
|
prefix = f"{name}_"
|
|
4243
|
-
metadata_agent_pattern = '%"agent_path":"' + name + '"%'
|
|
4302
|
+
metadata_agent_pattern = '%"agent_path": "' + name + '"%'
|
|
4244
4303
|
conn = self.core.memory._get_conn()
|
|
4245
4304
|
# [v1.24.1] 兼容旧格式 (agent_xxx) 和新格式 (sess_xxx)
|
|
4246
4305
|
rows = conn.execute(
|
|
@@ -8427,7 +8486,7 @@ window.addEventListener('beforeunload', function() {{
|
|
|
8427
8486
|
|
|
8428
8487
|
if agent:
|
|
8429
8488
|
# 按 agent 路径筛选:旧格式 session_id LIKE '{agent}_%' 或新格式 metadata 包含 agent_path
|
|
8430
|
-
metadata_pattern = '%"agent_path":"' + agent + '"%'
|
|
8489
|
+
metadata_pattern = '%"agent_path": "' + agent + '"%'
|
|
8431
8490
|
rows = conn.execute(
|
|
8432
8491
|
"SELECT m.session_id, COUNT(*) as msg_count, MAX(m.created_at) as last_active "
|
|
8433
8492
|
"FROM memories m "
|