From 65ff530ce4edf2e084d532ab4432ad095d3b1a2c Mon Sep 17 00:00:00 2001 From: AskaEth Date: Wed, 24 Jun 2026 19:31:49 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=8F=92=E4=BB=B6=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E6=9B=B4=E6=96=B0=20=E2=80=94=20plugins.json?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E6=9B=BF=E4=BB=A3=E7=A1=AC?= =?UTF-8?q?=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/plugin-development.md | 47 +++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 4 deletions(-) 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": "我的第一个插件" +} +``` ---