> 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`       | 来自 Speaker ID 记录、由 Convai 分配的标识符。请保存它并将其重复用作 `EndUserID`.                     |
| `EndUserMetadata` | 随同发送的可选 JSON 上下文 `EndUserID`。请将其设置在聊天机器人组件上。                                  |

对于 WebRTC `StartSession` 流程，插件会读取 `EndUserID` 来自 `UConvaiChatbotComponent` 通过 `IConvaiConnectionInterface`。同时在 `UConvaiPlayerComponent` 上也设置相同的值，以便您项目中的两个组件保持同步。

### 选择身份策略

| 策略     | 适用场景                                          | 备注                                                                                                                                                                                        |
| ------ | --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| 发言者 ID | 您的项目需要一个由 Blueprint 管理的身份记录，可在 Unreal 中列出或删除。 | 调用 **Convai 创建 Speaker ID** 一次，然后保存返回的 `SpeakerID`。请参阅 [Speaker ID 管理](/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`.                                                                                                                                                             |
| 设备回退   | 一台本地设备对应一名玩家。                                 | 将 chatbot `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 %}

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

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

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

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

### 验证身份

在以下操作之前 `StartSession`，打印这些值：

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

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

### 下一步

{% content-ref url="/pages/490cd1c53fd291cb3dcb57f385b0eee013c3ae74" %}
[说话者 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 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.
