# 在AI人设系统提示中添加{username}作为模板参数

**URL:** <https://meta.discourse.org/t/add-username-as-a-template-param-in-ai-persona-system-prompts/406846>\
**Category:** Feature\
**Tags:** completed, ai\
**Created:** [2026年七月5日 00:30 UTC](https://meta.discourse.org/t/add-username-as-a-template-param-in-ai-persona-system-prompts/406846 "2026-07-05T00:30:59Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![42aross](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/42aross/32/569643_2.png) [@42aross](https://meta.discourse.org/u/42aross)\
**Post date:** [2026年七月5日 00:30 UTC](https://meta.discourse.org/t/add-username-as-a-template-param-in-ai-persona-system-prompts/406846/1 "2026-07-05T00:30:59Z")

</div>

这是我第一次参与贡献。如果我在过程中有什么疏漏，我深表歉意，并且非常感谢您的耐心以及任何建议，如果有更好的方法的话。

虽然这微不足道，但我是一名 Pro 用户。

我需要一种可靠的方式来识别与 AI 代理交互的用户。这就是我提出的解决方案。非常感谢您抽出时间考虑，并提供任何建议。

在 AI 角色系统提示中添加 `{username}` 作为模板参数

我提交了 PR #41446（ [FEATURE: Add {username} template param to BotContext - Pull Request #41446 - discourse/discourse - GitHub](https://github.com/discourse/discourse/pull/41446) ），将 `{username}` 添加到 `BotContext::TEMPLATE_PARAMS` 中。

使用场景：作为与外部服务桥梁的角色需要在服务器端解析当前用户的身份，而不是由 LLM 从帖子文本中推断。目前还没有一种干净的方法来实现这一点。`{participants}` 仅在私信中填充，而要求 LLM 从主题元数据中解析用户名则容易出错且存在注入风险。

此更改很小（新增一个方法，在允许列表中添加一个字符串）且为附加性质。除非现有提示中已经包含字面意义上的 `{username}`，否则它们不会受到影响。

再次感谢！

---

_[View the full topic](https://meta.discourse.org/t/add-username-as-a-template-param-in-ai-persona-system-prompts/406846)._
