> 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-unity-sdk/features/long-term-memory/configure-memory-for-a-character.md).

# 为角色配置记忆

说明如何从仪表板或脚本中为角色开启或关闭长期记忆，以及其全局作用域对共享角色意味着什么。

默认情况下，长期记忆处于禁用状态（`MemorySettings.IsEnabled = false`）。在您显式启用之前，不会提取或存储任何事实。您可以通过 Convai 控制台启用或禁用记忆，或通过以下方式以编程方式控制： `client.Characters`.

{% hint style="danger" %}
**记忆设置对该角色全局生效。** 为某个角色启用 LTM 会影响连接到该角色 ID 的每个应用、SDK 版本和部署。如果您在开发、预发布和生产环境之间共享一个角色，那么在其中一个环境中启用记忆也会在所有环境中启用。对于共享角色，在启用前请先与团队协调。
{% endhint %}

***

### 启用或禁用记忆

{% tabs %}
{% tab title="仪表板" %}
这是大多数团队推荐的方法。更改会立即生效，无需更新代码或重新部署。

1. 在 [convai.com](https://convai.com).
2. 打开要配置的角色。
3. 选中 **记忆** 选项卡，在角色设置侧边栏中。
4. 切换 **长期记忆** 为 **开**.
5. 点击 **保存**.

要禁用，请重复相同步骤并切换 **长期记忆** 为 **关闭**.
{% endtab %}

{% tab title="脚本" %}
使用 `client.Characters` 当您需要程序化控制时——例如在自动化测试环境、构建流水线或运行时管理面板中。 `ConvaiRestClient.Characters` 被标记为 `[已弃用]` 以取代 `ConvaiCharacterApiClient`，因此此代码会在带有 `CS0618` 警告下编译；目前它仍然是读写此设置的唯一强类型访问器。

**检查当前状态**

```csharp
using Convai.RestAPI;
using UnityEngine;

public class MemoryAdmin : MonoBehaviour
{
    private async void Start()
    {
        using var client = new ConvaiRestClient(ConvaiSettings.Instance.ApiKey);

        bool isEnabled = await client.Characters.GetMemoryEnabledAsync("your-character-id");
        Debug.Log($"LTM enabled: {isEnabled}");
    }
}
```

**启用记忆**

```csharp
using Convai.RestAPI;
using UnityEngine;

public class MemoryAdmin : MonoBehaviour
{
    private async void Start()
    {
        using var client = new ConvaiRestClient(ConvaiSettings.Instance.ApiKey);

        await client.Characters.SetMemoryEnabledAsync("your-character-id", true);
        Debug.Log("长期记忆已启用。");
    }
}
```

**禁用记忆**

```csharp
await client.Characters.SetMemoryEnabledAsync("your-character-id", false);
```

{% endtab %}
{% endtabs %}

***

### 禁用记忆但不删除记录

{% hint style="warning" %}
禁用 LTM 会停止提取新的记忆，但 **不会删除现有的记忆记录**。已存储的事实仍保留在 Convai 上，如果您之后重新启用 LTM，它们将被重新注入。

如果您想禁用 LTM 并移除所有已存储的记忆，请先删除这些记忆，然后再禁用。
{% endhint %}

若要在禁用前清除某个用户—角色配对的所有记忆，请使用 `client.Memory.DeleteAllAsync` 然后 `SetMemoryEnabledAsync`. `DeleteAllAsync` 会删除某个特定用户—角色配对的记忆。若要改为删除所有角色下的全部终端用户记录，请使用 `client.EndUsers.DeleteAsync(endUserId)`。请参阅 [管理最终用户记录](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/end-user-management.md).

参见 [长期记忆使用示例](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/usage-examples.md) 以实现完整的重置模式。

***

### 下一步

{% content-ref url="/pages/c12fc9539ece3543a049cf5c334655c9bb0a6a3c" %}
[终端用户身份](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/end-user-identity.md)
{% endcontent-ref %}

{% content-ref url="/pages/49cef55d22f33c0ffdf4893701cd5a6686bd7590" %}
[管理终端用户记录](/api-docs/zh/cha-jian-yu-ji-cheng/convai-unity-sdk/features/long-term-memory/end-user-management.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-unity-sdk/features/long-term-memory/configure-memory-for-a-character.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.
