diff --git a/data_analysis_agent.py b/data_analysis_agent.py index 4b672b2..14883df 100644 --- a/data_analysis_agent.py +++ b/data_analysis_agent.py @@ -131,16 +131,25 @@ class DataAnalysisAgent: print(f" 📝 描述: {description}") print(f" 🔍 分析: {analysis}") - # 记录图片信息 - collected_figures.append( - { - "figure_number": figure_number, - "filename": filename, - "file_path": file_path, - "description": description, - "analysis": analysis, - } - ) + # 验证文件是否存在 + # 只有文件真正存在时才加入列表,防止报告出现裂图 + if file_path and os.path.exists(file_path): + print(f" ✅ 文件存在: {file_path}") + # 记录图片信息 + collected_figures.append( + { + "figure_number": figure_number, + "filename": filename, + "file_path": file_path, + "description": description, + "analysis": analysis, + } + ) + else: + if file_path: + print(f" ⚠️ 文件不存在: {file_path}") + else: + print(f" ⚠️ 未提供文件路径") return { "action": "collect_figures", @@ -317,7 +326,11 @@ class DataAnalysisAgent: elif process_result["action"] == "collect_figures": # 记录图片收集结果 collected_figures = process_result.get("collected_figures", []) - feedback = f"已收集 {len(collected_figures)} 个图片及其分析" + missing_figures = process_result.get("missing_figures", []) + + feedback = f"已收集 {len(collected_figures)} 个有效图片及其分析。" + if missing_figures: + feedback += f"\n⚠️ 以下图片未找到,请检查代码是否成功保存了这些图片: {missing_figures}" self.conversation_history.append( { "role": "user", @@ -331,6 +344,7 @@ class DataAnalysisAgent: "round": self.current_round, "action": "collect_figures", "collected_figures": collected_figures, + "missing_figures": missing_figures, "response": response, } )