> 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).

# 终端用户身份

配置稳定的 Unreal 玩家身份，以便每个 Convai 角色在会话开始前为正确用户加载记忆。

终端用户身份用于告知 Convai 当前是哪位玩家在与角色对话。请设置一个稳定的 `EndUserID` ，并在聊天机器人组件上设置后再调用 `StartSession` ，以免一位用户的记忆出现在另一位用户的对话中。

### 关键术语

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

对于 WebRTC `StartSession` 流程，插件会通过 `EndUserID` 从 `UConvaiChatbotComponent` 经由 `IConvaiConnectionInterface`读取。还请在 `UConvaiPlayerComponent` 上设置相同的值，确保项目中的两个组件保持同步。

### 选择身份策略

| 策略         | 适用情况                               | 备注                                                                                                                                                                                                                   |
| ---------- | ---------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Speaker ID | 项目需要一个由蓝图管理、可在 Unreal 中列出或删除的身份记录。 | 调用 **Convai Create Speaker ID** 一次，然后保存返回的 `SpeakerID`。请参阅 [Speaker ID 管理](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/long-term-memory/speaker-id-management.md). |
| 账户 ID      | 项目已有登录 ID 或个人资料 ID。                | 将稳定的账户 ID 直接指定为 `EndUserID`.                                                                                                                                                                                         |
| 设备回退方案     | 一台本地设备对应一位玩家。                      | 将聊天机器人的 `EndUserID` 留空，插件会在连接时生成设备标识符。                                                                                                                                                                               |

对于共享设备、培训和新手引导项目，请使用 Speaker 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 %}

### 仅在适当情况下使用设备回退方案

如果聊天机器人连接时 `EndUserID` 为空，插件会调用 `UConvaiUtils::GetDeviceUniqueIdentifier()`。该辅助函数会依次尝试 `FPlatformMisc::GetDeviceId()`，然后是 `FPlatformMisc::GetOperatingSystemId()`，然后是 `和`.

FPlatformMisc::GetLoginId()。这适用于单一本地用户，但不足以应对以下情况：

* 多人共用的教室或实验室设备。
* 供多名学员使用的培训终端。
* 需要让记忆随已登录用户跨设备同步的项目。

### 验证身份

在调用 `StartSession`之前，打印以下值：

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

这两个值应保持一致。连接时发送给 Convai 的是聊天机器人的值。

### 后续步骤

{% content-ref url="/pages/490cd1c53fd291cb3dcb57f385b0eee013c3ae74" %}
[说话者 ID 管理](https://docs.convai.com/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" %}
[为角色配置记忆](https://docs.convai.com/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 参考](https://docs.convai.com/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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
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>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
