AgentbaseDocs
文档目录

经验(Experiences)与技能(Skills)知识蒸馏

功能概述与核心场景

在企业级智能体(Agent)生产体系中,传统的陈述性记忆(Declarative Memory,如单条事实 fact 和用户偏好 preference)只能回答“用户是谁、系统当前配置是什么”,却无法回答“当遇到某类复杂生产故障时,应该按照什么方法论和步骤调用工具解决问题”。随着客服与运维智能体每天处理成百上千次多轮工单对话与工具执行(Tool Execution Trajectories),如果不能将成功排障的操作轨迹沉淀为程序性知识(Procedural Knowledge),智能体在下次遇到同类故障时仍需从零试错。

Agentbase Memory(v2.10.0)提供原生的经验(Experiences)与技能(Skills)知识蒸馏(Knowledge Distillation)能力。系统通过可编排的**七步知识蒸馏流水线(distillation Pipeline)**,驱动 DashScope 对话推理模型(dashscope-prod 下的 qwen-plus)与 1024 维稠密向量模型(text-embedding-v3),自动将原始会话消息(messages)和工具调用事件轨迹(toolEvents)转化为两类高度结构化的程序性知识资产:

在 Agentbase 企业智能中台(组织 ID:69c6d1aa00062e6bb60)的标杆项目 **企业智能客服与知识中台**(项目 ID:enterprise-ai-hub-210,基于 OceanBase Shared V2 存储模式)中,运维团队将 VIP 架构师 user_zhangwei_001 与一线工程师 user_lina_002 处置 OceanBase 向量内存不足 (-4013)、AI 网关 429 限流自动故障转移 等真实工单的对话与工具轨迹提交蒸馏(如生产蒸馏任务 dst_3e5b09f456c5d5c332507ec1dbe3eb6d 与 dst_adc2cfda21c940fb5d5e4a3263ae56f9),实现了跨会话、跨用户的排障智慧自动复用。


核心概念与架构

Agentbase Memory 的知识蒸馏引擎通过七步标准流水线(7-Step Distillation Pipeline)串联证据接收、技能抽取与合并、经验抽取与关联、安全质量校验及落库投影,如下图所示:

flowchart TB
    subgraph InputPlane["输入证据层 (POST /v1/memory/memories/distillations)"]
        RawEvidence["原始执行证据载荷\n• messages (user / assistant / system / tool)\n• toolEvents (工具调用名称、入参、出参、耗时与状态)\n• scope (user / agent / project) + verifiedSuccess"]
        ExecMode{"执行等待模式 (mode)"}
        AsyncMode["mode = async\n入队后立即返回 HTTP 202 + distillationId"]
        WaitMode["mode = wait (最长等待 20s)\n20s 内终态返回 HTTP 200;超时返回 202 + waitTimedOut:true"]
        RawEvidence --> ExecMode
        ExecMode --> AsyncMode
        ExecMode --> WaitMode
    end

    subgraph SevenStepPipeline["七步知识蒸馏流水线 (scenario = distillation)"]
        S1["Step 1: receive (接收与有界校验)\n校验 messages 与 toolEvents (受 maxToolEvents 限制)\n冻结不可变 L0 Source 证据链"]
        S2["Step 2: skill_extraction (技能候选抽取)\n调用 qwen-plus 提炼标准化多步 SOP\n(name / triggerConditions / steps[] / parameters / Verification)"]
        S3["Step 3: skill_merge (存量技能召回与合并)\n向量召回 Top 1..20 相似技能 (mergeThreshold)\n决策执行 ADD / MERGE / SKIP"]
        S4["Step 4: experience_extraction (排障经验抽取)\n提炼情境案例 (scenario / problem / action / outcome / lesson)\n并自动建立对本次产出 Skill 的 dependencies 引用"]
        S5["Step 5: experience_merge (存量经验召回与合并)\n向量召回相似存量 Experience\n决策执行合并更新 (累加独立会话证据) 或新增"]
        S6["Step 6: validation (必选质量与安全校验节点)\n校验步骤自洽性、过滤低置信度条目、拦截含敏感凭据内容"]
        S7["Step 7: knowledge_operation (知识持久化与向量投影)\n写入 OceanBase Shared V2 知识表并构建 text-embedding-v3 1024维索引"]

        S1 --> S2 --> S3 --> S4 --> S5 --> S6 --> S7
    end

    subgraph LifecycleGate["生命周期状态流转与检索消费"]
        Gate{"激活策略门禁\nevolution.requireConfirmation\n& evolution.activation"}
        Shadow["候选观察态 (shadow)\n进入待确认队列 (/knowledge/reviews) 或继续积累多会话证据"]
        Active["生效态 (active)\n立即可通过 /experiences/search、/skills/search 与 /recall 召回"]
        Forgotten["已遗忘态 (forgotten)\n调用 DELETE 停止线上复用"]

        S7 --> Gate
        Gate -->|"requireConfirmation=true 或未达激活阈值"| Shadow
        Gate -->|"requireConfirmation=false 且满足激活门槛"| Active
        Shadow -->|"管理员批准 (approve) 或证据达标"| Active
        Active -->|"DELETE 遗忘"| Forgotten
    end

    AsyncMode --> S1
    WaitMode --> S1

