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

  • First-time use requires activating Memory: open the Memory page in the Bailian console and click Activate Now
  • 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" Note: agentscope-runtime depends on mcp.server.fastmcp, which was removed in mcp 2.x. If your environment has mcp 2.x, pin it during installation: pip install agentscope-runtime "mcp<2"; otherwise imports fail with No module named 'mcp.server.fastmcp'.
Explicitly set the API key in the terminal used for the examples. Replace the placeholder first and do not commit real keys:
export DASHSCOPE_API_KEY="sk-xxxxxxxxxxxxxxxx"
The Python examples use DASHSCOPE_API_KEY and MEMORY_SERVICE_ENDPOINT from the same terminal. Replace {WorkspaceId} in the service address with the actual workspace ID before starting Python; without the endpoint setting, the SDK does not automatically select that workspace's Memory service address. All three steps use the same user_id="user_001". This page uses the standalone Memory service, managed separately from Managed Agents Memory Store.

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

In the Bailian console, 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/memory_nodes/search \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "user_id": "user_001",
    "messages": [{"role": "user", "content": "What do I need to do?"}],
    "top_k": 10,
    "min_score": 0.3,
    "plan_version": "Lite"
  }'
You've completed writing, viewing, and searching memories. Check that the facts listed and retrieved for user_001 correspond to the conversation you wrote. The example stores and retrieves facts about reminders; it does not automatically schedule reminders. Inject the results into your prompt for personalized responses.
After the core flow, continue to create a memory with custom rules.