执行工厂 · 工具箱 API (0.1.3)

Download OpenAPI specification:

工具箱(tool box)是一组工具的容器,也是权限与发布的单位。Agent 挂载的是 工具箱,不是单个工具。

两层结构:工具箱有自己的生命周期(unpublish / published / offline) 与分类;箱内每个工具有独立的启停开关(enabled / disabled)。两者是两套状态, 别混——工具箱已发布不代表箱内工具都启用。

工具从哪来,两条路:

方式 接口
直接建(写 OpenAPI 或函数代码) POST /tool-box/{box_id}/tool
一份 OpenAPI 文档批量建工具(可顺带新建工具箱) POST /capabilities/openapi-bundle

工具箱、MCP Server 与 Skill 共用的分类列表见 category.yaml。

时间戳一律是纳秒:所有 *_time 字段由 time.Now().UnixNano() 生成, 按毫秒解析会得到 1970 年附近的日期。

认证:Authorization: Bearer <token>(OAuth access token 或 bak_ 前缀的 AppKey)。

检索入口在内部面:POST /internal-v1/tool-box/tools/search,请求体 { query, tool_refs, top_k },出参每项带 matched_by 与 score。

tool_refs 是扁平引用 "{box_id}/{tool_id}" 的列表。工具 id 在执行工厂里按箱 限定作用域,所以配对才是一个工具的身份——只按 tool_id 收窄会让调用方够到另一个 箱里同 id 的工具。格式非法的引用被静默丢弃(白名单来自存量绑定,一条失效条目应当 让范围变窄,而不是让整个请求失败);悬空引用查不到行,同样静默略过。

tool_refs 必填,空数组与字段缺失都返回空结果,不是「不过滤」——后者会把全平台 工具交给一个没有任何绑定的调用方。白名单进查询条件做 pre-filter,不是先取 top_k 再过滤;执行工厂只收一组引用,不认识 kn_id。

本期是字面子串匹配,不是语义检索:工具侧至今没有向量索引(技能侧有,工具侧 从零建一条链路体量相当),因此 matched_by 恒为 like、score 缺省。% 与 _ 按字面处理,不当通配符。出参形状按语义检索预留,届时替换实现不改契约。

不收进下面的 paths:内部面不校验令牌,按 docs/api/README.md 的口径不作为集成 合同发布。

ToolBox

新建工具箱

建一个空工具箱。metadata_type 决定这个箱子装哪类工具,建成后不可更改 (编辑接口的 metadata_type 是可选的,传了才校验)。

openapi 类型的箱子必须给 box_svc_url——箱内工具的请求都发往这个地址。

Authorizations:
OAuth2AppKey
Request Body schema: application/json
required
box_name
string

工具箱名称。

box_desc
string

工具箱描述。

box_svc_url
string

工具箱服务地址。**metadata_type=openapi 时必填**,箱内工具的请求都发往这里。

box_category
string
Default: "other_category"

分类。

metadata_type
required
string (MetadataType)
Enum: "openapi" "function"

元数据类型。工具箱建成后不可更改;决定箱内工具怎么定义 (function 走 function_input,openapi 走 data)。

source
string
Default: "custom"

来源。

object or string

OpenAPI 文档,建箱同时导入工具时用。 JSON 请求体里传 OpenAPI 文档对象(不是转义后的字符串,传字符串会解析失败); application/x-www-form-urlencoded 与 multipart/form-data 里是 OpenAPI JSON/YAML 原文文本,multipart 时也可作为名为 data 的文件上传。

Responses

Request samples

Content type
application/json
Example
{
  • "box_name": "天气服务",
  • "box_desc": "对接第三方天气 API",
  • "box_svc_url": "https://api.example.com",
  • "box_category": "data_query",
  • "metadata_type": "openapi"
}

Response samples

Content type
application/json
{
  • "box_id": "string"
}

分页查询工具箱

分页列出当前主体拥有 view 权限的工具箱。metadata_type 过滤用于「函数工具工作台 只列函数工具箱」这类场景。只有 execute、没有 view 的工具箱不会出现在顶层目录中; 已知其 ID 的运行时仍可读取具体工具元数据并执行。

