Directives 模块
更新时间:2026-11-03
指令接口
本文介绍指令相关的 5 个接口。创建和管理 directive(指令),约束记忆处理和推理时的行为。
调用说明
- 接入地址:
https://cloud.memory.bj.baidubce.com/api,下文路径直接拼接在该地址后。 - 请求头:
Authorization: Bearer <token>必填;有 JSON 请求体时需携带Content-Type: application/json。 - 错误码、异步操作和
operationId的说明见 API 简介。
接口列表
| 接口 | 方法 | 路径 |
|---|---|---|
| 列出 directive | GET |
/v1/default/banks/{bank_id}/directives |
| 创建 directive | POST |
/v1/default/banks/{bank_id}/directives |
| 获取 directive | GET |
/v1/default/banks/{bank_id}/directives/{directive_id} |
| 更新 directive | PATCH |
/v1/default/banks/{bank_id}/directives/{directive_id} |
| 删除 directive | DELETE |
/v1/default/banks/{bank_id}/directives/{directive_id} |
列出 directive
GET /v1/default/banks/{bank_id}/directives
列出注入 prompt 的硬规则。
参数
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
bank_id |
path | string |
是 | Bank 的唯一标识符。 |
tags |
query | array<string>? |
否 | 按 tags 筛选。 |
tags_match |
query | "any" \| "all" \| "exact" |
否 | tag 的匹配方式;默认值:"any" |
active_only |
query | boolean |
否 | 仅返回启用的 directives;默认值:true |
limit |
query | integer |
否 | 默认值:100;取值范围:1–1000 |
offset |
query | integer |
否 | 默认值:0;最小值:0 |
请求头
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
Authorization |
header | string |
是 | Bearer token。 |
响应
- 状态码:
200— 成功响应 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
items |
array<DirectiveResponse> |
是 | 结果项目列表。 |
items[] · DirectiveResponse
数据结构 DirectiveResponse:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
id |
string |
是 | 资源的唯一标识符。 |
bank_id |
string |
是 | 所属 Bank 的唯一标识符。 |
name |
string |
是 | 名称。 |
content |
string |
是 | 资源的正文内容;对 directive/page 等资源含其可编辑文本。 |
priority |
integer |
否 | 默认值:0 |
is_active |
boolean |
否 | 默认值:true |
tags |
array<string> |
否 | 默认值:[] |
created_at |
string? |
否 | 创建时间。 |
updated_at |
string? |
否 | 最后更新时间。 |
响应示例
JSON
1{
2 "items": [
3 {
4 "id": "string",
5 "bank_id": "string",
6 "name": "string",
7 "content": "string",
8 "priority": 0,
9 "is_active": true,
10 "tags": [],
11 "created_at": "string",
12 "updated_at": "string"
13 }
14 ]
15}
响应
- 状态码:
422— 校验错误 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
detail |
array<ValidationError> |
否 | 详细信息或校验错误列表。 |
detail[] · ValidationError
数据结构 ValidationError:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
loc |
array<string \| integer> |
是 | 发生校验错误的位置路径;数组元素可以是字段名或索引。 |
msg |
string |
是 | 错误消息或状态消息。 |
type |
string |
是 | 对象或错误的类型。 |
input |
any |
否 | 触发校验的原始输入值。 |
ctx |
Context |
否 | 错误上下文信息。 |
响应示例
JSON
1{
2 "detail": [
3 {
4 "loc": [],
5 "msg": "string",
6 "type": "string",
7 "input": null,
8 "ctx": {}
9 }
10 ]
11}
operationId=list_directives
创建 directive
POST /v1/default/banks/{bank_id}/directives
创建一条将注入 prompt 的硬规则。
参数
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
bank_id |
path | string |
是 | Bank 的唯一标识符。 |
请求头
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
Authorization |
header | string |
是 | Bearer token。 |
Content-Type |
header | string |
是 | 固定application/json |
请求体
- 格式:
application/json - 必填:是
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
name |
string |
是 | directive 的可读名称。 |
content |
string |
是 | 要注入 prompts 的 directive 文本。 |
priority |
integer |
否 | 优先级更高的 directives 会优先注入;默认值:0 |
is_active |
boolean |
否 | 此 directive 是否启用;默认值:true |
tags |
array<string> |
否 | 用于筛选的标签;默认值:[] |
请求示例
JSON
1{
2 "name": "string",
3 "content": "string",
4 "priority": 0,
5 "is_active": true,
6 "tags": []
7}
响应
- 状态码:
200— 成功响应 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
id |
string |
是 | 资源的唯一标识符。 |
bank_id |
string |
是 | 所属 Bank 的唯一标识符。 |
name |
string |
是 | 名称。 |
content |
string |
是 | 资源的正文内容;对 directive/page 等资源含其可编辑文本。 |
priority |
integer |
否 | 默认值:0 |
is_active |
boolean |
否 | 默认值:true |
tags |
array<string> |
否 | 默认值:[] |
created_at |
string? |
否 | 创建时间。 |
updated_at |
string? |
否 | 最后更新时间。 |
响应示例
JSON
1{
2 "id": "string",
3 "bank_id": "string",
4 "name": "string",
5 "content": "string",
6 "priority": 0,
7 "is_active": true,
8 "tags": [],
9 "created_at": "string",
10 "updated_at": "string"
11}
响应
- 状态码:
422— 校验错误 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
detail |
array<ValidationError> |
否 | 详细信息或校验错误列表。 |
detail[] · ValidationError
数据结构 ValidationError:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
loc |
array<string \| integer> |
是 | 发生校验错误的位置路径;数组元素可以是字段名或索引。 |
msg |
string |
是 | 错误消息或状态消息。 |
type |
string |
是 | 对象或错误的类型。 |
input |
any |
否 | 触发校验的原始输入值。 |
ctx |
Context |
否 | 错误上下文信息。 |
响应示例
JSON
1{
2 "detail": [
3 {
4 "loc": [],
5 "msg": "string",
6 "type": "string",
7 "input": null,
8 "ctx": {}
9 }
10 ]
11}
operationId=create_directive
获取 directive
GET /v1/default/banks/{bank_id}/directives/{directive_id}
按 ID 获取指定 directive。
参数
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
bank_id |
path | string |
是 | Bank 的唯一标识符。 |
directive_id |
path | string |
是 | Directive 的唯一 ID。 |
请求头
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
Authorization |
header | string |
是 | Bearer token。 |
响应
- 状态码:
200— 成功响应 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
id |
string |
是 | 资源的唯一标识符。 |
bank_id |
string |
是 | 所属 Bank 的唯一标识符。 |
name |
string |
是 | 名称。 |
content |
string |
是 | 资源的正文内容;对 directive/page 等资源含其可编辑文本。 |
priority |
integer |
否 | 默认值:0 |
is_active |
boolean |
否 | 默认值:true |
tags |
array<string> |
否 | 默认值:[] |
created_at |
string? |
否 | 创建时间。 |
updated_at |
string? |
否 | 最后更新时间。 |
响应示例
JSON
1{
2 "id": "string",
3 "bank_id": "string",
4 "name": "string",
5 "content": "string",
6 "priority": 0,
7 "is_active": true,
8 "tags": [],
9 "created_at": "string",
10 "updated_at": "string"
11}
响应
- 状态码:
422— 校验错误 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
detail |
array<ValidationError> |
否 | 详细信息或校验错误列表。 |
detail[] · ValidationError
数据结构 ValidationError:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
loc |
array<string \| integer> |
是 | 发生校验错误的位置路径;数组元素可以是字段名或索引。 |
msg |
string |
是 | 错误消息或状态消息。 |
type |
string |
是 | 对象或错误的类型。 |
input |
any |
否 | 触发校验的原始输入值。 |
ctx |
Context |
否 | 错误上下文信息。 |
响应示例
JSON
1{
2 "detail": [
3 {
4 "loc": [],
5 "msg": "string",
6 "type": "string",
7 "input": null,
8 "ctx": {}
9 }
10 ]
11}
operationId=get_directive
更新 directive
PATCH /v1/default/banks/{bank_id}/directives/{directive_id}
更新 directive 属性。
参数
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
bank_id |
path | string |
是 | Bank 的唯一标识符。 |
directive_id |
path | string |
是 | Directive 的唯一 ID。 |
请求头
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
Authorization |
header | string |
是 | Bearer token。 |
Content-Type |
header | string |
是 | 固定application/json |
请求体
- 格式:
application/json - 必填:是
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
name |
string? |
否 | 新的名称。 |
content |
string? |
否 | 新的内容。 |
priority |
integer? |
否 | 新的优先级。 |
is_active |
boolean? |
否 | 新的启用状态。 |
tags |
array<string>? |
否 | 新的 tags。 |
请求示例
JSON
1{
2 "name": "string",
3 "content": "string",
4 "priority": 0,
5 "is_active": false,
6 "tags": [
7 "string"
8 ]
9}
响应
- 状态码:
200— 成功响应 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
id |
string |
是 | 资源的唯一标识符。 |
bank_id |
string |
是 | 所属 Bank 的唯一标识符。 |
name |
string |
是 | 名称。 |
content |
string |
是 | 资源的正文内容;对 directive/page 等资源含其可编辑文本。 |
priority |
integer |
否 | 默认值:0 |
is_active |
boolean |
否 | 默认值:true |
tags |
array<string> |
否 | 默认值:[] |
created_at |
string? |
否 | 创建时间。 |
updated_at |
string? |
否 | 最后更新时间。 |
响应示例
JSON
1{
2 "id": "string",
3 "bank_id": "string",
4 "name": "string",
5 "content": "string",
6 "priority": 0,
7 "is_active": true,
8 "tags": [],
9 "created_at": "string",
10 "updated_at": "string"
11}
响应
- 状态码:
422— 校验错误 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
detail |
array<ValidationError> |
否 | 详细信息或校验错误列表。 |
detail[] · ValidationError
数据结构 ValidationError:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
loc |
array<string \| integer> |
是 | 发生校验错误的位置路径;数组元素可以是字段名或索引。 |
msg |
string |
是 | 错误消息或状态消息。 |
type |
string |
是 | 对象或错误的类型。 |
input |
any |
否 | 触发校验的原始输入值。 |
ctx |
Context |
否 | 错误上下文信息。 |
响应示例
JSON
1{
2 "detail": [
3 {
4 "loc": [],
5 "msg": "string",
6 "type": "string",
7 "input": null,
8 "ctx": {}
9 }
10 ]
11}
operationId=update_directive
删除 directive
DELETE /v1/default/banks/{bank_id}/directives/{directive_id}
删除 directive。
参数
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
bank_id |
path | string |
是 | Bank 的唯一标识符。 |
directive_id |
path | string |
是 | Directive 的唯一 ID。 |
请求头
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
Authorization |
header | string |
是 | Bearer token。 |
响应
- 状态码:
200— 成功响应 - 格式:
application/json
无展开字段(标量、自由 object 或未声明 properties)
响应
- 状态码:
422— 校验错误 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
detail |
array<ValidationError> |
否 | 详细信息或校验错误列表。 |
detail[] · ValidationError
数据结构 ValidationError:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
loc |
array<string \| integer> |
是 | 发生校验错误的位置路径;数组元素可以是字段名或索引。 |
msg |
string |
是 | 错误消息或状态消息。 |
type |
string |
是 | 对象或错误的类型。 |
input |
any |
否 | 触发校验的原始输入值。 |
ctx |
Context |
否 | 错误上下文信息。 |
响应示例
JSON
1{
2 "detail": [
3 {
4 "loc": [],
5 "msg": "string",
6 "type": "string",
7 "input": null,
8 "ctx": {}
9 }
10 ]
11}
operationId=delete_directive
评价此篇文章
