> 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. 选择 **Memory** 角色设置侧边栏中的选项卡。
4. 切换 **长期记忆** 到 **在**.
5. 单击 **保存**.

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

{% tab title="脚本编写" %}
使用 `client.Characters` 当您需要程序化控制时——例如在自动化测试设置、构建流水线或运行时管理面板中。

**检查当前状态**

```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("Long-term memory enabled.");
    }
}
```

**禁用记忆**

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