{"record":{"id":"7f41298d0fc5ce24","repo":"FoundationAgents/MetaGPT","slug":"lesson-content-invalid","errorCode":null,"errorMessage":"Lesson content invalid.","messagePattern":"Lesson content invalid\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/roles/teacher.py","lineNumber":44,"sourceCode":"    name: str = \"Lily\"\n    profile: str = \"{teaching_language} Teacher\"\n    goal: str = \"writing a {language} teaching plan part by part\"\n    constraints: str = \"writing in {language}\"\n    desc: str = \"\"\n\n    def __init__(self, **kwargs):\n        super().__init__(**kwargs)\n        self.name = WriteTeachingPlanPart.format_value(self.name, self.context)\n        self.profile = WriteTeachingPlanPart.format_value(self.profile, self.context)\n        self.goal = WriteTeachingPlanPart.format_value(self.goal, self.context)\n        self.constraints = WriteTeachingPlanPart.format_value(self.constraints, self.context)\n        self.desc = WriteTeachingPlanPart.format_value(self.desc, self.context)\n\n    async def _think(self) -> bool:\n        \"\"\"Everything will be done part by part.\"\"\"\n        if not self.actions:\n            if not self.rc.news or self.rc.news[0].cause_by != any_to_str(UserRequirement):\n                raise ValueError(\"Lesson content invalid.\")\n            actions = []\n            print(TeachingPlanBlock.TOPICS)\n            for topic in TeachingPlanBlock.TOPICS:\n                act = WriteTeachingPlanPart(i_context=self.rc.news[0].content, topic=topic, llm=self.llm)\n                actions.append(act)\n            self.set_actions(actions)\n\n        if self.rc.todo is None:\n            self._set_state(0)\n            return True\n\n        if self.rc.state + 1 < len(self.states):\n            self._set_state(self.rc.state + 1)\n            return True\n\n        self.set_todo(None)\n        return False\n","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/roles/teacher.py#L26-L62","documentation":"Teacher role initializes its action list from the first incoming message; WriteTeachingPlanPart actions are created only when rc.news exists and the news message's cause_by is UserRequirement. Otherwise (no news, or news produced by another action) it raises this ValueError because there is no lesson content to build a teaching plan from.","triggerScenarios":"Running a Teacher role whose first observed message was sent by another role/action rather than the user (cause_by != UserRequirement), or running with an empty environment so rc.news is falsy.","commonSituations":"Putting Teacher in a multi-role team where a peer role's output reaches it first; calling role.run() without publishing a user requirement first; replaying histories where the initial message is mislabeled.","solutions":["Publish the lesson content as a user requirement before the Teacher's turn: env.publish_message(Message(content=lesson, cause_by=UserRequirement))","In teams, ensure Teacher is scheduled to receive the human input first (check subscriptions/ watch rules)","Wrap role startup in try/except ValueError and re-send the requirement if misrouted"],"exampleFix":"// before\n// Teacher runs first in a team and receives a peer action's message -> ValueError\n\n// after\nfrom metagpt.schema import Message\nfrom metagpt.actions.add_requirement import UserRequirement\nenv.publish_message(Message(content=\"Explain the water cycle\", cause_by=UserRequirement))","handlingStrategy":"validation","validationCode":"from metagpt.actions.add_requirement import UserRequirement\nfrom metagpt.utils.common import any_to_str\nnews = teacher.rc.news\nassert news and any_to_str(news[0].cause_by) == any_to_str(UserRequirement), \"publish a user requirement first\"","typeGuard":null,"tryCatchPattern":"try:\n    await teacher.run()\nexcept ValueError as e:\n    if \"Lesson content invalid\" in str(e):\n        env.publish_message(Message(content=lesson, cause_by=UserRequirement))\n        await teacher.run()\n    else:\n        raise","preventionTips":["Publish the lesson topic as a UserRequirement message before the Teacher's first run","In multi-role teams, verify the Teacher's watch/subscription targets only user input","Unit-test role bootstrap with a properly labeled seed message"],"tags":["role","teacher","message-routing","workflow"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}