Create Profile Schema

Updated at:

Create a user profile schema and define profile fields

Creates a user profile schema, defining the fields and descriptions included in the profile.

Method and endpoint

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

Replace {WorkspaceId} with your actual workspace ID.

Request parameters

ParameterTypeRequiredLocationDescription
namestringYesBodyProfile schema name, up to 32 characters
descriptionstringNoBodyProfile schema description
plan_versionstringNoBodyBilling plan: pro or lite
extract_scenestringNoBodyExtraction mode: efficient or intelligent; defaults to efficient
attributesarrayYesBodyProfile attribute definitions; the array cannot be empty
attributes[].namestringYesBodyAttribute name
attributes[].descriptionstringNoBodyAttribute description
memory_library_idstringNoBodyMemory library ID. If omitted, the default memory library is used

Code examples

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": "Basic user profile",
    "description": "User information including age and interests",
    "extract_scene": "efficient",
    "attributes": [
      {"name": "Age", "description": "User age"},
      {"name": "Hobbies", "description": "User interests and hobbies"},
      {"name": "Occupation", "description": "User occupation"}
    ]
  }'
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="Basic user profile",
            description="User information including age and interests",
            attributes=[
                ProfileAttribute(name="Age", description="User age"),
                ProfileAttribute(name="Hobbies", description="User interests and hobbies"),
                ProfileAttribute(name="Occupation", description="User occupation"),
            ]
        ))
        print(f"Schema ID: {result.profile_schema_id}")
    finally:
        await create_schema.close()

asyncio.run(main())

Response example

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

ImportantAfter creation, pass profile_schema via AddMemory to extract the profile, then use GetUserProfile to retrieve it.