Add a single task result and update the file.
(self, task_data: Any, processing_time: float = None,
optimizer_data: Dict[str, Any] = None)
| 90 | self._save_to_file() |
| 91 | |
| 92 | def add_task_result(self, task_data: Any, processing_time: float = None, |
| 93 | optimizer_data: Dict[str, Any] = None): |
| 94 | """Add a single task result and update the file.""" |
| 95 | _, answer = parse_agent_result(task_data.result) |
| 96 | |
| 97 | task_result = {"task_id": task_data.task_id, |
| 98 | "task_input": task_data.input, |
| 99 | "ground_truth": str(task_data.ground_truth), |
| 100 | "result": answer, |
| 101 | "reasoning": getattr(task_data, 'reasoning', ""), |
| 102 | "correct": getattr(task_data, 'result', "") == str(task_data.ground_truth), |
| 103 | "processing_time": processing_time, "reflection_process": { |
| 104 | "initial_reasoning": optimizer_data.get("initial_agent_reasoning", ""), |
| 105 | "initial_result": optimizer_data.get("initial_agent_result", ""), |
| 106 | "reflection_rounds": [] |
| 107 | }} |
| 108 | |
| 109 | # Add detailed reflection process data for reflection optimizer |
| 110 | |
| 111 | # Process each reflection round |
| 112 | reflection_texts = optimizer_data.get("reflecion_text", []) |
| 113 | improved_solutions = optimizer_data.get("improved_solution", []) |
| 114 | |
| 115 | max_rounds = max(len(reflection_texts), len(improved_solutions)) |
| 116 | for i in range(max_rounds): |
| 117 | round_data = {} |
| 118 | |
| 119 | # Add reflection text for this round |
| 120 | if i < len(reflection_texts): |
| 121 | round_data["reflection_text"] = reflection_texts[i] |
| 122 | |
| 123 | # Add improved solution for this round |
| 124 | if i < len(improved_solutions): |
| 125 | round_data["improved_solution"] = improved_solutions[i] |
| 126 | |
| 127 | if round_data: |
| 128 | task_result["reflection_process"]["reflection_rounds"].append(round_data) |
| 129 | |
| 130 | # Final results |
| 131 | task_result["reflection_process"]["final_reasoning"] = optimizer_data.get("agent_reasoning", "") |
| 132 | task_result["reflection_process"]["final_result"] = optimizer_data.get("agent_result", "") |
| 133 | |
| 134 | self.results_data["results"].append(task_result) |
| 135 | |
| 136 | # Update summary |
| 137 | self.results_data["summary"]["completed_tasks"] = len(self.results_data["results"]) |
| 138 | correct_count = sum(1 for r in self.results_data["results"] if r["correct"]) |
| 139 | self.results_data["summary"]["correct_answers"] = correct_count |
| 140 | self.results_data["summary"]["accuracy"] = correct_count / len(self.results_data["results"]) if self.results_data["results"] else 0.0 |
| 141 | self.results_data["summary"]["last_updated"] = datetime.now().isoformat() + "Z" |
| 142 | |
| 143 | # Save updated results |
| 144 | self._save_to_file() |
| 145 | |
| 146 | def _save_to_file(self): |
| 147 | """Save current results to JSON file.""" |
no test coverage detected