条目里的 tools 是工具名字符串数组,不是工具对象也不是 ID——要工具详情 得再调 GET /tool-box/{box_id}/tools/list。

Authorizations:
OAuth2AppKey
query Parameters
page
integer >= 1
Default: 1

页码,从 1 开始。

page_size
integer [ 1 .. 100 ]
Default: 10

每页数量,1–100。

sort_by
string
Default: "update_time"
Enum: "create_time" "update_time" "name"

排序字段。

sort_order
string
Default: "desc"
Enum: "asc" "desc"

排序方向。

name
string

按工具箱名称过滤。

status
string (BizStatus)
Enum: "unpublish" "published" "offline"

按工具箱状态过滤。

category
string

按分类过滤。

create_user
string

按创建人过滤。

release_user
string

按发布人过滤。

metadata_type
string (MetadataType)
Enum: "openapi" "function"

按元数据类型过滤。

all
boolean

忽略分页返回全部。

Responses

Response samples

Content type
application/json
{
  • "total": 45,
  • "page": 1,
  • "page_size": 2,
  • "total_pages": 23,
  • "has_next": true,
  • "has_prev": false,
  • "data": [
    ]
}

按 ID 批量取工具箱名

与 /skills/names 同契约:不存在的 ID 静默略过、不占位, 调用方自己比对哪些没回来。

Authorizations:
OAuth2AppKey
Request Body schema: application/json
required
ids
Array of strings

待取名的工具箱 ID 列表。空列表返回空 entries。

Responses

Request samples

Content type
application/json
{
  • "ids": [
    ]
}

Response samples

Content type
application/json
{
  • "entries": [
    ]
}

查询工具箱详情

取工具箱详情,含箱内工具的完整定义。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

Responses

Response samples

Content type
application/json
{
  • "box_id": "string",
  • "box_name": "string",
  • "box_desc": "string",
  • "box_svc_url": "string",
  • "metadata_type": "openapi",
  • "status": "unpublish",
  • "category_type": "string",
  • "category_name": "string",
  • "is_internal": true,
  • "source": "string",
  • "tools": [
    ],
  • "create_user": "string",
  • "create_time": 0,
  • "update_user": "string",
  • "update_time": 0,
  • "release_user": "string",
  • "release_time": 0
}

更新工具箱

更新走 POST 不是 PUT。box_name / box_desc / box_category 都是必填 ——这是整体覆盖,不是部分更新,不传就报必填错误。

metadata_type 反而是可选的:工具箱建成后类型不会变,带了才校验取值。

响应里的 edit_tools 列出因本次更新而受影响的工具及其新状态。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

Request Body schema: application/json
required
box_name
required
string
box_desc
required
string
box_svc_url
string

metadata_type=openapi 时必填。

box_category
required
string
metadata_type
string (MetadataType)
Enum: "openapi" "function"

元数据类型。工具箱建成后不可更改;决定箱内工具怎么定义 (function 走 function_input,openapi 走 data)。

object or string

OpenAPI 文档。 JSON 请求体里传 OpenAPI 文档对象(不是转义后的字符串,传字符串会解析失败); application/x-www-form-urlencoded 与 multipart/form-data 里是 OpenAPI JSON/YAML 原文文本,multipart 时也可作为名为 data 的文件上传。

Responses

Request samples

Content type
application/json
{
  • "box_name": "string",
  • "box_desc": "string",
  • "box_svc_url": "string",
  • "box_category": "string",
  • "metadata_type": "openapi",
  • "data": { }
}

Response samples

Content type
application/json
{
  • "box_id": "string",
  • "edit_tools": [
    ]
}

删除工具箱

删除工具箱及其下全部工具。已被 Agent 挂载的工具箱删除后调用方会拿到 404。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

Responses

Response samples

Content type
application/json
{
  • "error_code": "string",
  • "description": "string",
  • "error_details": null,
  • "metadata": { }
}

更新工具箱状态

