Skip to main content
Memory Fragments

Add Memory

Store conversations as memory fragments, automatically extracting key information

POST
/add
cURL
curl --request POST \
  --url 'https://dashscope.aliyuncs.com/api/v2/apps/memory/add' \
  --header 'Authorization: Bearer <YOUR_API_KEY>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "user_id": "<string>",
  "messages": [
    {
      "role": "user",
      "content": "<string>"
    }
  ],
  "custom_content": "<string>",
  "profile_schema": "<string>",
  "memory_library_id": "<string>",
  "meta_data": {}
}
'
{
  "request_id": "<string>",
  "memory_nodes": [
    {
      "memory_node_id": "<string>",
      "content": "<string>",
      "event": "<string>"
    }
  ]
}
Stores user conversations as memory fragments, automatically extracting key information. Also supports directly specifying custom content for storage. To extract a user profile at the same time, pass profile_schema.
Before calling, ensure you have obtained an API Key. See Authentication.

Request parameters

ParameterTypeRequiredDescription
user_idstringYesMemory entity ID, used to identify the owning object, max 64 characters
messagesarrayYes*Conversation message list, up to 50 entries. Each contains role (user/assistant) and content
custom_contentstringYes*Custom content, max 512 characters. Mutually exclusive with messages
profile_schemastringNoProfile schema ID. If omitted, no user profile is extracted — only memory fragments are written
memory_library_idstringNoMemory library ID. If not provided, the default library is used
project_idstringNoMemory fragment rule ID. If not provided, the default rule is used
meta_dataobjectNoUser-defined information
messages and custom_content are mutually exclusive. When custom_content is provided, messages is ignored.
Call succeeded but profile attributes are empty? Memory fragments and user profiles are extracted by two independent pipelines. Without profile_schema, the API returns only memory_nodes and profile attributes stay empty. Call again with the profile schema ID — get it from ListProfileSchemas, or from Memory rules > Profile rules on the memory detail page in the console.

Response

FieldTypeDescription
request_idstringRequest ID
memory_nodesarrayList of changed memory fragments
memory_nodes[].memory_node_idstringMemory fragment ID
memory_nodes[].contentstringExtracted memory content
memory_nodes[].eventstringOperation type: ADD / UPDATE / DELETE
memory_nodes[].old_contentstringContent before update, only valid when event is UPDATE

Code examples

curl -X POST https://dashscope.aliyuncs.com/api/v2/apps/memory/add \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "messages": [
      {"role": "user", "content": "每天上午9点提醒我喝水"},
      {"role": "assistant", "content": "好的,已记录"},
      {"role": "user", "content": "明天10点提醒我整理会议纪要。"}
    ],
    "user_id": "user_001"
  }'

# response
{
  "memory_nodes": [
    {"content": "用户每天上午9点需要喝水提醒", "event": "ADD", "memory_node_id": "50b46e97..."},
    {"content": "用户明天10点需要整理会议纪要", "event": "ADD", "memory_node_id": "381cc694..."}
  ],
  "request_id": "bec69131-627c-..."
}
After writing, use SearchMemory to search memories.

Authorizations

string
header
required

Body

application/json
string
required

记忆实体 ID,最大 64 字符

object[]

对话消息列表,最多 50 条。与 custom_content 互斥

string

自定义内容,最大 512 字符。与 messages 互斥

string

画像模板 ID。不传则不提取用户画像,仅写入记忆片段

string

记忆库 ID,不传则使用默认记忆库

object

用户自定义信息

Response

200-application/json
string
object[]
Overview
Managed Agent API
Sandbox API
Flow Agent API
RAG API
Connector API
Framework Integration
Assistant API (Deprecating)
  • Overview