1. Experience(经验)vs Skill(技能)结构化模型深度对比

虽然 Experience 与 Skill 同属 L1 程序性知识层(共享 knowledgeId 命名体系与不可变修订版本 revisionId),但二者在认知定位、结构化 Schema 与消费方式上职责分明:

对比维度排障经验(Experience)标准化技能(Skill)
核心认知定位情境化案例与避坑指南(Case-Based Reasoning):回答“在什么业务背景和故障现象下,为什么某做法有效或失败,有哪些经验教训”。可执行的标准作业程序(Standard Operating Procedure, SOP):回答“当触发某条件时,第一步查什么、第二步调什么工具、参数怎么填、怎么验证恢复”。
结构化核心字段- title:经验标题(如 "OceanBase Shared V2 向量索引构建内存不足 (-4013) 应急处置经验")<br>- scenario:业务与技术背景情境<br>- problem:具体报错现象、症状与根因定位<br>- action:实际采取的排障或调优措施<br>- outcome:处置后的业务恢复结果与量化指标<br>- lesson:可迁移的核心洞察与避坑警示(insights / lesson)<br>- tags:领域分类标签数组<br>- confidence:模型评估置信度(0.0 ~ 1.0)<br>- scope:归属范围(user / agent / project)- name:技能标准名称(如 "ob_vector_memory_limit_expansion_sop")<br>- description:技能目标与适用边界综述<br>- triggerConditions:触发该技能的明确前提条件或错误码匹配规则(triggers)<br>- steps[]:有序执行步骤数组(每步含序号、动作指令、预期工具调用与判断分支)<br>- parameters:步骤所需的参数模板与变量约束(inputs)<br>- Verification:执行完成后的验收检查标准与回退预案<br>- dependencies:依赖的前置技能、工具或权限列表<br>- scope:归属范围(user / agent / project)
相互引用关系一条 Experience 可以关联引用本次或存量产出的 Skill(当所依赖的 Skill 尚未被批准激活时,会触发 skill_dependency_not_approved 保护)。Skill 在蒸馏流水线中先于 Experience 抽取(Step 2 & 3),以便后续 Experience(Step 4)能够直接引用已标准化的技能标识。
Prompt 注入时机在智能体开展根因分析、方案选型或回答复杂咨询时注入,提供历史同类案例参考。在智能体规划工具调用(Tool Planning)或执行自动化运维 SOP 时注入,指导精确的多步操作。

2. 七步知识蒸馏流水线(distillation Pipeline)逐节点解析

在 记忆 → 配置 → 经验与技能 Pipeline 中,每条蒸馏流水线固定由以下 7 个顺序节点构成:

