Load task and create MAS session
(self)
| 176 | ) |
| 177 | |
| 178 | async def load_task(self): |
| 179 | """Load task and create MAS session""" |
| 180 | self.logger.info(f"Creating research session for: {self.args.task_dir}") |
| 181 | |
| 182 | await self.interface.startup() |
| 183 | |
| 184 | # Use args.prompt_path if available (points to launch directory copy), otherwise fall back to task_dir |
| 185 | task_desc_path = getattr(self.args, 'prompt_path', None) or osp.join(self.args.task_dir, "prompt.json") |
| 186 | if not osp.exists(task_desc_path): |
| 187 | raise FileNotFoundError(f"Task description not found: {task_desc_path}") |
| 188 | self.logger.info(f"Using prompt file: {task_desc_path}") |
| 189 | |
| 190 | # Check if experience library exists and evolve prompt if it does |
| 191 | # Use base_output_dir if available (set by launch_discovery.py), otherwise use default |
| 192 | base_output_dir = getattr(self.args, 'base_output_dir', None) or osp.join("results", self.args.task_name) |
| 193 | library_path = osp.join(base_output_dir, "experience_library.json") |
| 194 | |
| 195 | # Get evolution_interval from config (default: 1, meaning evolve every round) |
| 196 | evolution_interval = self.config.get('memory', {}).get('long_memory', {}).get('prompt_evolver', {}).get('evolution_interval', 1) |
| 197 | |
| 198 | # Only evolve prompt when: |
| 199 | # 1. round_num > 1 (first round has no experience yet) |
| 200 | # 2. round_num % evolution_interval == 0 (respects the configured interval) |
| 201 | # Note: With interval=1, evolves at rounds 2, 3, 4, ... |
| 202 | # With interval=2, evolves at rounds 2, 4, 6, ... |
| 203 | should_evolve = (self.round_num > 1) and ((self.round_num - 1) % evolution_interval == 0) |
| 204 | |
| 205 | if should_evolve: |
| 206 | self.logger.info(f"Round {self.round_num}: Prompt evolution scheduled (interval={evolution_interval})") |
| 207 | else: |
| 208 | self.logger.info(f"Round {self.round_num}: Skipping prompt evolution (interval={evolution_interval})") |
| 209 | |
| 210 | if should_evolve and osp.exists(library_path) and LONG_MEMORY_AVAILABLE and PromptEvolver is not None: |
| 211 | self.logger.info("Experience library found, evolving prompt...") |
| 212 | try: |
| 213 | # Create a backup of the prompt before evolution (in the same directory as prompt file) |
| 214 | prompt_dir = osp.dirname(task_desc_path) |
| 215 | backup_path = osp.join(prompt_dir, f"prompt_backup_round{self.round_num}.json") |
| 216 | import shutil |
| 217 | shutil.copy(task_desc_path, backup_path) |
| 218 | self.logger.info(f"Backed up prompt to: {backup_path}") |
| 219 | |
| 220 | # Load config for PromptEvolver |
| 221 | config = {} |
| 222 | if self.args.config and osp.exists(self.args.config): |
| 223 | try: |
| 224 | with open(self.args.config, 'r') as f: |
| 225 | if self.args.config.endswith(('.yaml', '.yml')): |
| 226 | config = yaml.safe_load(f) |
| 227 | else: |
| 228 | config = json.load(f) |
| 229 | except Exception as e: |
| 230 | self.logger.warning(f"Failed to load config: {e}") |
| 231 | |
| 232 | # Initialize PromptEvolver with IdeaGraph |
| 233 | prompt_evolver = PromptEvolver(self.args, self.logger, config, idea_graph=self.idea_graph) |
| 234 | |
| 235 | # Get domain from current prompt |
no test coverage detected