插件 Agent 工具
插件 Agent 工具
OpenClaw 插件可以注册 Agent 工具(JSON Schema 函数),这些工具在 Agent 运行期间暴露给 LLM。工具可以是 必需的(始终可用)或 可选的(需手动启用)。
Agent 工具在主配置的 tools 下配置,或在每个 Agent 的 agents.list[].tools 下配置。允许列表/拒绝列表策略控制 Agent 可以调用哪些工具。
基本工具
import { Type } from "@sinclair/typebox";
export default function (api) {
api.registerTool({
name: "my_tool",
description: "做一件事",
parameters: Type.Object({
input: Type.String(),
}),
async execute(_id, params) {
return { content: [{ type: "text", text: params.input }] };
},
});
}
可选工具(需手动启用)
可选工具 永远不会 自动启用。用户必须将它们添加到 Agent 允许列表中。
export default function (api) {
api.registerTool(
{
name: "workflow_tool",
description: "运行本地工作流",
parameters: {
type: "object",
properties: {
pipeline: { type: "string" },
},
required: ["pipeline"],
},
async execute(_id, params) {
return { content: [{ type: "text", text: params.pipeline }] };
},
},
{ optional: true },
);
}
在 agents.list[].tools.allow(或全局 tools.allow)中启用可选工具:
{
agents: {
list: [
{
id: "main",
tools: {
allow: [
"workflow_tool", // 具体工具名称
"workflow", // 插件 ID(启用该插件的所有工具)
"group:plugins", // 所有插件工具
],
},
},
],
},
}
其他影响工具可用性的配置选项:
- 仅命名插件工具的允许列表被视为插件手动启用;核心工具保持启用,除非你也在允许列表中包含核心工具或组。
tools.profile/agents.list[].tools.profile(基础允许列表)tools.byProvider/agents.list[].tools.byProvider(特定于提供者的允许/拒绝)tools.sandbox.tools.*(沙箱模式下的工具策略)
规则与提示
- 工具名称 不得 与核心工具名称冲突;冲突的工具会被跳过。
- 允许列表中使用的插件 ID 不得与核心工具名称冲突。
- 对于触发副作用或需要额外二进制文件/凭据的工具,优先使用
optional: true。