步骤序号节点标识 (step)是否必选核心处理逻辑、模型调用与可调参数
Step 1receive必选接收与有界证据校验:校验输入的 messages 对话轮次与 toolEvents 工具执行轨迹(通过 maxToolEvents 限制单次最大工具事件数,防止超长循环日志撑爆上下文),并在 OceanBase sources 表中冻结不可变的 L0 原始证据记录。
Step 2skill_extraction可开关(与 Step 4 至少开启一项)抽取可复用 SOP 技能候选:调用 qwen-plus(structuredOutputMode: "tool_call")分析对话与 toolEvents 中的成功工具调用序列,提炼包含 name、triggerConditions、steps[]、parameters 与 Verification 的候选技能。支持自定义 skillDistillationPrompt。
Step 3skill_merge随 Step 2 联动召回相似存量技能并决策合并:使用 text-embedding-v3(1024 维)在同一治理作用域内召回 Top maxCandidates(取值 1~20)存量技能,结合余弦相似度阈值 mergeThreshold(取值 (0, 1])与 skillMergePrompt 交由模型决策:新增独立技能(ADD)、融合补充进既有技能并生成新修订版本(MERGE)或跳过重复项(SKIP)。
Step 4experience_extraction可开关(与 Step 2 至少开启一项)抽取排障经验并关联技能引用:调用 qwen-plus 从任务全貌中提炼情境案例(scenario、problem、action、outcome、lesson),并自动将 Step 2/3 产出的相关技能绑定为知识引用。支持自定义 experienceDistillationPrompt。
Step 5experience_merge随 Step 4 联动召回相似存量经验并决策合并:召回 Top maxCandidates(1~20)相似存量经验,按 mergeThreshold 与 experienceMergePrompt 执行跨会话合并(自动累加独立会话来源证据 sourceIds,助推达到 minIndependentSessionsForAgent 激活门槛)或新增。
Step 6validation必选质量与安全守门校验:强制执行的独立验证节点(支持定制 evolutionValidationPrompt)。负责核查候选知识的步骤逻辑自洽性、证据支撑度、置信度评分(confidence),并主动过滤低置信度条目或拦截包含未脱敏密钥/口令的违规候选。
Step 7knowledge_operation必选知识落库与状态路由:在单事务内持久化知识主记录、不可变版本快照(Revision)、L0 来源关联与 1024 维向量投影。根据项目 evolution.requireConfirmation 与 evolution.activation 策略,决定直接置为 **active 还是进入 shadow** 待确认队列。

功能入口与权限矩阵

控制台入口位于:**项目 enterprise-ai-hub-210 → 记忆(Memory) → 经验与技能** 页签(路由:/console/project-{region}-enterprise-ai-hub-210/memory?tab=evolution),配套流水线配置位于 记忆 → 配置 → 经验与技能 Pipeline。

功能动作控制台 UI 入口REST API 端点Server SDK 方法 (agentbase-node-sdk@2.10.0)所需 RBAC / API Key Scope跨模块关联依赖
提交知识蒸馏任务经验与技能 → 手动蒸馏 → 提交POST /v1/memory/memories/distillationsmemory.submitDistillationmemories.write调用 模型路由(qwen-plus / text-embedding-v3)与 配置中心
查询蒸馏任务列表与详情经验与技能 → 蒸馏任务列表GET /v1/memory/memories/distillations、GET .../{distillationId}memory.listDistillations / memory.getDistillationmemories.read关联 记忆审计 与 记忆链路追踪
重放失败/历史蒸馏任务蒸馏任务行尾 重放(Replay)POST /v1/memory/memories/distillations/{distillationId}/replaymemory.replayDistillationmemories.write基于冻结的原始 L0 Source 重新执行蒸馏管线
列表与语义搜索经验(Experiences)经验与技能 → 经验 列表与搜索框GET /v1/memory/memories/experiences、POST .../experiences/searchmemory.listExperiences / memory.searchExperiencesmemories.read为智能体工作台与 recall 提供情境经验
列表与语义搜索技能(Skills)经验与技能 → 技能 列表与搜索框GET /v1/memory/memories/skills、POST .../skills/searchmemory.listSkills / memory.searchSkillsmemories.read为智能体工作台与 recall 提供多步 SOP
追溯经验/技能的 L0 原始来源展开经验或技能详情 → 来源证据GET /v1/memory/memories/experiences/{knowledgeId}/sources、/skills/{knowledgeId}/sourcesmemory.listExperienceSources / memory.listSkillSourcesmemories.read关联 多层记忆划分 中的 L0 原始证据层
更新或遗忘(删除)经验/技能经验/技能行尾 编辑 / 遗忘 按钮PATCH /v1/memory/memories/knowledge/{knowledgeId}、DELETE .../knowledge/{knowledgeId}(或 /experiences/{id}、/skills/{id})memory.updateKnowledge / memory.forgetKnowledgememories.write / memories.delete遗忘后状态立即置为 forgotten 并停止线上召回

