feat: add datetime prompt scope option#9190
Conversation
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- When reading
datetime_system_prompt_scope, consider providing an explicit default (e.g.cfg.get("datetime_system_prompt_scope", "history")) so older configs or missing keys keep the existing behavior instead of silently switching to temporary prompts. - The
has_datetimeflag currently drives whether the entire<system_reminder>block is temporary; if additional non-datetime reminders are added later, this may unintentionally make them temporary as well—consider scoping the temp behavior to just the datetime part or documenting this coupling clearly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- When reading `datetime_system_prompt_scope`, consider providing an explicit default (e.g. `cfg.get("datetime_system_prompt_scope", "history")`) so older configs or missing keys keep the existing behavior instead of silently switching to temporary prompts.
- The `has_datetime` flag currently drives whether the entire `<system_reminder>` block is temporary; if additional non-datetime reminders are added later, this may unintentionally make them temporary as well—consider scoping the temp behavior to just the datetime part or documenting this coupling clearly.
## Individual Comments
### Comment 1
<location path="astrbot/core/astr_main_agent.py" line_range="934-937" />
<code_context>
timezone: str | None,
) -> None:
system_parts: list[str] = []
+ has_datetime = False
if cfg.get("identifier"):
user_id = event.message_obj.sender.user_id
</code_context>
<issue_to_address>
**issue (bug_risk):** Temporary scope for datetime also affects other system reminders bundled in the same TextPart.
When `datetime_system_prompt_scope` is not `"history"`, the entire `<system_reminder>` is placed in a single temp `TextPart`. As a result, identifier and any other reminders become temporary too and are not persisted, even though the toggle is meant to control only the datetime. If only the datetime should be temporary, consider splitting it into its own `TextPart` (or otherwise separating system reminder components) so the temp flag applies only to the datetime content.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
This pull request introduces a new configuration option, datetime_system_prompt_scope, allowing users to choose whether the current datetime system prompt is saved to the chat history or only included in the current request to improve prompt caching. The review feedback correctly identifies a critical issue where setting the scope to 'current' inadvertently bundles all system reminders together and marks the entire block as temporary, which incorrectly excludes other persistent reminders (like user identifiers) from the chat history. The reviewer provides a solid suggestion to separate the datetime reminder from other system reminders so that only the datetime reminder is marked as temporary.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| timezone: str | None, | ||
| ) -> None: | ||
| system_parts: list[str] = [] | ||
| has_datetime = False |
There was a problem hiding this comment.
Initialize datetime_part as None instead of using a boolean flag has_datetime. This will allow us to handle the datetime reminder separately from other persistent system reminders (like user identifier and group name) when the scope is set to 'current'.
| has_datetime = False | |
| datetime_part: str | None = None |
| current_time = now.strftime("%Y-%m-%d %H:%M (%Z)") | ||
| weekday = WEEKDAY_NAMES[now.weekday()] | ||
| system_parts.append(f"Current datetime: {current_time}, Weekday: {weekday}") | ||
| has_datetime = True | ||
|
|
||
| if system_parts: | ||
| system_content = ( | ||
| "<system_reminder>" + "\n".join(system_parts) + "</system_reminder>" | ||
| ) | ||
| req.extra_user_content_parts.append(TextPart(text=system_content)) | ||
| system_part = TextPart(text=system_content) | ||
| req.extra_user_content_parts.append( | ||
| system_part | ||
| if not has_datetime or cfg.get("datetime_system_prompt_scope") == "history" | ||
| else system_part.mark_as_temp() | ||
| ) |
There was a problem hiding this comment.
When datetime_system_prompt_scope is set to 'current', the current implementation bundles all system reminders (including user identifier and group name display) into a single system_content block and marks the entire block as temporary (mark_as_temp()). This causes other persistent reminders to also be excluded from the chat history, which is unintended.
To fix this, keep the datetime reminder separate from other system reminders when the scope is 'current', and only mark the datetime reminder as temporary.
current_time = now.strftime("%Y-%m-%d %H:%M (%Z)")
weekday = WEEKDAY_NAMES[now.weekday()]
datetime_part = f"Current datetime: {current_time}, Weekday: {weekday}"
if datetime_part and cfg.get("datetime_system_prompt_scope") == "history":
system_parts.append(datetime_part)
datetime_part = None
if system_parts:
system_content = (
"<system_reminder>" + "\n".join(system_parts) + "</system_reminder>"
)
req.extra_user_content_parts.append(TextPart(text=system_content))
if datetime_part:
datetime_content = (
"<system_reminder>" + datetime_part + "</system_reminder>"
)
req.extra_user_content_parts.append(TextPart(text=datetime_content).mark_as_temp())6ac5867 to
19279b6
Compare
|
Addressed the review feedback in
|
Refs #9189
Modifications / 改动点
Add
provider_settings.datetime_system_prompt_scopewith two modes:history: keep the existing behavior and write datetime reminders into chat history.current: include the latest datetime only in the current request and mark it as temporary so it is not saved into history.Keep the default as
historyto avoid changing existing behavior.Add dashboard config metadata and zh-CN/en-US translations for the new option.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
Checklist / 检查清单
😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
/ 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。
👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
/ 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。
🤓 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.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。