发布 / 下架工具箱。工具箱只有三个状态(unpublish / published / offline),没有 editing。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

Request Body schema: application/json
required
status
required
string (BizStatus)
Enum: "unpublish" "published" "offline"

工具箱的生命周期状态。只有三个值,没有 editing。

Responses

Request samples

Content type
application/json
{
  • "status": "unpublish"
}

Response samples

Content type
application/json
{
  • "box_id": "string",
  • "status": "unpublish"
}

在工具箱中新建工具

往箱子里加工具。metadata_type 决定必填字段:function 走 function_input(代码约定见 function.yaml,入口函数必须叫 handler),openapi 走 data(OpenAPI 原文)。

一次可以建出多个工具:一份 OpenAPI 文档里有几个操作就建几个工具, 所以响应是 success_count / failure_count 的批量结果,部分成功是常态 ——failure_count 非 0 时接口仍返回 200,失败明细在 failures 里。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

Request Body schema: application/json
required
metadata_type
required
string (MetadataType)
Enum: "openapi" "function"

元数据类型。工具箱建成后不可更改;决定箱内工具怎么定义 (function 走 function_input,openapi 走 data)。

use_rule
string

使用规则。

object (GlobalParameter)

全局参数:调用该工具时固定附加的一个参数(如统一的 API Key)。 是单个对象不是数组。

object

函数定义。**metadata_type=function 时必填**,字段为 name、 description、script_type(仅 python)、code、inputs、outputs、 dependencies、dependencies_url。代码约定与 function.yaml 一致:入口函数必须叫 handler。

object or string

OpenAPI 文档。**metadata_type=openapi 时必填。文档里有几个操作就建 几个工具。JSON 请求体里传文档对象**(传字符串会解析失败);表单与 multipart 里是 JSON/YAML 原文文本,multipart 也可作为名为 data 的文件上传。

object

Responses

Request samples

Content type
application/json
{
  • "metadata_type": "openapi",
  • "use_rule": "string",
  • "global_parameters": {
    },
  • "function_input": { },
  • "data": { },
  • "extend_info": { }
}

Response samples

Content type
application/json
{
  • "box_id": "string",
  • "success_count": 0,
  • "success_ids": [
    ],
  • "failure_count": 0,
  • "failures": [
    ]
}

查询工具详情

取单个工具的完整定义,含元数据、全局参数与使用规则。该定义也是调用工具所需的运行时 输入,因此对所属工具箱拥有 view、public_access 或 execute 任一权限即可读取; 这不会让 execute-only 工具箱出现在顶层目录中。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

tool_id
required
string

工具 ID。

Responses

Response samples

Content type
application/json
{
  • "tool_id": "string",
  • "name": "string",
  • "description": "string",
  • "status": "enabled",
  • "metadata_type": "openapi",
  • "metadata": { },
  • "use_rule": "string",
  • "global_parameters": {
    },
  • "resource_object": "tool",
  • "extend_info": { },
  • "create_user": "string",
  • "create_time": 0,
  • "update_user": "string",
  • "update_time": 0
}

更新工具

更新走 POST 不是 PUT。 name、description、metadata_type 都是必填 ——整体覆盖,不是部分更新。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

tool_id
required
string

工具 ID。

Request Body schema: application/json
required
name
required
string
description
required
string
metadata_type
required
string (MetadataType)
Enum: "openapi" "function"

元数据类型。工具箱建成后不可更改;决定箱内工具怎么定义 (function 走 function_input,openapi 走 data)。

use_rule
string
object (GlobalParameter)

全局参数:调用该工具时固定附加的一个参数(如统一的 API Key)。 是单个对象不是数组。

object

函数定义(编辑形态,无 name / description)。

object or string

OpenAPI 文档。JSON 请求体里传文档对象(传字符串会解析失败);表单与 multipart 里是 JSON/YAML 原文文本,multipart 也可作为名为 data 的文件上传。

object

Responses

Request samples

Content type
application/json
{
  • "name": "string",
  • "description": "string",
  • "metadata_type": "openapi",
  • "use_rule": "string",
  • "global_parameters": {
    },
  • "function_input": { },
  • "data": { },
  • "extend_info": { }
}

