diff --git a/docs/api/plugin-development.md b/docs/api/plugin-development.md index e5f070f..95ed621 100644 --- a/docs/api/plugin-development.md +++ b/docs/api/plugin-development.md @@ -94,13 +94,52 @@ func (t *HelloTool) Validate(args map[string]interface{}) error { return nil } ## 注册到 Cyrene -在 `ai-core/cmd/main.go` 的工具注册区添加一行: +### 方式一:plugins.json(推荐) -```go -registerPluginTools(toolRegistry, &myplugin.HelloPlugin{}) +1. 将插件代码放到 `backend/plugins/<插件名>/` +2. 在 `backend/ai-core/plugins.json` 中添加条目: + +```json +{ "name": "my-hello", "import": "git.yeij.top/AskaEth/Cyrene-Plugins/my-hello", "struct": "HelloPlugin" } ``` -重启 ai-core,LLM 即可在对话中自动调用 `hello` 工具。 +3. 运行代码生成器: + +```bash +cd backend/ai-core/cmd && go run gen_plugins.go +``` + +4. 重新编译 ai-core + +### 方式二:直接注册(需要构造参数的插件) + +在 `ai-core/cmd/main.go` 中添加: + +```go +for _, t := range (&myplugin.HelloPlugin{}).Tools() { + toolRegistry.Register(t) +} +``` + +### 插件目录结构 + +``` +backend/plugins/ ← 第三方插件目录 + my-hello/ + plugin.json ← 插件声明(name, version, struct) + main.go ← 插件入口 +``` + +`plugin.json` 格式: + +```json +{ + "name": "my-hello", + "version": "1.0.0", + "author": "your-name", + "description": "我的第一个插件" +} +``` ---