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_KEYconfigured. See Get API key- For Python SDK:
pip install agentscope-runtime
Step 1: Write memory
Call AddMemory to pass a conversation to the memory. The system auto-extracts factual memories.
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": "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"
}'
from agentscope_runtime.tools.modelstudio_memory import (
AddMemory, AddMemoryInput, Message,
)
import asyncio
async def add_memory_example():
add_memory = AddMemory()
try:
await add_memory.arun(AddMemoryInput(
user_id="user_001",
messages=[
Message(role="user", content="Remind me to drink water at 9 AM every day"),
Message(role="assistant", content="Got it, recorded"),
Message(role="user", content="Remind me to organize meeting notes at 10 AM tomorrow"),
]
))
print("Memory written")
finally:
await add_memory.close()
asyncio.run(add_memory_example())
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://dashscope.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"
from agentscope_runtime.tools.modelstudio_memory import (
ListMemory, ListMemoryInput,
)
import asyncio
async def list_memory_example():
list_memory = ListMemory()
try:
result = await list_memory.arun(ListMemoryInput(
user_id="user_001",
page_size=10,
page_num=1
))
for node in result.memory_nodes:
print(f"Memory: {node.content}")
finally:
await list_memory.close()
asyncio.run(list_memory_example())
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://dashscope.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"
}'
from agentscope_runtime.tools.modelstudio_memory import (
SearchMemory, SearchMemoryInput, Message,
)
import asyncio
async def search_memory_example():
search_memory = SearchMemory()
try:
result = await search_memory.arun(SearchMemoryInput(
user_id="user_001",
messages=[Message(role="user", content="What do I need to do?")]
))
for node in result.memory_nodes:
print(f"Memory: {node.content}")
finally:
await search_memory.close()
asyncio.run(search_memory_example())
NoteYou've completed writing, viewing, and searching memories. Inject the results into your prompt for personalized responses.
ImportantAfter the core flow, continue to create a memory with custom rules.