Response samples

Content type
application/json
{
  • "box_id": "string",
  • "tool_id": "string"
}

分页查询箱内工具

列出工具箱里的工具。对已知工具箱拥有 view、public_access 或 execute 任一权限 即可读取,因为工具定义是执行时构造参数所需的元数据;顶层工具箱目录仍只按 view 过滤。

**响应的数据字段叫 tools 不是 data**,还多一个 box_id——与本服务其他 分页接口(含同模块的 /tool-box/market/tools)不一致,解析时注意。

排序字段这里可选 create_time / update_time / tool_name,默认 create_time(工具箱列表默认的是 update_time)。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

query Parameters
page
integer >= 1
Default: 1

页码,从 1 开始。

page_size
integer [ 1 .. 100 ]
Default: 10

每页数量,1–100。

sort_by
string
Default: "create_time"
Enum: "create_time" "update_time" "tool_name"

排序字段。

sort_order
string
Default: "desc"
Enum: "asc" "desc"

排序方向。

name
string

按工具名过滤。

status
string (ToolStatus)
Enum: "enabled" "disabled"

按工具启停状态过滤。

user_id
string

按创建者过滤。

all
boolean

忽略分页返回全部。

Responses

Response samples

Content type
application/json
{
  • "total": 0,
  • "page": 0,
  • "page_size": 0,
  • "total_pages": 0,
  • "has_next": true,
  • "has_prev": true,
  • "box_id": "string",
  • "tools": [
    ]
}

批量删除箱内工具

按 ID 批量删除工具箱里的工具。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

Request Body schema: application/json
required
tool_ids
required
Array of strings

要删除的工具 ID 列表。

Responses

Request samples

Content type
application/json
{
  • "tool_ids": [
    ]
}

Response samples

Content type
application/json
{
  • "box_id": "string",
  • "tool_ids": [
    ]
}

批量启停箱内工具

请求体是数组,一次改多个工具的启停。工具的状态只有 enabled / disabled 两个值——与工具箱的发布状态是两套,别混。

禁用的工具不会出现在 Agent 可用的工具列表里,但仍留在箱子中。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

Request Body schema: application/json
required
Array
tool_id
required
string
status
required
string (ToolStatus)
Enum: "enabled" "disabled"

单个工具的启停状态。与工具箱的 BizStatus 是两套,别混——工具箱已发布不 代表箱内工具都启用。

Responses

Request samples

Content type
application/json
[
  • {
    },
  • {
    }
]

Response samples

Content type
application/json
[
  • {
    }
]

调试工具

用给定参数真实调用一次工具。与 /proxy/{tool_id} 的差别只在语义与审计 ——调试面向开发期,代理面向生产调用。请求与响应结构一致。

调用主体来自 OAuth/AppKey 或受信任内部身份上下文,并且必须对具体 tool_box:{box_id} 持有 execute。拒绝或 bkn-safe 判定失败时不会调用工具。

For platform Function tools, the authenticated request credential reaches the sandbox without requiring conversation/interaction IDs or enabling Trace. The proxy endpoint below uses the same credential forwarding rules.

参数按 HTTP 的四个位置分开传:header / query / path / body。 函数工具的顶层 timeout 以秒为单位控制沙箱执行;超时时响应体的 status_code 为 504,接口本身仍返回 200。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

tool_id
required
string

工具 ID。

Request Body schema: application/json
required
timeout
integer

超时(秒)。函数工具会将其用于沙箱执行;超出代理上限时按上限执行。

object

请求头参数。

object

查询参数。

object

路径参数。

body
any

请求体。函数类工具只用这个。

Responses

Request samples

Content type
application/json
{
  • "timeout": 0,
  • "header": { },
  • "query": { },
  • "path": {
    },
  • "body": null
}

Response samples

Content type
application/json
{
  • "status_code": 0,
  • "headers": { },
  • "body": null,
  • "error": "string"
}

代理调用工具

