{"record":{"id":"5dfccb058b64c7fa","repo":"FoundationAgents/MetaGPT","slug":"task-id-is-not-found-in-the-insight-pool","errorCode":null,"errorMessage":"task_id is not found in the insight_pool","messagePattern":"task_id is not found in the insight_pool","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/ext/sela/insights/instruction_generator.py","lineNumber":109,"sourceCode":"        rsp_list.append(rsp)\n        for item in rsp_list:\n            item_dict = json.loads(item)\n            data = {\n                \"Insights\": item_dict,\n            }\n            new_data.append(data)\n        return new_data\n\n    @staticmethod\n    def load_insight_pool(file_path, use_fixed_insights, task_id=None):\n        data = InstructionGenerator.load_json_data(file_path)\n        if use_fixed_insights:\n            current_directory = os.path.dirname(__file__)\n            fixed_insights = InstructionGenerator.load_json_data(f\"{current_directory}/fixed_insights.json\")\n            data.extend(fixed_insights)\n        for item in data:\n            if \"task_id\" not in item:\n                raise ValueError(\"task_id is not found in the insight_pool\")\n\n        if task_id:\n            data = [item for item in data if int(item[\"task_id\"]) == int(task_id)]\n        return data\n\n    async def generate_new_instructions(self, task_id, original_instruction, max_num, ext_info=None):\n        data = self.insight_pool\n        new_instructions = []\n        if len(data) == 0:\n            mcts_logger.log(\"MCTS\", f\"No insights available for task {task_id}\")\n            # return [original_instruction]  # Return the original instruction if no insights are available\n        for i in range(max_num):\n            if len(data) == 0:\n                insights = \"No insights available\"\n            else:\n                item = data[i]\n                insights = item[\"Analysis\"]\n            new_instruction = await InstructionGenerator.generate_new_instruction(","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/ext/sela/insights/instruction_generator.py#L91-L127","documentation":"Raised by InstructionGenerator.load_insight_pool when any entry in the loaded insight pool JSON lacks a 'task_id' key. Every insight must carry a task_id because the pool is filtered by task (int(item['task_id']) == int(task_id)) and later grouped per task.","triggerScenarios":"Loading an analysis_pool/insight_pool JSON where at least one item was added without a task_id field — typically hand-written or externally generated insights.","commonSituations":"Editing the pool JSON to add domain knowledge and omitting task_id; merging insights from another pool format; use_fixed_insights pulling a malformed fixed_insights.json.","solutions":["Add an integer 'task_id' field to every entry in the insight pool JSON","Validate the JSON offline: assert all('task_id' in item for item in data)","Keep the schema of your added insights identical to existing entries"],"exampleFix":"# before\n{\"Analysis\": \"...\"}\n\n# after\n{\"task_id\": 0, \"Analysis\": \"...\"}","handlingStrategy":"validation","validationCode":"data = json.load(open(pool_path))\nmissing = [i for i, item in enumerate(data) if \"task_id\" not in item]\nassert not missing, f\"entries missing task_id: {missing}\"","typeGuard":"def insight_pool_valid(data: list[dict]) -> bool:\n    return all(isinstance(item, dict) and \"task_id\" in item for item in data)","tryCatchPattern":null,"preventionTips":["Validate pool JSON against existing entries' schema before adding insights","Always include integer task_id in hand-written insights"],"tags":["sela","insights","json-schema","validation"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}