Skip to main content

Quickstart

Write, view, and search memories in 3 steps

Use the default memory to write, view, and search memories in 3 steps. To customize memory rules, see Create memory.

Prerequisites

  • DASHSCOPE_API_KEY configured. See Get API key
  • Workspace ID obtained. Replace {workspaceId} in the request URLs below with this ID. The API key must belong to the same workspace
  • For Python SDK: pip install agentscope-runtime, then set the service address: export MEMORY_SERVICE_ENDPOINT="https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory"

Step 1: Write memory

Call AddMemory to pass a conversation to the memory. The system auto-extracts factual memories.
curl -X POST https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/add \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "messages": [
      {"role": "user", "content": "Remind me to drink water at 9 AM every day"},
      {"role": "assistant", "content": "Got it, recorded"},
      {"role": "user", "content": "Remind me to organize meeting notes at 10 AM tomorrow"}
    ],
    "user_id": "user_001"
  }'

Step 2: View memory

On the Memory page, open the default memory's Memory details tab. Enter memory entity ID user_001 and click View to see auto-extracted factual memories. Or list memories via API:
curl -X GET "https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/memory_nodes?user_id=user_001&page_size=10&page_num=1" \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header "Content-Type: application/json"

Step 3: Search memory

In the console, switch to the Memory search tab. Enter entity ID user_001, type "What do I need to do?" in the input, and click Run. Or search via API:
curl -X POST https://{workspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/search \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "user_id": "user_001",
    "query": "What do I need to do?"
  }'
You can also use the Bailian CLI. First configure the API key and workspace ID as described in Use the CLI, then run bl memory add --user-id user_001 --messages '[{"role":"user","content":"Remind me to drink water at 9 AM every day"}]' to write, bl memory list --user-id user_001 to view, and bl memory search --user-id user_001 --query "What do I need to do?" to search memories. Since CLI 2.5.0, add uses async extraction and waits up to 120 seconds by default. If you submit without waiting (--wait 0) or the command times out, confirm the extraction results before continuing.
You've completed writing, viewing, and searching memories. Inject the results into your prompt for personalized responses.
After the core flow, continue to create a memory with custom rules.