Memory module for storing and retrieving historical information from: 1. Idea generation outputs (ideas_*.json files) 2. Experiment execution notes (notes.txt files)
| 727 | # Memory Module |
| 728 | # ============================================================================ |
| 729 | class MemoryModule: |
| 730 | """ |
| 731 | Memory module for storing and retrieving historical information from: |
| 732 | 1. Idea generation outputs (ideas_*.json files) |
| 733 | 2. Experiment execution notes (notes.txt files) |
| 734 | """ |
| 735 | |
| 736 | def __init__(self, logger: Optional[logging.Logger] = None): |
| 737 | """ |
| 738 | Initialize the memory module |
| 739 | |
| 740 | Args: |
| 741 | logger: Logger instance for logging operations |
| 742 | """ |
| 743 | self.logger = logger or logging.getLogger("MemoryModule") |
| 744 | self.ideas_history: List[Dict] = [] |
| 745 | self.notes_history: List[Dict] = [] |
| 746 | self.memory_data: Dict = { |
| 747 | 'ideas': [], |
| 748 | 'experiments': [], |
| 749 | 'summary': { |
| 750 | 'total_ideas': 0, |
| 751 | 'total_experiments': 0, |
| 752 | 'successful_experiments': 0, |
| 753 | 'failed_experiments': 0 |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | def load_idea_generation_output(self, idea_file_path: str) -> Dict: |
| 758 | """ |
| 759 | Load idea generation output from a JSON file |
| 760 | |
| 761 | Args: |
| 762 | idea_file_path: Path to the ideas JSON file (e.g., results/{task}/ideas_{session_id}.json) |
| 763 | |
| 764 | Returns: |
| 765 | Dictionary containing the loaded ideas |
| 766 | """ |
| 767 | try: |
| 768 | if not osp.exists(idea_file_path): |
| 769 | self.logger.warning(f"Idea file not found: {idea_file_path}") |
| 770 | return {} |
| 771 | |
| 772 | # Check for duplicates - skip if already loaded |
| 773 | abs_path = osp.abspath(idea_file_path) |
| 774 | for existing in self.memory_data['ideas']: |
| 775 | if osp.abspath(existing.get('file_path', '')) == abs_path: |
| 776 | self.logger.debug(f"Ideas already loaded, skipping: {idea_file_path}") |
| 777 | return existing.get('data', {}) |
| 778 | |
| 779 | with open(idea_file_path, 'r', encoding='utf-8') as f: |
| 780 | ideas_data = json.load(f) |
| 781 | |
| 782 | self.logger.info(f"Loaded ideas from: {idea_file_path}") |
| 783 | |
| 784 | # Store in memory |
| 785 | idea_entry = { |
| 786 | 'file_path': idea_file_path, |