三亩地 三亩地SAN MU DI · CODE DIARY
ARTICLE DETAIL

日记详情

真实记录编程学习的某一天,欢迎挑你感兴趣的翻一翻。

QwenPaw工具注册

QwenPaw工具注册
## 工具插件是如何工作的 ### 插件的 `type` 字段决定了能力 在 `plugin.json` 中把 `type` 设为 `"tool"`,插件安装后会自动把工具注册给 Agent 调用: ```json { "id": "my-custom-tool", "name": "我的自定义工具", "version": "1.0.0", "type": "tool", "entry": { "backend": "plugin.py" } } ``` ### 注册方式 QwenPaw 提供了两种注册工具的方式: **方式一:通过 `@tool_descriptor` 装饰器(v2.0.1+ 推荐)** ```python from qwenpaw.tools import tool_descriptor @tool_descriptor( name="get_weather", description="查询指定城市的天气" ) def get_weather(city: str) -> str: return f"{city}:晴,25°C" ``` 工具会自动被发现和注册,不需要手动调用 `register_tool`。 **方式二:通过 `PluginApi.register_tool`** ```python from qwenpaw.plugins.api import PluginApi class MyToolPlugin: def register(self, api: PluginApi): api.register_tool(get_weather) ```

完整例子:一个天气工具插件

weather-tool/ ├── plugin.json ├── plugin.py

plugin.json:

{ "id": "weather-tool", "name": "天气查询工具", "version": "1.0.0", "type": "tool", "description": "查询城市天气", "author": "同事", "entry": { "backend": "plugin.py" } }

plugin.py:

from qwenpaw.tools import tool_descriptor ​ @tool_descriptor( name="get_weather", description="根据城市名查询当前天气,返回温度、天气状况" ) def get_weather(city: str) -> str: # 这里可以接真实的天气 API return f"{city}:晴,22-30°C,微风"

安装:

qwenpaw plugin install weather-tool/

安装后重启 QwenPaw,进入Agent 设置 → 工具管理,就能看到get_weather工具,启用后 Agent 就可以调用了。


安装后工具的生命周期

上传插件 ZIP/目录 ↓ qwenpaw plugin install ← 安装到本地 ↓ qwenpaw app 启动 ← 自动加载、自动注册工具 ↓ Console → Agent 设置 → 工具管理 ← 启用/禁用/配置 API Key ↓ Agent 对话中就可以调用 ← LLM 自主决定何时调用

所以回到你的问题

是的,插件上传接口完全可以上传工具。你同事给你的插件如果type"tool",那就是两个 Agent 工具。你只需要:

# QwenPaw 离线状态下 qwenpaw plugin install /path/to/plugin-dir/ ​ # 然后启动 qwenpaw app

工具就会出现在工具管理里了。把插件文件给我看看plugin.json,我帮你确认是不是工具类插件 👀

← 返回列表