diff --git a/astrbot/core/astr_main_agent.py b/astrbot/core/astr_main_agent.py index ee007140b..cee6e9e27 100644 --- a/astrbot/core/astr_main_agent.py +++ b/astrbot/core/astr_main_agent.py @@ -115,6 +115,15 @@ from astrbot.core.utils.quoted_message_parser import ( from astrbot.core.utils.string_utils import normalize_and_dedupe_strings LLM_ERROR_MESSAGE_EXTRA_KEY = "_llm_error_message" +WEEKDAY_NAMES = ( + "Monday", + "Tuesday", + "Wednesday", + "Thursday", + "Friday", + "Saturday", + "Sunday", +) WEB_SEARCH_CITATION_TOOL_NAMES = frozenset( { "web_search_baidu", @@ -874,18 +883,17 @@ def _append_system_reminders( system_parts.append(f"Group name: {group_name}") if cfg.get("datetime_system_prompt"): - current_time = None + now = None if timezone: try: now = datetime.datetime.now(zoneinfo.ZoneInfo(timezone)) - current_time = now.strftime("%Y-%m-%d %H:%M (%Z)") except Exception as exc: # noqa: BLE001 logger.error("时区设置错误: %s, 使用本地时区", exc) - if not current_time: - current_time = ( - datetime.datetime.now().astimezone().strftime("%Y-%m-%d %H:%M (%Z)") - ) - system_parts.append(f"Current datetime: {current_time}") + if now is None: + now = datetime.datetime.now().astimezone() + 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}") if system_parts: system_content = ( diff --git a/tests/unit/test_astr_main_agent.py b/tests/unit/test_astr_main_agent.py index 84f354894..31c80e09e 100644 --- a/tests/unit/test_astr_main_agent.py +++ b/tests/unit/test_astr_main_agent.py @@ -1,5 +1,6 @@ """Tests for astr_main_agent module.""" +import datetime import os from unittest.mock import AsyncMock, MagicMock, patch @@ -134,6 +135,39 @@ def _setup_conversation_for_build(conv_mgr, cid: str = "conv-id") -> MagicMock: return conversation +def test_append_system_reminders_includes_weekday(mock_event): + """Test datetime reminder includes weekday information.""" + req = ProviderRequest(prompt="Hello") + fixed_now = datetime.datetime( + 2026, + 6, + 8, + 12, + 34, + tzinfo=datetime.timezone.utc, + ) + + class FixedDateTime(datetime.datetime): + @classmethod + def now(cls, tz=None): + if tz: + return fixed_now.astimezone(tz) + return fixed_now + + with patch("astrbot.core.astr_main_agent.datetime.datetime", FixedDateTime): + ama._append_system_reminders( + mock_event, + req, + {"datetime_system_prompt": True}, + "UTC", + ) + + assert [part.text for part in req.extra_user_content_parts] == [ + "Current datetime: " + "2026-06-08 12:34 (UTC), Weekday: Monday" + ] + + class TestMainAgentBuildConfig: """Tests for MainAgentBuildConfig dataclass."""