Bank Templates 模块
Bank 模板接口
本文介绍 Bank 模板相关的 3 个接口。获取 Bank 模板的 JSON Schema,导出和导入 Bank 模板,便于在不同环境间复用配置。
调用说明
- 接入地址:
https://cloud.memory.bj.baidubce.com/api,下文路径直接拼接在该地址后。 - 请求头:
Authorization: Bearer <token>必填;有 JSON 请求体时需携带Content-Type: application/json。 - 错误码、异步操作和
operationId的说明见 API 简介。
接口列表
| 接口 | 方法 | 路径 |
|---|---|---|
| 获取 Bank 模板 JSON Schema | GET |
/v1/bank-template-schema |
| 导出 Bank 模板 | GET |
/v1/default/banks/{bank_id}/export |
| 导入 Bank 模板 | POST |
/v1/default/banks/{bank_id}/import |
获取 Bank 模板 JSON Schema
GET /v1/bank-template-schema
返回 bank template manifest 格式的 JSON Schema。导入前可用它校验 template manifest。
请求头
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
Authorization |
header | string |
是 | Bearer token。 |
响应
- 状态码:
200— 成功响应 - 格式:
application/json
无展开字段(标量、自由 object 或未声明 properties)
operationId=get_bank_template_schema
导出 Bank 模板
GET /v1/default/banks/{bank_id}/export
将 Bank 当前配置、mental models 和 directives 导出为 template manifest。导出的 manifest 可导入其他 Bank 以复现该配置。
参数
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
bank_id |
path | string |
是 | Bank 的唯一标识符。 |
请求头
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
Authorization |
header | string |
是 | Bearer token。 |
响应
- 状态码:
200— 成功响应 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
version |
string |
是 | Manifest schema 版本(当前为 1)。 |
bank |
BankTemplateConfig? |
否 | 要应用的 Bank 配置。省略则保持配置不变。 |
mental_models |
array<BankTemplateMentalModel>? |
否 | 要创建或更新的 mental models(按 id 匹配)。省略则保持不变。 |
directives |
array<BankTemplateDirective>? |
否 | 要创建或更新的 directives(按名称匹配)。省略则保持不变。 |
bank · BankTemplateConfig
数据结构 BankTemplateConfig:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
reflect_mission |
string? |
否 | Reflect 异步操作的 mission/context |
retain_mission |
string? |
否 | 控制 retain 抽取的内容 |
retain_extraction_mode |
string? |
否 | Fact 抽取模式:'concise'(默认)、'verbose'、'custom'、'verbatim' 或 'chunks' |
retain_custom_instructions |
string? |
否 | 自定义抽取 prompt(mode='custom' 时生效) |
retain_chunk_size |
integer? |
否 | 每个内容 chunk 的目标最大字符数 |
retain_structured_chunk_size |
integer? |
否 | 单条 JSONL 行或单轮对话保持完整时允许的最大字符数;未设置时默认为 retain_chunk_size |
enable_observations |
boolean? |
否 | 是否进行 observation consolidation |
enable_auto_consolidation |
boolean? |
否 | 是否在 Retain 后自动执行 observation consolidation。 |
enable_temporal_retrieval |
boolean? |
否 | 是否在 Recall 中启用时序检索及日期感知查询。 |
enable_graph_retrieval |
boolean? |
否 | 是否在 Recall 中启用 entity/link 图检索。 |
enable_reranking |
boolean? |
否 | 是否在 Recall 中启用 cross-encoder reranker。 |
entity_labels |
array<LabelGroup-Output>? |
否 | Entity label 受控词表。 |
consolidation_max_memories_per_round |
integer? |
否 | 每轮 consolidation 处理的 memory 最大数量。 |
consolidation_llm_parallelism |
integer? |
否 | Consolidation LLM 调用的最大并发数。 |
recall_include_chunks |
boolean? |
否 | Recall 是否默认包含原始 chunk 文本。 |
recall_max_tokens |
integer? |
否 | Recall 返回 facts 的默认 token budget。 |
recall_chunks_max_tokens |
integer? |
否 | Recall 返回原始 chunks 的默认 token budget。 |
memory_defense |
object? |
否 | Memory Defense 配置。 |
observations_mission |
string? |
否 | 控制合成的内容 |
disposition_skepticism |
integer? |
否 | Skepticism 特征(1-5);取值范围:1–5 |
disposition_literalism |
integer? |
否 | Literalism 特征(1-5);取值范围:1–5 |
disposition_empathy |
integer? |
否 | Empathy 特征(1-5);取值范围:1–5 |
entities_allow_free_form |
boolean? |
否 | 是否允许词表之外的 entities |
retain_default_strategy |
string? |
否 | 默认 retain strategy 的名称(retain_strategies map 中的键) |
retain_strategies |
object? |
否 | retain strategy 名称到各 strategy 配置字典的映射 |
retain_chunk_batch_size |
integer? |
否 | 每个流式批次的最大 chunks 数(0 表示禁用批处理) |
mcp_enabled_tools |
array<string>? |
否 | 此 bank 的 MCP tool allowlist(null 表示所有 tools) |
consolidation_llm_batch_size |
integer? |
否 | observation consolidation 的 LLM 批次大小 |
consolidation_source_facts_max_tokens |
integer? |
否 | 每个 consolidation 批次的源 facts 最大 token 数 |
consolidation_source_facts_max_tokens_per_observation |
integer? |
否 | 每个 observation 的源 facts 最大 token 数 |
max_observations_per_scope |
integer? |
否 | 每个 consolidation scope 保留的最大 observations 数 |
observation_scope_limits |
array<object>? |
否 | 按 scope 覆盖 maxobservations_per_scope:[{"scope": ["run*", "shared"], "limit": 1}]。每个 scope 是 fnmatch tag-globs 列表;consolidation scope 要求精确覆盖(每个 tag 都匹配某个 glob,且每个 glob 都匹配某个 tag)。按列表顺序使用第一条匹配规则;未匹配的 scope 回退到 max_observations_per_scope。 |
reflect_source_facts_max_tokens |
integer? |
否 | 每次 Reflect 调用的源 facts 最大 token 数 |
llm_gemini_safety_settings |
array<any>? |
否 | 每个 bank 的 Gemini/VertexAI 安全过滤设置 |
recall_budget_function |
string? |
否 | Recall budget 映射函数:fixed 或 adaptive。 |
recall_budget_fixed_low |
integer? |
否 | budget=low 时固定的 thinking_budget(function=fixed)。 |
recall_budget_fixed_mid |
integer? |
否 | budget=mid 时固定的 thinking_budget(function=fixed)。 |
recall_budget_fixed_high |
integer? |
否 | budget=high 时固定的 thinking_budget(function=fixed)。 |
recall_budget_adaptive_low |
number? |
否 | budget=low 时 max_tokens 的比例(function=adaptive)。 |
recall_budget_adaptive_mid |
number? |
否 | budget=mid 时 max_tokens 的比例(function=adaptive)。 |
recall_budget_adaptive_high |
number? |
否 | budget=high 时 max_tokens 的比例(function=adaptive)。 |
recall_budget_min |
integer? |
否 | adaptive 函数的下限(裁剪后)。 |
recall_budget_max |
integer? |
否 | adaptive 函数的上限(裁剪后)。 |
audit_log_enabled |
boolean? |
否 | 是否为此 Bank 启用审计日志(覆盖服务器默认值)。 |
store_document_text |
boolean? |
否 | 是否持久化原始源文本(documents.original_text / chunks.chunk_text)。设置为 false 时仅保留派生 facts。 |
config.entity_labels[] · LabelGroup-Output
数据结构 LabelGroup-Output:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
key |
string |
是 | 字段键名。 |
description |
string |
否 | 字段说明;默认值:"" |
type |
"value" \| "multi-values" \| "text" \| "map" |
否 | 字段类型;默认值:"value" |
optional |
boolean |
否 | 是否为可选字段;默认值:false |
tag |
boolean |
否 | 是否将字段值用作 tag;默认值:false |
values |
array<LabelValue> |
否 | 允许的 label 值;默认值:[] |
fields |
map<string, MapField-Output> |
否 | 子字段定义;默认值:{} |
values[] · LabelValue
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
value |
string |
是 | Label 值。 |
description |
string |
否 | Label 说明;默认值:"" |
mental_models[] · BankTemplateMentalModel
数据结构 BankTemplateMentalModel:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
id |
string |
是 | Mental model 的唯一 ID(小写字母数字和连字符)。 |
name |
string |
是 | Mental model 的可读名称。 |
source_query |
string |
是 | 用于生成内容的查询。 |
tags |
array<string> |
否 | 用于限定可见范围的标签;默认值:[] |
max_tokens |
integer |
否 | 生成内容的最大 token 数;默认值:2048;取值范围:256–8192 |
trigger |
MentalModelTrigger-Output |
否 | 触发器设置;默认值:{} |
trigger · MentalModelTrigger-Output
数据结构 MentalModelTrigger-Output:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
mode |
"full" \| "delta" |
否 | 刷新模式。full(默认)每次刷新都从头生成 mental model 内容;delta 在现有内容上进行局部编辑,逐字节保留未变化的章节,移除过时内容并加入新内容。如果 mental model 尚无内容,或 source_query 自上次刷新后发生变化,delta 会自动回退为完整生成;默认值:"full" |
response_schema |
object? |
否 | 用于结构化输出的可选 JSON Schema。 |
keep_trace |
boolean |
否 | 是否保留最近一次 mental model 刷新的执行 trace;默认值:false |
refresh_after_consolidation |
boolean |
否 | 为 true 时,在 observations consolidation 后刷新此 mental model(实时模式);默认值:false |
refresh_cron |
string? |
否 | 用于按固定计划刷新此 mental model 的 cron 表达式(UTC,标准 5 字段语法,例如0 3 * * * 表示每天 UTC 03:00)。与 refresh_after_consolidation 互斥:model 只能在 consolidation 后刷新或按 cron 刷新,不能同时启用。计划刷新仅在 model 已过期时执行(自上次刷新后 scope 内出现新 memories);没有变化时跳过,避免浪费 LLM 调用。null 表示不设置计划。 |
fact_types |
array<"world" \| "experience" \| "observation">? |
否 | 筛选 Reflect 时检索的 fact type。null 表示全部类型(world、experience、observation)。 |
exclude_mental_models |
boolean |
否 | 为 true 时,从 Reflect 循环中排除所有 mental models(跳过search_mental_models 工具);默认值:false |
exclude_mental_model_ids |
array<string>? |
否 | 按 ID 从 Reflect 循环中排除指定 mental models。 |
tags_match |
"any" \| "all" \| "any_strict" \| "all_strict" \| "exact"? |
否 | 覆盖 refresh 时 model tags 筛选 memories 的方式。未设置时,有 tags 的 model 默认为 all_strict(用于安全隔离),无 tags 的 model 默认为 any。设置为 any 可在 refresh 时同时包含无标签和有标签 memories。 |
tag_groups |
array<TagGroupLeaf \| TagGroupAnd-Output \| TagGroupOr-Output \| TagGroupNot-Output>? |
否 | Refresh 时使用的复合布尔 tag 表达式,用于替代 model 自身的 tags。设置后,这些 tag groups 会传给 Reflect,model 的扁平 tags 不再用于筛选。支持嵌套 and/or/not 表达式,以实现复杂的 tag scope。 |
include_chunks |
boolean? |
否 | 覆盖 refresh 内部 Recall 是否返回原始 chunk 文本。null 表示使用 Bank/全局 配置默认值(recall_include_chunks)。 |
recall_max_tokens |
integer? |
否 | 覆盖 refresh 内部 Recall 返回 facts 的 token budget。null 表示使用 Bank/全局 配置默认值(recall_max_tokens)。 |
recall_chunks_max_tokens |
integer? |
否 | 覆盖 refresh 内部 Recall 返回原始 chunks 的 token budget。null 表示使用 Bank/全局 配置默认值(recall_chunks_max_tokens)。 |
directives[] · BankTemplateDirective
数据结构 BankTemplateDirective:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
name |
string |
是 | directive 的可读名称。 (used as match key on re-import) |
content |
string |
是 | 要注入 prompts 的 directive 文本。 |
priority |
integer |
否 | 优先级更高的 directive 会优先注入;默认值:0 |
is_active |
boolean |
否 | 此 directive 是否启用;默认值:true |
tags |
array<string> |
否 | 用于筛选的标签;默认值:[] |
响应示例
1{
2 "bank": {
3 "disposition_empathy": 5,
4 "enable_observations": true,
5 "reflect_mission": "You are helping a support agent remember customer interactions.",
6 "retain_mission": "Extract customer issues, resolutions, and sentiment."
7 },
8 "directives": [
9 {
10 "content": "Always respond with empathy and understanding.",
11 "name": "Always be empathetic",
12 "priority": 10
13 }
14 ],
15 "mental_models": [
16 {
17 "id": "sentiment-overview",
18 "name": "Customer Sentiment Overview",
19 "source_query": "What is the overall sentiment trend?",
20 "trigger": {
21 "refresh_after_consolidation": true
22 }
23 }
24 ],
25 "version": "1"
26}
响应
- 状态码:
422— 校验错误 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
detail |
array<ValidationError> |
否 | 详细信息或校验错误列表。 |
detail[] · ValidationError
数据结构 ValidationError:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
loc |
array<string \| integer> |
是 | 发生校验错误的位置路径;数组元素可以是字段名或索引。 |
msg |
string |
是 | 错误消息或状态消息。 |
type |
string |
是 | 对象或错误的类型。 |
input |
any |
否 | 触发校验的原始输入值。 |
ctx |
Context |
否 | 错误上下文信息。 |
响应示例
1{
2 "detail": [
3 {
4 "loc": [],
5 "msg": "string",
6 "type": "string",
7 "input": null,
8 "ctx": {}
9 }
10 ]
11}
operationId=export_bank_template
导入 Bank 模板
POST /v1/default/banks/{bank_id}/import
导入 Bank template manifest,以创建或更新 Bank 配置、mental models 和 directives。Bank 不存在时会创建。配置字段作为 Bank 级覆盖项应用。Mental models 按 id 匹配,directives 按名称匹配;已有项更新,新项创建。使用 dry_run=true 可在不应用变更的情况下校验 manifest。
参数
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
bank_id |
path | string |
是 | Bank 的唯一标识符。 |
dry_run |
query | boolean |
否 | 仅校验,不应用更改;默认值:false |
请求头
| 名称 | In | 类型 | 必填 | 说明 |
|---|---|---|---|---|
Authorization |
header | string |
是 | Bearer token。 |
响应
- 状态码:
200— 成功响应 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
bank_id |
string |
是 | 被导入的 Bank。 |
config_applied |
boolean |
是 | Bank 配置是否已更新。 |
mental_models_created |
array<string> |
否 | IDs of newly created mental models;默认值:[] |
mental_models_updated |
array<string> |
否 | IDs of updated mental models;默认值:[] |
directives_created |
array<string> |
否 | Names of newly created directives;默认值:[] |
directives_updated |
array<string> |
否 | Names of updated directives;默认值:[] |
operation_ids |
array<string> |
否 | Operation IDs for mental model content generation (async);默认值:[] |
dry_run |
boolean |
否 | 此次运行是否仅执行校验;默认值:false |
响应示例
1{
2 "bank_id": "string",
3 "config_applied": false,
4 "mental_models_created": [],
5 "mental_models_updated": [],
6 "directives_created": [],
7 "directives_updated": [],
8 "operation_ids": [],
9 "dry_run": false
10}
响应
- 状态码:
422— 校验错误 - 格式:
application/json
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
detail |
array<ValidationError> |
否 | 详细信息或校验错误列表。 |
detail[] · ValidationError
数据结构 ValidationError:
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
loc |
array<string \| integer> |
是 | 发生校验错误的位置路径;数组元素可以是字段名或索引。 |
msg |
string |
是 | 错误消息或状态消息。 |
type |
string |
是 | 对象或错误的类型。 |
input |
any |
否 | 触发校验的原始输入值。 |
ctx |
Context |
否 | 错误上下文信息。 |
响应示例
1{
2 "detail": [
3 {
4 "loc": [],
5 "msg": "string",
6 "type": "string",
7 "input": null,
8 "ctx": {}
9 }
10 ]
11}
operationId=import_bank_template
评价此篇文章
