查询指定用户已提取的画像属性
获取指定用户的画像属性。画像提取为异步过程;调用 AddMemory 添加对话后,首次查询可能尚未返回属性值,请按业务重试策略再次查询。
说明若返回的属性值均为空,请确认调用 AddMemory 时已传入相同的 profile_schema。未传该参数时不会触发画像提取。
接口
GET
https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/profile_schemas/{profile_schema_id}/user_profile调用时请将 {WorkspaceId} 替换为真实的业务空间 ID。
路径参数
profile_schema_idstring必填画像模板 ID
查询参数
user_idstring必填记忆实体 ID
memory_library_idstring可选记忆库 ID
响应字段
request_idstring请求 ID
profile.schema_namestring画像模板名称
profile.schema_descriptionstring画像模板描述
profile.attributesarray画像属性列表
profile.attributes[].idstring属性 ID
profile.attributes[].namestring属性名称
profile.attributes[].valuestring属性值
请求示例
curl -X GET "https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/profile_schemas/{profile_schema_id}/user_profile?user_id=user_001" \
--header "Authorization: Bearer $DASHSCOPE_API_KEY" \
--header "Content-Type: application/json"
from agentscope_runtime.tools.modelstudio_memory import (
GetUserProfile, GetUserProfileInput,
)
import asyncio
async def main():
get_profile = GetUserProfile()
try:
profile = await get_profile.arun(GetUserProfileInput(
schema_id="YOUR_SCHEMA_ID",
user_id="user_001"
))
for attr in profile.profile.attributes:
print(f"{attr.name}: {attr.value or '未提取'}")
finally:
await get_profile.close()
asyncio.run(main())
响应示例
{
"profile": {
"attributes": [
{"id": "bb28e6cd522443fc9bf7e75b1377bf9d", "name": "年龄", "value": "28"},
{"id": "04eb06f5f04a437b82d07ceb088103f9", "name": "爱好", "value": "踢足球"},
{"id": "2eff4652a6bc47b0803635033b1e08dd", "name": "职业", "value": "软件工程师"}
],
"schema_description": "包含年龄和兴趣的用户信息",
"schema_name": "用户基础画像"
},
"request_id": "78cb6090-a7a5-9897-861c-082a64b43d97"
}
重要完整画像流程参见使用用户画像。
该文章对您有帮助吗?