插件 API

OpenVort 插件开发 API 参考。

BasePlugin

所有插件必须继承 BasePlugin 基类。

属性

属性类型说明
namestr插件唯一标识
descriptionstr插件描述
versionstr插件版本

方法

get_tools()

返回插件提供的工具列表。

def get_tools(self) -> list[BaseTool]:
    return [MyTool(), AnotherTool()]

get_prompts()

返回插件提供的 System Prompt 片段。

def get_prompts(self) -> list[str]:
    return ["You have access to ..."]

BaseTool

所有工具必须继承 BaseTool 基类。

属性

属性类型说明
namestr工具名称(Claude 调用时使用)
descriptionstr工具描述(影响 AI 调用决策)
parametersdictJSON Schema 格式的参数定义

方法

execute(**kwargs)

工具的执行逻辑,异步方法。

async def execute(self, **kwargs) -> str:
    result = await do_something(**kwargs)
    return json.dumps(result)

返回值

  • 返回 str 类型,建议使用 JSON 格式
  • 返回内容会作为 Tool Result 传回 Claude
  • Claude 基于返回内容生成最终回复

配置

插件可以通过环境变量或配置文件获取配置:

from openvort.config import settings

class MyPlugin(BasePlugin):
    def __init__(self):
        self.api_key = settings.get("MY_PLUGIN_API_KEY")

生命周期

  1. 发现 — 引擎启动时通过 entry_points 发现插件
  2. 加载 — 实例化插件,调用 __init__
  3. 注册 — 将 Tools 和 Prompts 注册到 Agent Runtime
  4. 运行 — Agent 在对话中按需调用 Tools

扩展市场 API

MarketplaceClient

核心引擎中用于与扩展市场交互的 HTTP 客户端。

方法说明
search(query, type, category)搜索扩展市场
get_skill(slug, author)获取 Skill 详情(含 content + bundle 信息)
get_plugin(slug, author)获取 Plugin 详情(含 packageName + bundle 信息)
download_bundle(url, dest)下载 Bundle zip 到本地
upload_bundle(slug, type, zip_path)上传 Bundle zip 到市场
publish_extension(body)发布/更新扩展元数据

MarketplaceInstaller

处理扩展的安装和卸载。

方法说明
install_skill(slug, author)安装 Skill(写入 DB + 注册 Prompt + 下载 Bundle)
install_plugin(slug, author)安装 Plugin(Bundle 解压或 pip install)
uninstall_skill(slug)卸载 Skill
uninstall_plugin(slug)卸载 Plugin Bundle
list_installed()列出已安装的市场扩展
check_updates()检查更新(比较版本号 + 内容 Hash)

管理面板 API

所有市场管理 API 在 /api/admin/marketplace/ 下,需要管理员认证:

方法路径说明
GET/search搜索市场
POST/install/skill安装 Skill
POST/install/plugin安装 Plugin
GET/installed列出已安装
POST/uninstall卸载扩展(支持 type 参数)
GET/updates检查更新(版本 + Hash)