fix: dedupe preset messages#4961
Merged
Soulter merged 1 commit intoAstrBotDevs:masterfrom Feb 8, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审质量。
Original comment in English
Hey - I've left some high level feedback:
- In
tool_loop_agent_runner.reset,_no_saveis only propagated whenrequest.contextsitems are dicts; consider also preserving_no_savewhen the context item is already aMessageinstance (e.g., viahasattr(msg, "_no_save")) so the flag isn't lost in those cases. - Since
_no_saveis declared as aPrivateAttr, 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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Soulter
approved these changes
Feb 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复预设对话重复注入的问题
Modifications / 改动点
添加_no_save私有字段
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.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:
Enhancements:
_no_saveattribute onMessageand propagate it through request contexts to control which assistant and user messages are persisted.Bug 修复:
增强功能:
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:
Enhancements:
_no_saveattribute onMessageand propagate it through request contexts to control which assistant and user messages are persisted.