创建画像模板

更新时间:
复制 MD 格式

创建用户画像模板,定义画像字段

创建用户画像模板,定义画像包含的字段及描述。

请求方法与路径

POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/profile_schemas

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

请求参数

参数类型必填位置说明
namestring是Body画像模板名称,最多 32 个字符
descriptionstring否Body画像模板描述
plan_versionstring否Body收费计划:pro 或 lite
extract_scenestring否Body提取场景:efficient 或 intelligent,默认 efficient
attributesarray是Body画像属性定义列表,不能为空数组
attributes[].namestring是Body属性名称
attributes[].descriptionstring否Body属性描述
memory_library_idstring否Body记忆库 ID,不传则使用默认记忆库

代码示例

curl -X POST https://{WorkspaceId}.cn-beijing.maas.aliyuncs.com/api/v2/apps/memory/profile_schemas \
  --header "Authorization: Bearer $DASHSCOPE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "name": "用户基础画像",
    "description": "包含年龄和兴趣的用户信息",
    "extract_scene": "efficient",
    "attributes": [
      {"name": "年龄", "description": "用户年龄"},
      {"name": "爱好", "description": "用户的兴趣爱好"},
      {"name": "职业", "description": "用户职业"}
    ]
  }'
from agentscope_runtime.tools.modelstudio_memory import (
    CreateProfileSchema, CreateProfileSchemaInput, ProfileAttribute,
)
import asyncio

async def main():
    create_schema = CreateProfileSchema()
    try:
        result = await create_schema.arun(CreateProfileSchemaInput(
            name="用户基础画像",
            description="包含年龄和兴趣的用户信息",
            attributes=[
                ProfileAttribute(name="年龄", description="用户年龄"),
                ProfileAttribute(name="爱好", description="用户的兴趣爱好"),
                ProfileAttribute(name="职业", description="用户职业"),
            ]
        ))
        print(f"Schema ID: {result.profile_schema_id}")
    finally:
        await create_schema.close()

asyncio.run(main())

响应示例

{
  "profile_schema_id": "50edf54eaa5842e891d959ae115205be",
  "request_id": "f190a540-814e-9c1c-873e-0661851c8fca"
}

重要创建后,使用 AddMemory 传入 profile_schema 提取画像,再用 GetUserProfile 获取。