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
package/skills/mcp/SKILL.md
CHANGED
|
@@ -1,200 +1,159 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: mcp-usage
|
|
3
3
|
description: How to use MCP (Model Context Protocol) tools. Available tools, calling patterns, and best practices.
|
|
4
|
-
allowed-tools:
|
|
4
|
+
allowed-tools: ext_skill, ext_call, mcp_reload, mcp_list_servers, mcp_set_enabled, Read, Write, Edit, Glob, Grep, execute_command
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# MCP Usage Guide
|
|
8
8
|
|
|
9
|
-
>
|
|
9
|
+
> MCP 工具已统一通过 `ext_call` / `ext_skill` 调用,每个 MCP 服务器自动注册为 `mcp:<servername>` 扩展。
|
|
10
10
|
|
|
11
11
|
---
|
|
12
12
|
|
|
13
|
-
## 1.
|
|
13
|
+
## 1. 核心概念
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
列出所有已连接的 MCP 服务器及其工具。
|
|
15
|
+
每个 MCP 服务器(如 `designmd`、`fetch`)启动后会自动注册为扩展插件 `mcp:<servername>`。
|
|
16
|
+
其原始工具直接挂在该扩展下,**无需 `mcp_call` 中转**。
|
|
18
17
|
|
|
19
18
|
```
|
|
20
|
-
|
|
19
|
+
mcp:<servername>
|
|
20
|
+
├── <tool1>: 描述...
|
|
21
|
+
├── <tool2>: 描述...
|
|
22
|
+
└── <tool3>: 描述...
|
|
21
23
|
```
|
|
22
24
|
|
|
23
|
-
|
|
25
|
+
## 2. 调用模式
|
|
24
26
|
|
|
25
|
-
|
|
26
|
-
{
|
|
27
|
-
"success": true,
|
|
28
|
-
"servers": [{ "name": "fetch", "tools": [{ "name": "fetch", "description": "..." }] }]
|
|
29
|
-
}
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
### mcp_tool_schema
|
|
33
|
-
|
|
34
|
-
查询工具的完整参数结构,直接返回可复制的调用示例。
|
|
27
|
+
### 2.1 标准三步走(推荐)
|
|
35
28
|
|
|
36
29
|
```
|
|
37
|
-
|
|
30
|
+
// 1. 查询参数说明
|
|
31
|
+
ext_skill({ plugin: "mcp:<servername>" })
|
|
32
|
+
|
|
33
|
+
// 2. 根据返回的参数定义调用
|
|
34
|
+
ext_call({
|
|
35
|
+
plugin: "mcp:<servername>",
|
|
36
|
+
tool: "<tool_name>",
|
|
37
|
+
args: { "参数名": "参数值", ... }
|
|
38
|
+
})
|
|
38
39
|
```
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
### 2.2 简单调用(已知参数)
|
|
41
42
|
|
|
42
|
-
```
|
|
43
|
-
{
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
"required": ["url"],
|
|
49
|
-
"example": "{\"url\": \"https://example.com\"}",
|
|
50
|
-
"fullExample": "mcp_call({ server: \"fetch\", tool: \"fetch\", args_json: '{\"url\": \"https://...\"}' })"
|
|
51
|
-
}
|
|
52
|
-
}
|
|
43
|
+
```
|
|
44
|
+
ext_call({
|
|
45
|
+
plugin: "mcp:designmd",
|
|
46
|
+
tool: "search_design_kits",
|
|
47
|
+
args: { query: "dark", limit: 5 }
|
|
48
|
+
})
|
|
53
49
|
```
|
|
54
50
|
|
|
55
|
-
###
|
|
56
|
-
|
|
57
|
-
调用 MCP 服务器的工具。
|
|
51
|
+
### 2.3 嵌套参数
|
|
58
52
|
|
|
59
53
|
```
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
tool: "
|
|
63
|
-
|
|
54
|
+
ext_call({
|
|
55
|
+
plugin: "mcp:designmd",
|
|
56
|
+
tool: "search_design_kits",
|
|
57
|
+
args: {
|
|
58
|
+
query: "minimal",
|
|
59
|
+
tags: ["dark", "saas"],
|
|
60
|
+
sort: "trending",
|
|
61
|
+
limit: 10
|
|
62
|
+
}
|
|
64
63
|
})
|
|
65
64
|
```
|
|
66
65
|
|
|
67
|
-
|
|
66
|
+
---
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
- 必填参数不能为空
|
|
71
|
-
- 如果不知道参数结构,先用 `mcp_tool_schema` 查询
|
|
68
|
+
## 3. 管理工具
|
|
72
69
|
|
|
73
|
-
###
|
|
70
|
+
### mcp_list_servers
|
|
74
71
|
|
|
75
|
-
|
|
72
|
+
列出所有 MCP 服务器及其连接状态。
|
|
76
73
|
|
|
77
74
|
```
|
|
78
|
-
|
|
75
|
+
mcp_list_servers()
|
|
79
76
|
```
|
|
80
77
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
## 2. Calling Patterns
|
|
78
|
+
### mcp_reload
|
|
84
79
|
|
|
85
|
-
|
|
80
|
+
重新加载 `.foliko/mcp_config.json` 配置。
|
|
86
81
|
|
|
87
|
-
```javascript
|
|
88
|
-
// 调用 fetch 工具获取网页
|
|
89
|
-
mcp_call({
|
|
90
|
-
server: 'fetch',
|
|
91
|
-
tool: 'fetch',
|
|
92
|
-
args_json: '{"url": "https://news.baidu.com"}',
|
|
93
|
-
});
|
|
94
82
|
```
|
|
95
|
-
|
|
96
|
-
### 多个参数调用
|
|
97
|
-
|
|
98
|
-
```javascript
|
|
99
|
-
// 调用搜索工具
|
|
100
|
-
mcp_call({
|
|
101
|
-
server: 'bing-cn-mcp-server',
|
|
102
|
-
tool: 'bing_search',
|
|
103
|
-
args_json: '{"query": "关键词", "count": 10}',
|
|
104
|
-
});
|
|
83
|
+
mcp_reload()
|
|
105
84
|
```
|
|
106
85
|
|
|
107
|
-
###
|
|
108
|
-
|
|
109
|
-
对于复杂参数(嵌套对象、数组等):
|
|
86
|
+
### mcp_set_enabled
|
|
110
87
|
|
|
111
|
-
|
|
88
|
+
动态开启/关闭某个 MCP 服务器(关闭时对应的 `mcp:<server>` 扩展也会注销)。
|
|
112
89
|
|
|
113
90
|
```
|
|
114
|
-
|
|
91
|
+
mcp_set_enabled({ server: "designmd", enabled: false })
|
|
115
92
|
```
|
|
116
93
|
|
|
117
|
-
2. 根据返回的 `example` 或 `fullExample` 构造调用
|
|
118
|
-
|
|
119
94
|
---
|
|
120
95
|
|
|
121
|
-
##
|
|
122
|
-
|
|
123
|
-
### 参数为空
|
|
96
|
+
## 4. 错误处理
|
|
124
97
|
|
|
125
|
-
|
|
98
|
+
### 插件不存在
|
|
126
99
|
|
|
127
100
|
```json
|
|
128
|
-
{
|
|
129
|
-
"success": false,
|
|
130
|
-
"error": "参数为空!必须提供: url",
|
|
131
|
-
"hint": "正确格式: {\"url\": \"具体值\"}"
|
|
132
|
-
}
|
|
101
|
+
{ "success": false, "error": "扩展插件 'mcp:foo' 不存在" }
|
|
133
102
|
```
|
|
134
103
|
|
|
135
|
-
|
|
104
|
+
→ 先调用 `mcp_list_servers()` 确认服务器名是否正确
|
|
136
105
|
|
|
137
|
-
|
|
106
|
+
### 参数缺失或类型错误
|
|
138
107
|
|
|
139
|
-
|
|
140
|
-
{
|
|
141
|
-
"success": false,
|
|
142
|
-
"error": "args_json 格式错误,不是有效的 JSON"
|
|
143
|
-
}
|
|
144
|
-
```
|
|
108
|
+
→ 调用 `ext_skill({ plugin: "mcp:<server>" })` 查看参数定义
|
|
145
109
|
|
|
146
|
-
###
|
|
110
|
+
### 服务器连接失败
|
|
147
111
|
|
|
148
|
-
|
|
149
|
-
{
|
|
150
|
-
"success": false,
|
|
151
|
-
"error": "MCP server 'xxx' not found"
|
|
152
|
-
}
|
|
153
|
-
```
|
|
112
|
+
→ 检查 `.foliko/mcp_config.json` 配置,或调用 `mcp_reload()` 重试
|
|
154
113
|
|
|
155
114
|
---
|
|
156
115
|
|
|
157
|
-
##
|
|
116
|
+
## 5. 配置
|
|
158
117
|
|
|
159
118
|
MCP 服务器配置在 `.foliko/mcp_config.json`:
|
|
160
119
|
|
|
161
120
|
```json
|
|
162
121
|
{
|
|
163
122
|
"mcpServers": {
|
|
164
|
-
"
|
|
165
|
-
"
|
|
166
|
-
"
|
|
167
|
-
"
|
|
168
|
-
|
|
169
|
-
}
|
|
123
|
+
"designmd": {
|
|
124
|
+
"enabled": true,
|
|
125
|
+
"command": "npx",
|
|
126
|
+
"args": ["designmd-mcp"],
|
|
127
|
+
"env": { "DESIGNMD_API_KEY": "xxx" }
|
|
170
128
|
}
|
|
171
129
|
}
|
|
172
130
|
}
|
|
173
131
|
```
|
|
174
132
|
|
|
175
|
-
|
|
133
|
+
`enabled: false` 的服务器不会自动连接;可通过 `mcp_set_enabled` 动态开启。
|
|
176
134
|
|
|
177
135
|
---
|
|
178
136
|
|
|
179
|
-
##
|
|
137
|
+
## 6. Best Practices
|
|
180
138
|
|
|
181
|
-
- [ ]
|
|
182
|
-
- [ ]
|
|
183
|
-
- [ ] 必填参数必须提供
|
|
139
|
+
- [ ] 不确定参数时先调用 `ext_skill({ plugin: "mcp:<server>" })`
|
|
140
|
+
- [ ] 参数值遵守 JSON 格式(注意引号)
|
|
184
141
|
- [ ] 修改配置后用 `mcp_reload()` 重载
|
|
185
|
-
- [ ]
|
|
142
|
+
- [ ] 调用前可先 `mcp_list_servers()` 确认服务器状态
|
|
143
|
+
- [ ] args 直接传对象,不要序列化成字符串
|
|
186
144
|
|
|
187
145
|
---
|
|
188
146
|
|
|
189
|
-
##
|
|
147
|
+
## 7. Quick Reference
|
|
190
148
|
|
|
191
|
-
| 场景 | 操作
|
|
192
|
-
| -------------- |
|
|
193
|
-
|
|
|
194
|
-
|
|
|
195
|
-
| 调用工具 | `
|
|
196
|
-
| 重载配置 | `mcp_reload()`
|
|
149
|
+
| 场景 | 操作 |
|
|
150
|
+
| -------------- | ---------------------------------------------------------- |
|
|
151
|
+
| 查看服务器列表 | `mcp_list_servers()` |
|
|
152
|
+
| 查询参数说明 | `ext_skill({ plugin: "mcp:<server>" })` |
|
|
153
|
+
| 调用工具 | `ext_call({ plugin: "mcp:<server>", tool: "x", args: {} })` |
|
|
154
|
+
| 重载配置 | `mcp_reload()` |
|
|
155
|
+
| 启停服务器 | `mcp_set_enabled({ server: "x", enabled: true })` |
|
|
197
156
|
|
|
198
157
|
---
|
|
199
158
|
|
|
200
|
-
> **Tip:**
|
|
159
|
+
> **Tip:** MCP 工具的 `args` 是普通对象,不需要像旧版那样序列化成 JSON 字符串。
|
package/skills/plugins/SKILL.md
CHANGED
|
@@ -15,13 +15,99 @@ Foliko 支持两种插件开发方式:
|
|
|
15
15
|
| **function(foliko)** | `module.exports = function(foliko) {}` | `.foliko/plugins/*.js` |
|
|
16
16
|
| **类式插件** | `class MyPlugin extends Plugin {}` | `.foliko/plugins/*/index.js` |
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
**推荐使用类式插件**,支持更完善的生命周期管理(disable/enable 时自动处理工具/扩展)。
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
22
|
-
## 快速开始
|
|
22
|
+
## 快速开始 - 类式插件(推荐)
|
|
23
23
|
|
|
24
|
-
创建 `.foliko/plugins/my-plugin.js`:
|
|
24
|
+
创建 `.foliko/plugins/my-plugin/index.js`:
|
|
25
|
+
|
|
26
|
+
```javascript
|
|
27
|
+
const { Plugin } = require('foliko');
|
|
28
|
+
|
|
29
|
+
class MyPlugin extends Plugin {
|
|
30
|
+
name = 'my-plugin';
|
|
31
|
+
version = '1.0.0';
|
|
32
|
+
description = '我的插件';
|
|
33
|
+
|
|
34
|
+
onStart(framework) {
|
|
35
|
+
// 注册 AI SDK 工具(直接调用)
|
|
36
|
+
this.tool.register({
|
|
37
|
+
name: 'hello',
|
|
38
|
+
description: '打招呼',
|
|
39
|
+
inputSchema: framework.z.object({
|
|
40
|
+
name: framework.z.string().describe('姓名')
|
|
41
|
+
}),
|
|
42
|
+
execute: async (args) => ({ message: `Hello, ${args.name}!` }),
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// 注册扩展工具(通过 ext_call 调用)
|
|
46
|
+
this.extension.register({
|
|
47
|
+
name: 'greet',
|
|
48
|
+
description: '打招呼扩展',
|
|
49
|
+
inputSchema: framework.z.object({
|
|
50
|
+
name: framework.z.string()
|
|
51
|
+
}),
|
|
52
|
+
execute: async (args) => ({ message: `Hi, ${args.name}!` }),
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
module.exports = MyPlugin;
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### 类式插件生命周期
|
|
61
|
+
|
|
62
|
+
| 方法 | 调用时机 | 用途 |
|
|
63
|
+
|------|----------|------|
|
|
64
|
+
| `onStart(framework)` | start/enable/reload | 注册工具、扩展、子代理 |
|
|
65
|
+
| `onStop()` | disable | 清理资源(工具/扩展基类自动处理) |
|
|
66
|
+
| `onCwdChanged(oldCwd, newCwd, framework)` | 工作目录变更 | 更新资源路径 |
|
|
67
|
+
|
|
68
|
+
### 工具/扩展自动管理
|
|
69
|
+
|
|
70
|
+
| 操作 | 效果 |
|
|
71
|
+
|------|------|
|
|
72
|
+
| `disable` | 自动移除工具/扩展(保留注册记录) |
|
|
73
|
+
| `enable` | 自动重新注册工具/扩展 |
|
|
74
|
+
| `reload` | 移除后重新注册 |
|
|
75
|
+
| `uninstall` | 移除并清空注册记录 |
|
|
76
|
+
|
|
77
|
+
### 手动操作
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
// 注册
|
|
81
|
+
this.tool.register({ name: 'xxx', ... });
|
|
82
|
+
this.extension.register({ name: 'xxx', ... });
|
|
83
|
+
|
|
84
|
+
// 移除
|
|
85
|
+
this.tool.remove('xxx');
|
|
86
|
+
this.extension.remove('xxx');
|
|
87
|
+
|
|
88
|
+
// 执行
|
|
89
|
+
const r1 = await this.tool.execute('any-tool', { arg: 'value' }); // 执行任何已注册工具
|
|
90
|
+
const r2 = await this.extension.execute('xxx', { arg: 'value' }); // 执行当前插件的扩展
|
|
91
|
+
const r3 = await this.extension.execute('plugin-name', 'xxx', { arg: 'value' }); // 执行指定插件的扩展
|
|
92
|
+
|
|
93
|
+
// 工作流
|
|
94
|
+
this.workflow.register('my-workflow', { name: 'my-workflow', steps: [...] });
|
|
95
|
+
const result = await this.workflow.execute('my-workflow', { input: 'value' });
|
|
96
|
+
this.workflow.remove('my-workflow');
|
|
97
|
+
|
|
98
|
+
// 子代理
|
|
99
|
+
this.agent.register({ name: 'my-agent', role: '助手', goal: '描述' });
|
|
100
|
+
const agent = this.agent.get('my-agent');
|
|
101
|
+
this.agent.remove('my-agent');
|
|
102
|
+
|
|
103
|
+
// Prompt
|
|
104
|
+
this.prompt.register('my-prompt', () => 'content', { scope: 'global' });
|
|
105
|
+
this.prompt.remove('my-prompt');
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 快速开始 - function(foliko)
|
|
25
111
|
|
|
26
112
|
```javascript
|
|
27
113
|
/**
|
package/skills/python/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: python-plugin-dev
|
|
3
|
-
description: Python 插件开发指南。当用户说"创建 Python 插件"、"用 Python 写插件"时立即调用此 skill。注意:只适合python 开发插件
|
|
3
|
+
description: Python 插件开发指南。当用户说"创建 Python 插件"、"用 Python 写插件"时立即调用此 skill。注意:只适合 python 开发插件
|
|
4
4
|
allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -8,44 +8,40 @@ allowed-tools: Read, Write, Edit, Glob, Grep, Bash
|
|
|
8
8
|
|
|
9
9
|
## ext_call 调用方式
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
每个 Python 插件自动注册为独立扩展 `python:<插件名>`,通过 `ext_call` + `ext_skill` 统一调用:
|
|
12
12
|
|
|
13
13
|
```javascript
|
|
14
|
+
// 1. 先查询参数
|
|
15
|
+
ext_skill({ plugin: "python:<插件名>" })
|
|
16
|
+
|
|
17
|
+
// 2. 用结构化对象参数调用
|
|
14
18
|
ext_call({
|
|
15
|
-
plugin: "
|
|
16
|
-
tool: "
|
|
17
|
-
args: {
|
|
19
|
+
plugin: "python:<插件名>", // 格式:python:<插件名>
|
|
20
|
+
tool: "<工具名>", // 纯工具名(不带插件名前缀)
|
|
21
|
+
args: { /* Zod 结构化参数 */ }
|
|
18
22
|
});
|
|
19
23
|
```
|
|
20
24
|
|
|
21
|
-
**注意**:插件下的工具调用时,`tool` 参数格式为:
|
|
22
|
-
|
|
23
|
-
- 如果工具名是 `query_data`,插件名是 `test_nested_plugin`
|
|
24
|
-
- 调用时:`plugin: "python"`, `tool: "test_nested_plugin_query_data"`
|
|
25
|
-
- 即:自动将 `插件名_工具名` 合并为 `tool` 参数
|
|
26
|
-
|
|
27
25
|
**示例**:
|
|
28
26
|
|
|
29
27
|
```javascript
|
|
30
|
-
// 插件名:
|
|
28
|
+
// 插件名: my-plugin, 工具名: hello
|
|
31
29
|
ext_call({
|
|
32
|
-
plugin: 'python',
|
|
33
|
-
tool: '
|
|
30
|
+
plugin: 'python:my-plugin',
|
|
31
|
+
tool: 'hello',
|
|
34
32
|
args: { name: 'Foliko' },
|
|
35
33
|
});
|
|
36
34
|
|
|
37
35
|
// 插件名: test_nested_plugin, 工具名: query_data
|
|
38
36
|
ext_call({
|
|
39
|
-
plugin: 'python',
|
|
40
|
-
tool: '
|
|
37
|
+
plugin: 'python:test_nested_plugin',
|
|
38
|
+
tool: 'query_data',
|
|
41
39
|
args: { filter: { name: 'Alice' } },
|
|
42
40
|
});
|
|
43
41
|
```
|
|
44
42
|
|
|
45
43
|
## 概述
|
|
46
44
|
|
|
47
|
-
## 概述
|
|
48
|
-
|
|
49
45
|
Python 插件允许用 Python 语言开发工具,插件代码运行在 Python 环境中,可以调用所有 Python 库。
|
|
50
46
|
|
|
51
47
|
## 插件存放位置
|
|
@@ -105,11 +101,12 @@ def calc(params):
|
|
|
105
101
|
return {"success": True, "result": result}
|
|
106
102
|
```
|
|
107
103
|
|
|
108
|
-
**重要**:`
|
|
104
|
+
**重要**:`TOOLS` 字段定义了插件提供的所有工具。框架会自动:
|
|
109
105
|
|
|
110
|
-
1.
|
|
111
|
-
2.
|
|
112
|
-
3.
|
|
106
|
+
1. 把插件注册为 `python:<插件名>` 扩展
|
|
107
|
+
2. 每个工具作为该扩展下的 tool(tool 名为原始名,不带前缀)
|
|
108
|
+
3. 附加到系统提示词【Extensions 扩展工具】部分
|
|
109
|
+
4. 可通过 `ext_call({ plugin: "python:<插件名>", tool: "<工具名>", args: {...} })` 调用
|
|
113
110
|
|
|
114
111
|
## 工具函数规范
|
|
115
112
|
|
|
@@ -135,13 +132,13 @@ def calc(params):
|
|
|
135
132
|
|
|
136
133
|
## 使用方式
|
|
137
134
|
|
|
138
|
-
通过 `ext_call`
|
|
135
|
+
通过 `ext_call` 调用(`python:<插件名>` 是固定格式):
|
|
139
136
|
|
|
140
137
|
```javascript
|
|
141
138
|
ext_call({
|
|
142
|
-
plugin: 'python',
|
|
143
|
-
tool: '
|
|
144
|
-
args: { name: 'Foliko' },
|
|
139
|
+
plugin: 'python:my-plugin', // python:<插件名>
|
|
140
|
+
tool: 'hello', // 纯工具名(不带插件名前缀)
|
|
141
|
+
args: { name: 'Foliko' }, // 工具参数
|
|
145
142
|
});
|
|
146
143
|
```
|
|
147
144
|
|
|
@@ -149,7 +146,7 @@ ext_call({
|
|
|
149
146
|
|
|
150
147
|
## 嵌套参数支持
|
|
151
148
|
|
|
152
|
-
`ext_call` 的 `args`
|
|
149
|
+
`ext_call` 的 `args` 参数支持多层嵌套结构,可以传递复杂的数据对象。
|
|
153
150
|
|
|
154
151
|
### 支持的参数类型
|
|
155
152
|
|
|
@@ -167,15 +164,15 @@ ext_call({
|
|
|
167
164
|
```javascript
|
|
168
165
|
// 简单参数
|
|
169
166
|
ext_call({
|
|
170
|
-
plugin: 'python',
|
|
171
|
-
tool: '
|
|
167
|
+
plugin: 'python:my-plugin',
|
|
168
|
+
tool: 'query',
|
|
172
169
|
args: { table: 'users' },
|
|
173
170
|
});
|
|
174
171
|
|
|
175
172
|
// 嵌套 filter
|
|
176
173
|
ext_call({
|
|
177
|
-
plugin: 'python',
|
|
178
|
-
tool: '
|
|
174
|
+
plugin: 'python:my-plugin',
|
|
175
|
+
tool: 'query_data',
|
|
179
176
|
args: {
|
|
180
177
|
filter: {
|
|
181
178
|
name: 'Alice',
|
|
@@ -191,8 +188,8 @@ ext_call({
|
|
|
191
188
|
|
|
192
189
|
// 带 options 的复杂查询
|
|
193
190
|
ext_call({
|
|
194
|
-
plugin: 'python',
|
|
195
|
-
tool: '
|
|
191
|
+
plugin: 'python:my-plugin',
|
|
192
|
+
tool: 'query_data',
|
|
196
193
|
args: {
|
|
197
194
|
filter: { status: 'active' },
|
|
198
195
|
options: {
|
|
@@ -226,10 +223,9 @@ def query_data(params):
|
|
|
226
223
|
|
|
227
224
|
### 注意事项
|
|
228
225
|
|
|
229
|
-
1.
|
|
230
|
-
2.
|
|
231
|
-
3.
|
|
232
|
-
4. **数组对象**:支持数组和嵌套对象的任意组合
|
|
226
|
+
1. **嵌套深度**:支持任意深度的嵌套对象
|
|
227
|
+
2. **空值处理**:使用 `.get()` 方法并提供默认值,避免 KeyError
|
|
228
|
+
3. **数组对象**:支持数组和嵌套对象的任意组合
|
|
233
229
|
|
|
234
230
|
## 示例:天气查询插件
|
|
235
231
|
|
|
@@ -274,6 +270,16 @@ def get_weather(params):
|
|
|
274
270
|
return {"success": False, "error": str(e)}
|
|
275
271
|
```
|
|
276
272
|
|
|
273
|
+
调用方式:
|
|
274
|
+
|
|
275
|
+
```javascript
|
|
276
|
+
ext_call({
|
|
277
|
+
plugin: 'python:weather', // python:<插件名>
|
|
278
|
+
tool: 'get_weather', // 纯工具名
|
|
279
|
+
args: { city: '上海' },
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
277
283
|
## 示例:文件处理插件
|
|
278
284
|
|
|
279
285
|
```python
|
|
@@ -330,6 +336,16 @@ def write_file(params):
|
|
|
330
336
|
return {"success": False, "error": str(e)}
|
|
331
337
|
```
|
|
332
338
|
|
|
339
|
+
调用方式:
|
|
340
|
+
|
|
341
|
+
```javascript
|
|
342
|
+
ext_call({
|
|
343
|
+
plugin: 'python:file_processor',
|
|
344
|
+
tool: 'read_file',
|
|
345
|
+
args: { path: '/tmp/test.txt' },
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
333
349
|
## 注意事项
|
|
334
350
|
|
|
335
351
|
1. **文件格式** - 必须是单个 `.py` 文件
|
|
@@ -338,12 +354,14 @@ def write_file(params):
|
|
|
338
354
|
4. **工具函数名** - 必须与 TOOLS 中定义的 name 一致
|
|
339
355
|
5. **异常处理** - 所有可能出错的地方都要 try-except
|
|
340
356
|
6. **编码** - 文件使用 UTF-8 编码
|
|
357
|
+
7. **命名空间** - 扩展名格式为 `python:<PLUGIN.name>`,工具名是 `TOOLS[].name`(不带前缀)
|
|
341
358
|
|
|
342
359
|
## 开发流程
|
|
343
360
|
|
|
344
361
|
1. **编写插件代码** - 在 `.foliko/plugins/` 下创建 `.py` 文件
|
|
345
|
-
2. **自动加载** -
|
|
346
|
-
3.
|
|
362
|
+
2. **自动加载** - 框架启动时自动注册到 `python:<插件名>` 扩展
|
|
363
|
+
3. **测试** - 在聊天中用 `/<插件名>:<工具名>` 测试,或让 LLM 用 `ext_call` 调用
|
|
364
|
+
4. **调试** - 查看返回的 `success` 和 `error` 信息
|
|
347
365
|
|
|
348
366
|
## 常用 Python 库
|
|
349
367
|
|