更新记忆

更新时间:
复制 MD 格式

更新一条事实记忆的内容

更新指定记忆节点的内容。接口会自动识别节点类型并格式化内容。

请求方法与路径

PATCH https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/memory_nodes/{memory_node_id}

调用时请将 {WorkspaceId} 替换为真实的业务空间 ID。

请求参数

参数类型必填位置说明
memory_node_idstring是Path记忆节点 ID
custom_contentstring是Body更新后的记忆内容
memory_library_idstring否Body记忆库 ID
meta_dataobject否Body元信息。增量更新,未指定的键保持不变
skill_namestring条件必填Body节点为 skill 类型时,必须同时传入 skill_name、skill_description 和 skill_tags
skill_descriptionstring条件必填Bodyskill 描述。必填条件同 skill_name
skill_tagsarray[string]条件必填Bodyskill 标签。必填条件同 skill_name

返回结果

字段类型说明
request_idstring请求 ID

请求示例

curl --location --request PATCH 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/memory_nodes/42dfc089dfa7409889966960a95c3b7e' \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "custom_content": "更新后的记忆内容",
    "memory_library_id": "memory_library_001",
    "meta_data": {"location_name": "杭州"}
  }'
from agentscope_runtime.tools.modelstudio_memory import UpdateMemory
import asyncio

async def main():
    update_memory = UpdateMemory()
    try:
        await update_memory.arun(
            memory_node_id="MEMORY_NODE_ID",
            user_id="user_001",
            custom_content="还要提醒我上午10点吃药。"
        )
        print("更新成功")
    finally:
        await update_memory.close()

asyncio.run(main())

响应示例

{
  "request_id": "cc2690f9f2b3485a93013e5705c91241"
}

重要删除记忆使用 DeleteMemory。