瀏覽代碼

删除[Formatted Output]字符的输出,准备增加详细的日志,排查二次对话返回为空的问题。

wangxq 1 月之前
父節點
當前提交
29ac9a1418

+ 11 - 6
test/custom_react_agent/agent.py

@@ -489,7 +489,9 @@ class CustomReactAgent:
                         clean_history.append({"type": "human", "content": msg.content})
                     elif isinstance(msg, AIMessage):
                         if not msg.tool_calls and msg.content:
-                            clean_content = msg.content.replace("[Formatted Output]\n", "").strip()
+                            # 注释掉 [Formatted Output] 清理逻辑 - 源头已不生成前缀
+                            # clean_content = msg.content.replace("[Formatted Output]\n", "").strip()
+                            clean_content = msg.content.strip()
                             if clean_content:
                                 clean_history.append({"type": "ai", "content": clean_content})
                 
@@ -522,8 +524,9 @@ class CustomReactAgent:
             elif isinstance(msg, AIMessage):
                 # 只保留最终的、面向用户的回答(不包含工具调用的纯文本回答)
                 if not msg.tool_calls and msg.content:
-                    # 移除可能存在的格式化标记
-                    clean_content = msg.content.replace("[Formatted Output]\n", "").strip()
+                    # 注释掉 [Formatted Output] 清理逻辑 - 源头已不生成前缀
+                    # clean_content = msg.content.replace("[Formatted Output]\n", "").strip()
+                    clean_content = msg.content.strip()
                     if clean_content:
                         clean_history.append({"type": "ai", "content": clean_content})
         
@@ -578,7 +581,8 @@ class CustomReactAgent:
         
         # 保持原有的消息格式化(用于shell.py兼容)
         last_message = state['messages'][-1]
-        last_message.content = f"[Formatted Output]\n{last_message.content}"
+        # 注释掉前缀添加,直接使用原始内容
+        # last_message.content = f"[Formatted Output]\n{last_message.content}"
         
         # 生成API格式的数据
         api_data = await self._async_generate_api_data(state)
@@ -600,8 +604,9 @@ class CustomReactAgent:
         last_message = state['messages'][-1]
         response_content = last_message.content
         
-        if response_content.startswith("[Formatted Output]\n"):
-            response_content = response_content.replace("[Formatted Output]\n", "")
+        # 注释掉 [Formatted Output] 清理逻辑 - 源头已不生成前缀
+        # if response_content.startswith("[Formatted Output]\n"):
+        #     response_content = response_content.replace("[Formatted Output]\n", "")
         
         api_data = {
             "response": response_content

+ 1 - 1
test/custom_react_agent/config.py

@@ -15,7 +15,7 @@ PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(_
 # qwen3-30b-a3b
 QWEN_API_KEY = "sk-db68e37f00974031935395315bfe07f0"
 QWEN_BASE_URL = "https://dashscope.aliyuncs.com/compatible-mode/v1"
-QWEN_MODEL = "qwen3-235b-a22b"
+QWEN_MODEL = "qwen-plus"
 
 # --- Redis 配置 ---
 REDIS_URL = "redis://localhost:6379"

+ 16 - 16
test/custom_react_agent/enhanced_redis_api.py

@@ -309,22 +309,22 @@ def clean_ai_message_for_simple_mode(ai_msg: Dict[str, Any]) -> Dict[str, Any]:
     # 处理内容格式化
     content = original_content.strip()
     
-    # 调试:检查 [Formatted Output] 处理
-    if '[Formatted Output]' in content:
-        logger.info(f"🔍 发现 [Formatted Output] 标记")
-        
-        if content.startswith('[Formatted Output]\n'):
-            # 去掉标记,保留后面的实际内容
-            actual_content = content.replace('[Formatted Output]\n', '')
-            logger.info(f"🔍 去除标记后的内容: '{actual_content}', 长度: {len(actual_content)}")
-            cleaned_msg["content"] = actual_content
-            content = actual_content
-        elif content == '[Formatted Output]' or content == '[Formatted Output]\n':
-            # 如果只有标记没有内容
-            logger.info(f"🔍 只有标记没有实际内容")
-            cleaned_msg["content"] = ""
-            cleaned_msg["is_intermediate_step"] = True
-            content = ""
+    # 注释掉 [Formatted Output] 清理逻辑 - 源头已不生成前缀
+    # if '[Formatted Output]' in content:
+    #     logger.info(f"🔍 发现 [Formatted Output] 标记")
+    #     
+    #     if content.startswith('[Formatted Output]\n'):
+    #         # 去掉标记,保留后面的实际内容
+    #         actual_content = content.replace('[Formatted Output]\n', '')
+    #         logger.info(f"🔍 去除标记后的内容: '{actual_content}', 长度: {len(actual_content)}")
+    #         cleaned_msg["content"] = actual_content
+    #         content = actual_content
+    #     elif content == '[Formatted Output]' or content == '[Formatted Output]\n':
+    #         # 如果只有标记没有内容
+    #         logger.info(f"🔍 只有标记没有实际内容")
+    #         cleaned_msg["content"] = ""
+    #         cleaned_msg["is_intermediate_step"] = True
+    #         content = ""
     
     # 如果清理后内容为空或只有空白,标记为中间步骤
     if not content.strip():

+ 3 - 3
test/custom_react_agent/shell.py

@@ -226,9 +226,9 @@ class CustomAgentShell:
             
             if result.get("success"):
                 answer = result.get('answer', '')
-                # 去除 [Formatted Output] 标记,只显示真正的回答
-                if answer.startswith("[Formatted Output]\n"):
-                    answer = answer.replace("[Formatted Output]\n", "")
+                # 注释掉 [Formatted Output] 清理逻辑 - 源头已不生成前缀
+                # if answer.startswith("[Formatted Output]\n"):
+                #     answer = answer.replace("[Formatted Output]\n", "")
                 
                 print(f"🤖 Agent: {answer}")