> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/end-user-identity.md).

# 最终用户身份

终端用户身份会告诉 Convai 是哪个玩家在与角色对话。请设置一个稳定的 `EndUserID` 在聊天机器人组件上，先于 `StartSession` 这样，一个用户的记忆就不会出现在另一个用户的对话中。

### 关键术语

| 术语                | 作用                                                                            |
| ----------------- | ----------------------------------------------------------------------------- |
| `EndUserID`       | 您的项目在连接时发送给 Convai 的身份字符串。请将其设置在 `UConvaiChatbotComponent` 之前 `StartSession`. |
| `SpeakerID`       | 一个由 Convai 分配的、来自 Speaker ID 记录的标识符。请保存它，并将其重复用作 `EndUserID`.                 |
| `EndUserMetadata` | 与……一并发送的可选 JSON 上下文 `EndUserID`。将其设置在聊天机器人组件上。                                |

对于 WebRTC `StartSession` 流程，插件会读取 `EndUserID` 从 `UConvaiChatbotComponent` 通过 `IConvaiConnectionInterface`。同时也在 `UConvaiPlayerComponent` 上设置相同的值，这样项目中的两个组件就能保持同步。

### 选择一种身份策略

| 策略     | 适用场景                                              | 备注                                                                                                                                                                              |
| ------ | ------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 说话人 ID | 您的项目需要一个由 Blueprint 管理的身份记录，并且可以在 Unreal 中列出或删除它。 | 调用 **Convai 创建说话人 ID** 一次，然后保存返回的 `SpeakerID`。参见 [说话人 ID 管理](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/speaker-id-management.md). |
| 账号 ID  | 您的项目已经有登录或个人资料 ID。                                | 将您的稳定账号 ID 直接指定为 `EndUserID`.                                                                                                                                                   |
| 设备回退   | 一台本地设备对应一名玩家。                                     | 将 chatbot 留空 `EndUserID` 留空，插件会在连接时推导出一个设备标识符。                                                                                                                                  |

对于共享设备、培训和入门项目，请使用说话人 ID 或您自己的账号 ID。设备回退可能会将同一台机器上的多个用户的记忆合并。

### 在 StartSession 之前分配身份

{% stepper %}
{% step %}

#### 设置聊天机器人身份

开启 `UConvaiChatbotComponent`，将 `EndUserID` 设置为保存的 `SpeakerID` 或账号 ID。

如果您想传递玩家上下文，请将 `EndUserMetadata` 设置为一个 JSON 字符串：

```json
{"name": "Alex", "role": "trainee", "course": "fire-safety"}
```

{% endstep %}

{% step %}

#### 将玩家组件

开启 `UConvaiPlayerComponent`，将 `EndUserID` 设置为相同的值。

如果您正在发送元数据，请将 `EndUserMetadata` 在玩家组件上设置为相同的 JSON 字符串。
{% endstep %}

{% step %}

#### 启动聊天机器人会话

调用 `StartSession` 在设置好身份值后，在聊天机器人组件上执行。

插件会发送 `EndUserID` 和 `EndUserMetadata` 在连接时发送。Convai 会将该身份与角色 ID 一起使用，以加载正确的记忆范围。
{% endstep %}
{% endstepper %}

{% hint style="warning" %}
在……之前设置身份 `StartSession`。如果在会话打开后才分配身份，Convai 可能无法将对话与预期的用户记录关联起来。
{% endhint %}

### 仅在适当时使用设备回退

如果 chatbot `EndUserID` 在连接时为空，插件会调用 `UConvaiUtils::GetDeviceUniqueIdentifier()`。该辅助函数会尝试 `FPlatformMisc::GetDeviceId()`，然后 `FPlatformMisc::GetOperatingSystemId()`，然后 `FPlatformMisc::GetLoginId()`.

这适用于单个本地用户，但对于以下情况则不够：

* 共享教室或实验室机器。
* 供多名学习者使用的培训自助终端。
* 记忆必须随已登录用户跨设备同步的项目。

### 验证身份

在……之前 `StartSession`，打印这些值：

* `UConvaiChatbotComponent.EndUserID`
* `UConvaiPlayerComponent.EndUserID`

两个值应当一致。聊天机器人中的值是在连接时发送给 Convai 的那个。

### 下一步

{% content-ref url="/pages/490cd1c53fd291cb3dcb57f385b0eee013c3ae74" %}
[Speaker ID 管理](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/speaker-id-management.md)
{% endcontent-ref %}

{% content-ref url="/pages/02906b279025410eed0c91dd64f1012b0304b626" %}
[为角色配置记忆](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/configure-memory-for-a-character.md)
{% endcontent-ref %}

{% content-ref url="/pages/d52ddbffaafeb3f6c5f97016d40633bc7ea09f16" %}
[LTM Blueprint 参考](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/ltm-blueprint-reference.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/end-user-identity.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