功能详解与操作指南

步骤一:在控制台按归属范围提交执行证据蒸馏并检索产出

步骤二:通过 REST API 提交含 toolEvents 的蒸馏任务并重放检验

在实际智能体运行时(Agent Runtime)中,后端服务可在工单结单或任务执行成功后,将完整对话 messages 与结构化工具轨迹 toolEvents 一并提交至 POST /v1/memory/memories/distillations:

export APPBASE_ENDPOINT="https://appbuild.oceanbase.com/v1"
export APPBASE_PROJECT_ID="enterprise-ai-hub-210"
export APPBASE_API_KEY="<APPBASE_API_KEY>"

# 1. 提交携带 messages 与 toolEvents 的知识蒸馏任务 (mode="wait",最长等待 20s 返回终态)
curl -fsS -X POST "${APPBASE_ENDPOINT}/memory/memories/distillations" \
  -H "X-Appwrite-Project: ${APPBASE_PROJECT_ID}" \
  -H "X-Appwrite-Key: ${APPBASE_API_KEY}" \
  -H "Idempotency-Key: distill-exp-skill-tk-20261022-001" \
  -H "Content-Type: application/json" \
  --data '{
    "userId": "user_zhangwei_001",
    "agentId": "enterprise-support-agent",
    "scope": "user",
    "sessionId": "sess_ticket_TK_20261022_001",
    "runId": "run_tk_20261022_001",
    "mode": "wait",
    "verifiedSuccess": true,
    "messages": [
      {
        "role": "user",
        "content": "生产告警:enterprise-ai-hub-210 项目在批量构建 1024 维 HNSW 向量索引时报错 OB_ALLOCATE_MEMORY_FAILED (-4013),请排查并恢复。"
      },
      {
        "role": "assistant",
        "content": "已调用 ob_sql_diagnostics 工具核查 GV$OB_VECTOR_MEMORY_INFO,确认租户向量内存池占比仅 10% 且使用率达 98.7%。随后调用 ob_tenant_param_updater 将 ob_vector_memory_limit_percentage 调整为 30%,并重建增量向量索引,验证 schema.status 已恢复为 ready。"
      }
    ],
    "toolEvents": [
      {
        "toolName": "ob_sql_diagnostics",
        "status": "succeeded",
        "durationMs": 42,
        "input": {
          "sql": "SELECT TENANT_ID, USED_VECTOR_MEMORY, LIMIT_VECTOR_MEMORY FROM oceanbase.GV$OB_VECTOR_MEMORY_INFO"
        },
        "output": {
          "tenant_vector_memory_limit_percentage": 10,
          "usage_ratio": 0.987
        }
      },
      {
        "toolName": "ob_tenant_param_updater",
        "status": "succeeded",
        "durationMs": 115,
        "input": {
          "parameter": "ob_vector_memory_limit_percentage",
          "value": 30
        },
        "output": {
          "updated": true,
          "effectiveValue": 30
        }
      }
    ]
  }' | jq .