生产调用入口:由平台代为执行工具并返回结果,调用方不必知道工具背后打的是 哪个地址。与调试接口的差别在于会走权限校验与审计日志。

调用主体来自 OAuth/AppKey 或受信任内部身份上下文,并且必须对具体 tool_box:{box_id} 持有 execute。用于知识网络 Action 时,ontology-query 还会在此前校验具体 Action Type 和数据依赖。请求体不能覆盖执行主体。 平台身份头和 trace 控制头在请求离开平台前会被移除。

返回的是被调服务的原始响应(status_code / headers / body), 不是平台自己的信封——上游返 500 时本接口仍是 200,status_code 里才是 500。 函数工具的顶层 timeout 以秒为单位控制沙箱执行,受代理最大超时配置约束; 沙箱执行超时时,信封的 status_code 为 504。

只有已发布工具箱里已启用的工具能被调用:工具箱 unpublish / offline, 或工具 disabled,都返回 400 ToolNotAvailable(details 说明是箱还是工具)。 这与调试接口不同——调试允许作者跑未发布的东西;生产调用不允许。下架一个 工具箱即刻让其全部工具停止响应本接口,不等下一次索引对账。

Function caller credentials and optional lifecycle context: both REST debug and proxy execution forward the authenticated request credential to this deployment's own Function runtime, regardless of Trace/evidence capture or whether conversation/interaction IDs are present. The Function can use bkn_osdk as the invoking caller without repeating a token in its inputs. Only a complete bkn-conversation-id / bkn-interaction-id pair is forwarded; partial lifecycle context is omitted. No MCP start/finish is required for these REST calls. Credential forwarding does not grant extra permissions.

这些值由服务端从请求本身捕获,不是工具的业务参数,不写进工具 Schema, 请求体里同名字段会被服务端捕获值覆盖。非函数工具不透传:OpenAPI 类工具 指向第三方地址,平台身份不出网。

注意随之而来的信任边界:函数代码由注册者提供,沙箱可出网,因此被调函数 能在自身环境变量里读到调用者的活令牌。只把函数工具发布给可信的注册者。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

tool_id
required
string

工具 ID。

Request Body schema: application/json
required
timeout
integer

超时(秒)。函数工具会将其用于沙箱执行;超出代理上限时按上限执行。

object

请求头参数。

object

查询参数。

object

路径参数。

body
any

请求体。函数类工具只用这个。

Responses

Request samples

Content type
application/json
{
  • "timeout": 0,
  • "header": { },
  • "query": { },
  • "path": {
    },
  • "body": null
}

Response samples

Content type
application/json
{
  • "status_code": 0,
  • "headers": { },
  • "body": null,
  • "error": "string"
}

一份 OpenAPI 文档批量建工具

「能力包」注册:给一份 OpenAPI 3.0 文档,把里面每个操作直接建成一个工具放进 工具箱,与 POST /tool-box/{box_id}/tool 走同一条建工具路径。新建的工具 **初始为 disabled**,需要再启用。

box_id 与 box_name 二选一:给 box_id 就往已有的 openapi 类工具箱 里加,box_id 为空时按 box_name 新建一个 openapi 类工具箱。两者都不给 返回 400。

部分失败是常态:只要建成至少一个工具就返回 200,failure_count 与 failures 说明哪些操作没建成;一个都没建成返回 400。

Authorizations:
OAuth2AppKey
Request Body schema: application/json
required
box_id
string

已有 openapi 类工具箱 ID。与 box_name 二选一,同时给时以它为准。

box_name
string

新建 openapi 类工具箱的名称,仅在 box_id 为空时生效。与 box_id 二选一。

box_desc
string

工具箱描述。

box_svc_url
required
string

工具箱服务地址。必填。

box_category
string
Default: "other_category"

新建工具箱的分类,取值见 category.yaml。

use_rule
string

生成的工具的使用规则。

data
required
string

OpenAPI 3.0 文档原文。必填。

object

写入每个生成工具的扩展信息。

Responses

Request samples

