Skip to content

fix: dedupe preset messages#4961

Merged
Soulter merged 1 commit intoAstrBotDevs:masterfrom
Raven95676:fix/persona-begin-dialog-dup-persist
Feb 8, 2026
Merged

fix: dedupe preset messages#4961
Soulter merged 1 commit intoAstrBotDevs:masterfrom
Raven95676:fix/persona-begin-dialog-dup-persist

Conversation

@Raven95676
Copy link
Member

@Raven95676 Raven95676 commented Feb 8, 2026

修复预设对话重复注入的问题

Modifications / 改动点

添加_no_save私有字段

  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果


Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

确保预设人物对话消息被视为不持久化的数据,这样它们就不会在会话历史中被反复重新注入。

Bug 修复:

  • 通过遵守消息上的非持久化标记,防止预设人物对话消息被保存到会话历史中并从中被反复重新注入。

功能增强:

  • Message 上引入私有属性 _no_save,并在请求上下文中进行传递,以控制哪些助手和用户消息需要被持久化。
Original summary in English

Summary by Sourcery

Ensure preset persona dialogue messages are treated as non-persisted so they are not repeatedly re-injected into conversation history.

Bug Fixes:

  • Prevent preset persona dialogue messages from being saved to and repeatedly re-injected from conversation history by honoring a non-persisted flag on messages.

Enhancements:

  • Introduce a private _no_save attribute on Message and propagate it through request contexts to control which assistant and user messages are persisted.

Bug 修复:

  • 确保预设人格(persona)对话消息被标记为不持久化(non-persisted),从而不会被反复重新注入到对话历史中。

增强功能:

  • Message 上引入私有的 _no_save 标志,并通过请求上下文进行传递,以控制哪些消息需要被持久化。
Original summary in English

Summary by Sourcery

确保预设人物对话消息被视为不持久化的数据,这样它们就不会在会话历史中被反复重新注入。

Bug 修复:

  • 通过遵守消息上的非持久化标记,防止预设人物对话消息被保存到会话历史中并从中被反复重新注入。

功能增强:

  • Message 上引入私有属性 _no_save,并在请求上下文中进行传递,以控制哪些助手和用户消息需要被持久化。
Original summary in English

Summary by Sourcery

Ensure preset persona dialogue messages are treated as non-persisted so they are not repeatedly re-injected into conversation history.

Bug Fixes:

  • Prevent preset persona dialogue messages from being saved to and repeatedly re-injected from conversation history by honoring a non-persisted flag on messages.

Enhancements:

  • Introduce a private _no_save attribute on Message and propagate it through request contexts to control which assistant and user messages are persisted.

@Raven95676 Raven95676 marked this pull request as ready for review February 8, 2026 14:08
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Feb 8, 2026
@dosubot
Copy link

dosubot bot commented Feb 8, 2026

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给出了一些总体反馈:

  • tool_loop_agent_runner.reset 中,只有当 request.contexts 的元素是 dict 时,_no_save 才会被向下传递;建议在上下文元素已经是 Message 实例时同样保留 _no_save(例如通过 hasattr(msg, "_no_save") 检查),这样在这些场景下该标志就不会丢失。
  • 由于 _no_save 被声明为 PrivateAttr,直接从外部的 dict 数据写入该字段会在一定程度上破坏封装;你可能希望将这类映射逻辑集中处理(例如通过一个 helper 或 factory),这样如果以后私有属性的处理方式有变化,相关行为会更容易审查和调整。
给 AI Agents 的提示
Please address the comments from this code review:

## Overall Comments
- In `tool_loop_agent_runner.reset`, `_no_save` is only propagated when `request.contexts` items are dicts; consider also preserving `_no_save` when the context item is already a `Message` instance (e.g., via `hasattr(msg, "_no_save")`) so the flag isn't lost in those cases.
- Since `_no_save` is declared as a `PrivateAttr`, directly setting it from external dict data slightly breaks the encapsulation; you might want to centralize this mapping (e.g., via a helper or factory) so the behavior is easier to audit and adjust if the private attribute handling changes.

Sourcery 对开源项目永久免费——如果你觉得我们的评审有帮助,欢迎分享给更多人 ✨
帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审质量。
Original comment in English

Hey - I've left some high level feedback:

  • In tool_loop_agent_runner.reset, _no_save is only propagated when request.contexts items are dicts; consider also preserving _no_save when the context item is already a Message instance (e.g., via hasattr(msg, "_no_save")) so the flag isn't lost in those cases.
  • Since _no_save is declared as a PrivateAttr, directly setting it from external dict data slightly breaks the encapsulation; you might want to centralize this mapping (e.g., via a helper or factory) so the behavior is easier to audit and adjust if the private attribute handling changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `tool_loop_agent_runner.reset`, `_no_save` is only propagated when `request.contexts` items are dicts; consider also preserving `_no_save` when the context item is already a `Message` instance (e.g., via `hasattr(msg, "_no_save")`) so the flag isn't lost in those cases.
- Since `_no_save` is declared as a `PrivateAttr`, directly setting it from external dict data slightly breaks the encapsulation; you might want to centralize this mapping (e.g., via a helper or factory) so the behavior is easier to audit and adjust if the private attribute handling changes.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot dosubot bot added the feature:persona The bug / feature is about astrbot AI persona system (system prompt) label Feb 8, 2026
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 8, 2026
@Soulter Soulter merged commit eca3ede into AstrBotDevs:master Feb 8, 2026
6 checks passed
@Raven95676 Raven95676 deleted the fix/persona-begin-dialog-dup-persist branch February 8, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature:persona The bug / feature is about astrbot AI persona system (system prompt) lgtm This PR has been approved by a maintainer size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants