Add Memory Async

Updated at:

Asynchronously store conversations as memories and query execution status and results by event ID

Submits a memory extraction task asynchronously. The API immediately returns an event ID. Use Get Event to query the result. This API supports extraction for multiple projects, skills, and user profiles.

NoteBefore calling, ensure you have obtained an API Key. See Authentication.

Endpoint

POSThttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/add-async

Replace {WorkspaceId} with your actual workspace ID.

Request body

messagesarrayOne of two

Conversation messages. Provide at least one of messages and custom_content

messages[].rolestringOptional

Message role. Valid values: user, assistant, and tool

messages[].contentstring / arrayOptional

Message content. Pass a text string or a multimodal array containing text and images

messages[].content[].typestringOptional

Content type: text or image_url. Images are parsed only for projects that support multimodal input

messages[].content[].textstringConditional

Text content. Required when type is text

messages[].content[].image_urlobjectConditional

Image information. Required when type is image_url

messages[].content[].image_url.urlstringConditional

Image URL

messages[].tool_callsarrayOptional

Tool calls initiated by an assistant message in OpenAI format. Tool messages are accepted only for skill extraction and are filtered out for other extraction types

messages[].tool_calls[].idstringOptional

Tool call ID

messages[].tool_calls[].typestringOptional

Tool call type. The value is function

messages[].tool_calls[].functionobjectConditional

Function call information. Required when tool_calls is present

messages[].tool_calls[].function.namestringConditional

Function name. Required for each tool call

messages[].tool_calls[].function.argumentsstringOptional

Function arguments as a JSON string, not an object

messages[].tool_call_idstringConditional

Corresponding tool call ID for a message whose role is tool. Tool messages are accepted only for skill extraction

custom_contentstringOne of two

Custom content. When provided, it is saved directly and extraction is no longer based on messages. It cannot be used with project_ids

user_idstringRequired

Sub-user ID used to isolate memories

memory_library_idstringOptional

Memory library ID. The default library is used if omitted

project_idstringOptional

Custom project ID. Mutually exclusive with project_ids

project_idsarray[string]Optional

Up to five custom project IDs. Mutually exclusive with project_id and cannot be used with custom_content

profile_schemastringOptional

User profile schema ID. Provide it to extract a user profile

extract_modestringOptional

Extraction mode. profile_only extracts only the profile

skill_namestringConditional

If the project is a skill and custom_content is provided, skill_name, skill_description, and skill_tags are all required

skill_descriptionstringConditional

Skill description. Required under the same conditions as skill_name

skill_tagsarray[string]Conditional

Skill tags. Required under the same conditions as skill_name

meta_dataobjectOptional

Custom metadata

Response fields

request_idstring

Request ID

event_idstring

Execution event ID

eventsarray

Execution tasks

events[].created_atinteger

Creation time

events[].event_idstring

Event ID

events[].event_typestring

Event type, such as ADD_ASYNC

events[].memory_library_idstring

Memory library ID for the task

events[].resource_idstring

Source ID, such as a project ID or profile schema ID

events[].resource_typestring

Source type: observation, skill, user_profile, custom_observation, or custom_skill

events[].statusstring

Task status: PENDING, RUNNING, SUCCEEDED, FAILED, or UNRECORDED

events[].updated_atinteger

Time when the status was last updated

events[].user_idstring

Sub-user ID for the task

events[].resultarray

Execution result. Empty in the initial response

Request example

curl --location 'https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/add-async' \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
    "memory_library_id": "memory_library_001",
    "project_ids": ["project_001"],
    "user_id": "user_001",
    "messages": [
      {"role": "user", "content": "Remind me to order takeout at 11 AM every day and to dress warmly tomorrow."},
      {"role": "assistant", "content": "Sure."}
    ],
    "meta_data": {"location_name": "Beijing"}
  }'

Response example

{
  "request_id": "048983ff-ed50-96e0-b0a6-482cce26cbe3",
  "event_id": "9d30e77a2f8e42378bf533406fdc09d9",
  "events": [
    {
      "created_at": 1784638015,
      "event_id": "9d30e77a2f8e42378bf533406fdc09d9",
      "event_type": "ADD_ASYNC",
      "memory_library_id": "memory_library_001",
      "resource_id": "project_001",
      "resource_type": "observation",
      "status": "PENDING",
      "updated_at": 1784638015,
      "user_id": "user_001",
      "result": []
    }
  ]
}

ImportantA status of PENDING or RUNNING means the task is still running. Use Get Event to query the result.