Content type
application/json
{
  • "box_id": "string",
  • "box_name": "string",
  • "box_desc": "string",
  • "box_svc_url": "string",
  • "box_category": "other_category",
  • "use_rule": "string",
  • "data": "string",
  • "extend_info": { }
}

Response samples

Content type
application/json
{
  • "box_id": "string",
  • "tool_ids": [
    ],
  • "links": [
    ],
  • "failure_count": 0,
  • "failures": [
    ]
}

工具箱市场列表

已发布工具箱的列表。过滤条件比工作区列表少了 status 与 metadata_type。

Authorizations:
OAuth2AppKey
query Parameters
page
integer >= 1
Default: 1

页码,从 1 开始。

page_size
integer [ 1 .. 100 ]
Default: 10

每页数量,1–100。

sort_by
string
Default: "update_time"
Enum: "create_time" "update_time" "name"

排序字段。

sort_order
string
Default: "desc"
Enum: "asc" "desc"

排序方向。

name
string

按名称过滤。

category
string

按分类过滤。

create_user
string

按创建人过滤。

release_user
string

按发布人过滤。

all
boolean

忽略分页返回全部。

Responses

Response samples

Content type
application/json
{
  • "total": 0,
  • "page": 0,
  • "page_size": 0,
  • "total_pages": 0,
  • "has_next": true,
  • "has_prev": true,
  • "data": [
    ]
}

市场工具搜索

跨工具箱按名称搜工具。

tool_name 是必填的——不传直接 400 (AgentOperatorIntegration.BadRequest.ValidationRequired)。这不是「列出 全部市场工具」的接口,是「按名字找工具」。

响应的数据字段是 data(与同模块 /tool-box/{box_id}/tools/list 的 tools 不同)。

Authorizations:
OAuth2AppKey
query Parameters
tool_name
required
string

工具名称。必填,不传返回 400。

page
integer >= 1
Default: 1

页码,从 1 开始。

page_size
integer [ 1 .. 100 ]
Default: 10

每页数量,1–100。

sort_by
string
Default: "update_time"
Enum: "create_time" "update_time" "tool_name"

排序字段。

sort_order
string
Default: "desc"
Enum: "asc" "desc"

排序方向。

status
string (ToolStatus)
Enum: "enabled" "disabled"

按工具启停状态过滤。

all
boolean

忽略分页返回全部。

Responses

Response samples

Content type
application/json
{
  • "total": 0,
  • "page": 0,
  • "page_size": 0,
  • "total_pages": 0,
  • "has_next": true,
  • "has_prev": true,
  • "data": [
    ]
}

工具箱市场详情

市场视角的工具箱详情,结构与 GET /tool-box/{box_id} 一致。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string

工具箱 ID。

Responses

Response samples

Content type
application/json
{
  • "box_id": "string",
  • "box_name": "string",
  • "box_desc": "string",
  • "box_svc_url": "string",
  • "metadata_type": "openapi",
  • "status": "unpublish",
  • "category_type": "string",
  • "category_name": "string",
  • "is_internal": true,
  • "source": "string",
  • "tools": [
    ],
  • "create_user": "string",
  • "create_time": 0,
  • "update_user": "string",
  • "update_time": 0,
  • "release_user": "string",
  • "release_time": 0
}

批量取已发布工具箱的指定字段

与 MCP 的 /mcp/market/batch/{mcp_ids}/{fields} 同一套路子:两个参数都走 路径、都是逗号分隔。注意这里的路径段名叫 box_id,但接受的是 ID 列表(服务端字段就叫 BoxIDs)。

响应是按 fields 投影后的对象数组,未选中的字段不出现。

Authorizations:
OAuth2AppKey
path Parameters
box_id
required
string
Example: 3f2a1c58-7b4e-4d19-9a06-2e5c8d71bf43,ccf29df2-f43d-414a-b644-db7c186cda77

工具箱 ID 列表,逗号分隔。参数名是单数,实际收列表。

fields
required
string
Example: box_id,box_name,status

要取的字段名,逗号分隔。

Responses

Response samples

Content type
application/json
[
  • {
    }
]