工具调用 (HTTP)
工具调用 (HTTP)
Section titled “工具调用 (HTTP)”OpenClaw 的 Gateway 暴露了一个简单的 HTTP 端点,用于直接调用单个工具。它始终启用,但受到 Gateway 身份验证和工具策略的限制。
POST /tools/invoke- 与 Gateway 相同的端口 (WS + HTTP 复用):
http://<gateway-host>:<port>/tools/invoke
默认最大负载大小为 2 MB。
使用 Gateway 身份验证配置。发送 Bearer 令牌:
Authorization: Bearer <token>
注意:
- 当
gateway.auth.mode="token"时,使用gateway.auth.token(或OPENCLAW_GATEWAY_TOKEN)。 - 当
gateway.auth.mode="password"时,使用gateway.auth.password(或OPENCLAW_GATEWAY_PASSWORD)。
{ "tool": "sessions_list", "action": "json", "args": {}, "sessionKey": "main", "dryRun": false}字段:
tool(字符串,必填): 要调用的工具名称。action(字符串,可选): 如果工具模式支持action且 args 负载省略了它,则映射到 args 中。args(对象,可选): 特定于工具的参数。sessionKey(字符串,可选): 目标会话密钥。如果省略或为"main",Gateway 使用配置的主会话密钥 (遵循session.mainKey和默认代理,或全局范围内的global)。dryRun(布尔值,可选): 保留供将来使用;目前被忽略。
策略 + 路由行为
Section titled “策略 + 路由行为”工具可用性通过 Gateway 代理使用的相同策略链进行过滤:
tools.profile/tools.byProvider.profiletools.allow/tools.byProvider.allowagents.<id>.tools.allow/agents.<id>.tools.byProvider.allow- 组策略 (如果会话密钥映射到组或频道)
- 子代理策略 (当使用子代理会话密钥调用时)
如果策略不允许该工具,端点返回 404。
为了帮助组策略解析上下文,您可以选择设置:
x-openclaw-message-channel: <channel>(示例:slack,telegram)x-openclaw-account-id: <accountId>(当存在多个帐户时)
200→{ ok: true, result }400→{ ok: false, error: { type, message } }(无效请求或工具错误)401→ 未经授权404→ 工具不可用 (未找到或未列入白名单)405→ 方法不允许
curl -sS http://127.0.0.1:18789/tools/invoke \ -H 'Authorization: Bearer YOUR_TOKEN' \ -H 'Content-Type: application/json' \ -d '{ "tool": "sessions_list", "action": "json", "args": {} }'