lintsinghua
Committed by BaiFu

Fix agent temporal perception error by adding current real-world time to LLM prompt.

@@ -211,6 +211,13 @@ class ForumHost: @@ -211,6 +211,13 @@ class ForumHost:
211 def _call_qwen_api(self, system_prompt: str, user_prompt: str) -> Dict[str, Any]: 211 def _call_qwen_api(self, system_prompt: str, user_prompt: str) -> Dict[str, Any]:
212 """调用Qwen API""" 212 """调用Qwen API"""
213 try: 213 try:
  214 + current_time = datetime.now().strftime("%Y年%m月%d日%H时%M分")
  215 + time_prefix = f"今天的实际时间是{current_time}"
  216 + if user_prompt:
  217 + user_prompt = f"{time_prefix}\n{user_prompt}"
  218 + else:
  219 + user_prompt = time_prefix
  220 +
214 response = self.client.chat.completions.create( 221 response = self.client.chat.completions.create(
215 model=self.model, 222 model=self.model,
216 messages=[ 223 messages=[
@@ -4,6 +4,7 @@ Unified OpenAI-compatible LLM client for the Insight Engine, with retry support. @@ -4,6 +4,7 @@ Unified OpenAI-compatible LLM client for the Insight Engine, with retry support.
4 4
5 import os 5 import os
6 import sys 6 import sys
  7 +from datetime import datetime
7 from typing import Any, Dict, Optional 8 from typing import Any, Dict, Optional
8 9
9 from openai import OpenAI 10 from openai import OpenAI
@@ -54,6 +55,12 @@ class LLMClient: @@ -54,6 +55,12 @@ class LLMClient:
54 55
55 @with_retry(LLM_RETRY_CONFIG) 56 @with_retry(LLM_RETRY_CONFIG)
56 def invoke(self, system_prompt: str, user_prompt: str, **kwargs) -> str: 57 def invoke(self, system_prompt: str, user_prompt: str, **kwargs) -> str:
  58 + current_time = datetime.now().strftime("%Y年%m月%d日%H时%M分")
  59 + time_prefix = f"今天的实际时间是{current_time}"
  60 + if user_prompt:
  61 + user_prompt = f"{time_prefix}\n{user_prompt}"
  62 + else:
  63 + user_prompt = time_prefix
57 messages = [ 64 messages = [
58 {"role": "system", "content": system_prompt}, 65 {"role": "system", "content": system_prompt},
59 {"role": "user", "content": user_prompt}, 66 {"role": "user", "content": user_prompt},
@@ -4,6 +4,7 @@ Unified OpenAI-compatible LLM client for the Media Engine, with retry support. @@ -4,6 +4,7 @@ Unified OpenAI-compatible LLM client for the Media Engine, with retry support.
4 4
5 import os 5 import os
6 import sys 6 import sys
  7 +from datetime import datetime
7 from typing import Any, Dict, Optional 8 from typing import Any, Dict, Optional
8 9
9 from openai import OpenAI 10 from openai import OpenAI
@@ -57,6 +58,12 @@ class LLMClient: @@ -57,6 +58,12 @@ class LLMClient:
57 58
58 @with_retry(LLM_RETRY_CONFIG) 59 @with_retry(LLM_RETRY_CONFIG)
59 def invoke(self, system_prompt: str, user_prompt: str, **kwargs) -> str: 60 def invoke(self, system_prompt: str, user_prompt: str, **kwargs) -> str:
  61 + current_time = datetime.now().strftime("%Y年%m月%d日%H时%M分")
  62 + time_prefix = f"今天的实际时间是{current_time}"
  63 + if user_prompt:
  64 + user_prompt = f"{time_prefix}\n{user_prompt}"
  65 + else:
  66 + user_prompt = time_prefix
60 messages = [ 67 messages = [
61 {"role": "system", "content": system_prompt}, 68 {"role": "system", "content": system_prompt},
62 {"role": "user", "content": user_prompt}, 69 {"role": "user", "content": user_prompt},
@@ -4,6 +4,7 @@ Unified OpenAI-compatible LLM client for the Query Engine, with retry support. @@ -4,6 +4,7 @@ Unified OpenAI-compatible LLM client for the Query Engine, with retry support.
4 4
5 import os 5 import os
6 import sys 6 import sys
  7 +from datetime import datetime
7 from typing import Any, Dict, Optional 8 from typing import Any, Dict, Optional
8 9
9 from openai import OpenAI 10 from openai import OpenAI
@@ -54,6 +55,12 @@ class LLMClient: @@ -54,6 +55,12 @@ class LLMClient:
54 55
55 @with_retry(LLM_RETRY_CONFIG) 56 @with_retry(LLM_RETRY_CONFIG)
56 def invoke(self, system_prompt: str, user_prompt: str, **kwargs) -> str: 57 def invoke(self, system_prompt: str, user_prompt: str, **kwargs) -> str:
  58 + current_time = datetime.now().strftime("%Y年%m月%d日%H时%M分")
  59 + time_prefix = f"今天的实际时间是{current_time}"
  60 + if user_prompt:
  61 + user_prompt = f"{time_prefix}\n{user_prompt}"
  62 + else:
  63 + user_prompt = time_prefix
57 messages = [ 64 messages = [
58 {"role": "system", "content": system_prompt}, 65 {"role": "system", "content": system_prompt},
59 {"role": "user", "content": user_prompt}, 66 {"role": "user", "content": user_prompt},