获取用户画像

更新时间:
复制 MD 格式

查询指定用户已提取的画像属性

获取指定用户的画像属性。画像提取为异步过程;调用 AddMemory 添加对话后,首次查询可能尚未返回属性值,请按业务重试策略再次查询。

说明若返回的属性值均为空,请确认调用 AddMemory 时已传入相同的 profile_schema。未传该参数时不会触发画像提取。

接口

GEThttps://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/profile_schemas/{profile_schema_id}/user_profile

调用时请将 {WorkspaceId} 替换为真实的业务空间 ID。

路径参数

profile_schema_idstring必填

画像模板 ID

位置:Path

查询参数

user_idstring必填

记忆实体 ID

位置:Query
memory_library_idstring可选

记忆库 ID

位置:Query

响应字段

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"
}

重要完整画像流程参见使用用户画像。