Skip to content

API 参考: 工具 (Tools)

工具注册、管理、测试和工具包端点。

注册工具

注册一个可被 AI 调用的工具。如果 name 已存在,自动执行更新。

POST /v1/tools

权限要求: write

请求体

字段类型必填说明
namestring工具唯一名称
descriptionstring工具描述,AI 依据此判断何时调用
appIdstring所属应用 ID
input_schemaobjectJSON Schema 格式的输入参数定义
executionobject执行配置
execution.typestring--"http""handler"
execution.methodstring--HTTP 方法 (GET/POST/PUT/DELETE)
execution.urlstring--请求 URL,支持 {param} 占位符
execution.headersobject--自定义请求头
execution.paramsobject--URL 查询参数
execution.bodyobject--请求体

请求示例

bash
curl -X POST https://api.invoratec.cn/v1/tools \
  -H "X-API-Key: claw_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "erp_get_inventory",
    "description": "查询 ERP 系统的库存数据",
    "appId": "my-erp",
    "input_schema": {
      "type": "object",
      "properties": {
        "warehouse_id": { "type": "string", "description": "仓库ID" }
      },
      "required": ["warehouse_id"]
    },
    "execution": {
      "type": "http",
      "method": "GET",
      "url": "https://erp.example.com/api/inventory?wh={warehouse_id}"
    }
  }'

响应 (201 Created)

json
{
  "_id": "665f1a2b3c4d5e6f7a8b9c0d",
  "name": "erp_get_inventory",
  "description": "查询 ERP 系统的库存数据",
  "appId": "my-erp",
  "developerId": "user_123",
  "input_schema": { ... },
  "execution": { ... },
  "enabled": true,
  "createdAt": "2026-04-12T08:00:00.000Z",
  "updatedAt": "2026-04-12T08:00:00.000Z"
}

如果工具已存在(更新),响应中额外包含 "updated": true

错误

状态码说明
400namedescription 缺失
403缺少 write 权限

列出工具

GET /v1/tools

查询参数

参数类型说明
appIdstring按所属应用过滤

请求示例

bash
# 列出所有工具
curl https://api.invoratec.cn/v1/tools \
  -H "X-API-Key: claw_xxxx"

# 按应用过滤
curl "https://api.invoratec.cn/v1/tools?appId=my-erp" \
  -H "X-API-Key: claw_xxxx"

响应

json
{
  "tools": [
    {
      "_id": "665f...",
      "name": "erp_get_inventory",
      "description": "查询 ERP 系统的库存数据",
      "appId": "my-erp",
      "enabled": true,
      "updatedAt": "2026-04-12T08:00:00.000Z"
    }
  ],
  "total": 1
}

获取工具详情

GET /v1/tools/{name}

路径参数

参数类型说明
namestring工具名称

请求示例

bash
curl https://api.invoratec.cn/v1/tools/erp_get_inventory \
  -H "X-API-Key: claw_xxxx"

响应

返回完整的工具文档,包含 input_schemaexecution 配置。

错误

状态码说明
404工具不存在

更新工具

PUT /v1/tools/{name}

权限要求: write

路径参数

参数类型说明
namestring工具名称

请求体

可更新以下字段:description, input_schema, execution, enabled, appId

请求示例

bash
curl -X PUT https://api.invoratec.cn/v1/tools/erp_get_inventory \
  -H "X-API-Key: claw_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "查询 ERP 库存(含批次号)",
    "enabled": true
  }'

响应

返回更新后的完整工具文档。

错误

状态码说明
403缺少 write 权限
404工具不存在

删除工具

DELETE /v1/tools/{name}

权限要求: write

请求示例

bash
curl -X DELETE https://api.invoratec.cn/v1/tools/erp_get_inventory \
  -H "X-API-Key: claw_xxxx"

响应

json
{ "success": true }

测试工具执行

在沙箱中测试工具的执行结果。HTTP 工具会实际发送请求(超时 10 秒),handler 类型工具需要桌面代理执行。

POST /v1/tools/{name}/test

权限要求: write

路径参数

参数类型说明
namestring工具名称

请求体

字段类型说明
inputobject传递给工具的输入参数

请求示例

bash
curl -X POST https://api.invoratec.cn/v1/tools/erp_get_inventory/test \
  -H "X-API-Key: claw_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "input": { "warehouse_id": "WH-001" }
  }'

响应 (成功)

json
{
  "status": "success",
  "result": { "items": [...], "total": 42 },
  "elapsed_ms": 230
}

响应 (失败)

json
{
  "status": "error",
  "error": "Connection timeout",
  "elapsed_ms": 10001
}

错误

状态码说明
404工具不存在
500执行出错

创建工具包

将多个工具组织为一个工具包,并附加 AI 知识提示。

POST /v1/tools/packs

权限要求: write

请求体

字段类型必填说明
idstring工具包唯一标识符
namestring英文名称
nameZhstring中文名称
descriptionstring描述
toolsstring[]工具名称列表
knowledgestringAI 知识提示文本

请求示例

bash
curl -X POST https://api.invoratec.cn/v1/tools/packs \
  -H "X-API-Key: claw_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "erp-inventory-pack",
    "name": "ERP Inventory Pack",
    "nameZh": "ERP 库存工具包",
    "description": "库存查询和管理工具集",
    "tools": ["erp_get_inventory", "erp_update_stock"],
    "knowledge": "仓库编号以WH-开头。库存数据每5分钟同步。"
  }'

响应 (201 Created)

json
{
  "_id": "665f...",
  "packId": "erp-inventory-pack",
  "name": "ERP Inventory Pack",
  "nameZh": "ERP 库存工具包",
  "tools": ["erp_get_inventory", "erp_update_stock"],
  "knowledge": "仓库编号以WH-开头。库存数据每5分钟同步。",
  "status": "draft",
  "createdAt": "2026-04-12T08:00:00.000Z"
}

错误

状态码说明
400idname 缺失
403缺少 write 权限

列出工具包

GET /v1/tools/packs

请求示例

bash
curl https://api.invoratec.cn/v1/tools/packs \
  -H "X-API-Key: claw_xxxx"

响应

json
{
  "packs": [
    {
      "_id": "665f...",
      "packId": "erp-inventory-pack",
      "name": "ERP Inventory Pack",
      "nameZh": "ERP 库存工具包",
      "tools": ["erp_get_inventory", "erp_update_stock"],
      "status": "draft"
    }
  ]
}

智航云 AI 中台 — 开发者平台