# 2. 查询指定蒸馏任务详情与产出的 knowledgeIds
export DISTILLATION_ID="dst_3e5b09f456c5d5c332507ec1dbe3eb6d"
curl -fsS "${APPBASE_ENDPOINT}/memory/memories/distillations/${DISTILLATION_ID}" \
  -H "X-Appwrite-Project: ${APPBASE_PROJECT_ID}" \
  -H "X-Appwrite-Key: ${APPBASE_API_KEY}" | jq .

# 3. 当调整了经验与技能 Pipeline 或上游模型恢复后,重放 (Replay) 该蒸馏任务
curl -fsS -X POST "${APPBASE_ENDPOINT}/memory/memories/distillations/${DISTILLATION_ID}/replay" \
  -H "X-Appwrite-Project: ${APPBASE_PROJECT_ID}" \
  -H "X-Appwrite-Key: ${APPBASE_API_KEY}" \
  -H "Idempotency-Key: replay-dst-3e5b09f4-001" \
  -H "Content-Type: application/json" \
  --data '{}' | jq .

步骤三:使用 Server SDK 检索经验与技能、追溯 sources 与淘汰过时知识

在 Node.js 业务后端中,可通过 agentbase-node-sdk@2.10.0 分别调用 searchExperiences、searchSkills、listSkillSources 与 forgetKnowledge,完成从知识检索、来源审计到淘汰清理的完整闭环:

// 使用官方服务端 SDK: agentbase-node-sdk@2.10.0
import { Client, Memory } from 'agentbase-node-sdk';

const client = new Client()
    .setEndpoint('https://appbuild.oceanbase.com/v1')
    .setProject('enterprise-ai-hub-210')
    .setKey(process.env.APPBASE_API_KEY);

const memory = new Memory(client);

// 1. 语义搜索匹配的排障经验 (POST /v1/memory/memories/experiences/search)
const experiences = await memory.searchExperiences({
    userId: 'user_zhangwei_001',
    scope: 'user',
    query: 'OceanBase 向量索引构建报 -4013 内存不足如何解决',
    limit: 5
});

for (const exp of experiences.items || []) {
    console.log('[Experience]', exp.knowledgeId, exp.title, '置信度:', exp.confidence);
}

// 2. 语义搜索匹配的标准 SOP 技能 (POST /v1/memory/memories/skills/search)
const skills = await memory.searchSkills({
    userId: 'user_zhangwei_001',
    scope: 'user',
    query: '扩容租户向量内存池 ob_vector_memory_limit_percentage 标准步骤',
    limit: 5
});

if (skills.items?.length > 0) {
    const topSkill = skills.items[0];
    console.log('[Skill SOP]', topSkill.knowledgeId, topSkill.name, '步骤数:', topSkill.steps?.length);

    // 3. 追溯支撑该技能的 L0 原始会话与工具轨迹来源 (GET .../skills/{knowledgeId}/sources)
    const sources = await memory.listSkillSources({
        knowledgeId: topSkill.knowledgeId,
        limit: 10
    });
    console.log('关联的不可变 L0 Source 数量:', sources.total);
}

// 4. 当某项旧经验因系统架构升级不再适用时,调用遗忘接口立即停止线上召回 (DELETE)
async function retireObsoleteKnowledge(knowledgeId) {
    await memory.forgetKnowledge({
        knowledgeId,
        userId: 'user_zhangwei_001',
        scope: 'user',
        reason: 'OceanBase 集群已升级至自动弹性向量内存管理,旧手动阈值经验退役'
    });
}

常见问题与排障(FAQ)

1. 为什么在配置“经验与技能 Pipeline”时,不能同时关闭 skill_extraction 和 experience_extraction 两个节点?

2. 提交蒸馏请求时使用 mode: "wait",如果返回了 HTTP 202 且带有 "waitTimedOut": true,任务是否失败了?需要重新提交吗?

3. 为什么某条经验(Experience)已经完成了抽取,但在激活或审批时提示 skill_dependency_not_approved?


相关文档