Skip to content

Commit 0fb3f5e

Browse files
feat: display current weekday information (#8669)
在现实世界时间感知提示中追加 Weekday 字段,让模型能直接获取今天是星期几。\n\n使用固定英文星期表避免受系统 locale 影响,并补充单测覆盖输出格式。 Co-authored-by: C₂₂H₂₅NO₆ <Sisyphbaous-DT-Project@users.noreply.github.com>
1 parent 4b56268 commit 0fb3f5e

2 files changed

Lines changed: 49 additions & 7 deletions

File tree

astrbot/core/astr_main_agent.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,15 @@
115115
from astrbot.core.utils.string_utils import normalize_and_dedupe_strings
116116

117117
LLM_ERROR_MESSAGE_EXTRA_KEY = "_llm_error_message"
118+
WEEKDAY_NAMES = (
119+
"Monday",
120+
"Tuesday",
121+
"Wednesday",
122+
"Thursday",
123+
"Friday",
124+
"Saturday",
125+
"Sunday",
126+
)
118127
WEB_SEARCH_CITATION_TOOL_NAMES = frozenset(
119128
{
120129
"web_search_baidu",
@@ -874,18 +883,17 @@ def _append_system_reminders(
874883
system_parts.append(f"Group name: {group_name}")
875884

876885
if cfg.get("datetime_system_prompt"):
877-
current_time = None
886+
now = None
878887
if timezone:
879888
try:
880889
now = datetime.datetime.now(zoneinfo.ZoneInfo(timezone))
881-
current_time = now.strftime("%Y-%m-%d %H:%M (%Z)")
882890
except Exception as exc: # noqa: BLE001
883891
logger.error("时区设置错误: %s, 使用本地时区", exc)
884-
if not current_time:
885-
current_time = (
886-
datetime.datetime.now().astimezone().strftime("%Y-%m-%d %H:%M (%Z)")
887-
)
888-
system_parts.append(f"Current datetime: {current_time}")
892+
if now is None:
893+
now = datetime.datetime.now().astimezone()
894+
current_time = now.strftime("%Y-%m-%d %H:%M (%Z)")
895+
weekday = WEEKDAY_NAMES[now.weekday()]
896+
system_parts.append(f"Current datetime: {current_time}, Weekday: {weekday}")
889897

890898
if system_parts:
891899
system_content = (

tests/unit/test_astr_main_agent.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for astr_main_agent module."""
22

3+
import datetime
34
import os
45
from unittest.mock import AsyncMock, MagicMock, patch
56

@@ -134,6 +135,39 @@ def _setup_conversation_for_build(conv_mgr, cid: str = "conv-id") -> MagicMock:
134135
return conversation
135136

136137

138+
def test_append_system_reminders_includes_weekday(mock_event):
139+
"""Test datetime reminder includes weekday information."""
140+
req = ProviderRequest(prompt="Hello")
141+
fixed_now = datetime.datetime(
142+
2026,
143+
6,
144+
8,
145+
12,
146+
34,
147+
tzinfo=datetime.timezone.utc,
148+
)
149+
150+
class FixedDateTime(datetime.datetime):
151+
@classmethod
152+
def now(cls, tz=None):
153+
if tz:
154+
return fixed_now.astimezone(tz)
155+
return fixed_now
156+
157+
with patch("astrbot.core.astr_main_agent.datetime.datetime", FixedDateTime):
158+
ama._append_system_reminders(
159+
mock_event,
160+
req,
161+
{"datetime_system_prompt": True},
162+
"UTC",
163+
)
164+
165+
assert [part.text for part in req.extra_user_content_parts] == [
166+
"<system_reminder>Current datetime: "
167+
"2026-06-08 12:34 (UTC), Weekday: Monday</system_reminder>"
168+
]
169+
170+
137171
class TestMainAgentBuildConfig:
138172
"""Tests for MainAgentBuildConfig dataclass."""
139173

0 commit comments

Comments
 (0)