diff --git a/xmpp_agent_core.py b/xmpp_agent_core.py index d8ea6cc4..3cdb0e6e 100644 --- a/xmpp_agent_core.py +++ b/xmpp_agent_core.py @@ -186,9 +186,20 @@ class AgentBot(ClientXMPP): msg_type = 'groupchat' if is_group else 'chat' sid = session_id or SESSION_ID try: - # 注入当前日期时间,防止LLM日期幻觉 - now_str = datetime.now().strftime("%Y-%m-%d %H:%M %A") - timed_content = f"[当前时间: {now_str}]\n{content}" + # 注入当前时间 + 市场状态,防止LLM日期/交易时段幻觉 + now = datetime.datetime.now() + weekday = now.strftime("%A") + hour = now.hour + minute = now.minute + # 判断市场状态 + is_weekday = now.weekday() < 5 + if is_weekday: + ashare = "交易中" if (9 <= hour < 15) or (hour == 9 and minute >= 30) or (hour == 15 and minute == 0) else "已收盘" + hk = "交易中" if (9 <= hour < 16) or (hour == 9 and minute >= 30) or (hour == 15) else "已收盘" + else: + ashare = hk = "休市" + now_str = now.strftime("%Y-%m-%d %H:%M") + timed_content = f"[{now_str} {weekday} | A股{ashare} 港股{hk}]\n{content}" payload = json.dumps({ "model": "hermes-agent", "messages": [{"role": "user", "content": timed_content}]