FoundationAgents/MetaGPT · error · ValueError

Lesson content invalid.

Error message

Lesson content invalid.

What it means

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.

Source

Thrown at metagpt/roles/teacher.py:44

    name: str = "Lily"
    profile: str = "{teaching_language} Teacher"
    goal: str = "writing a {language} teaching plan part by part"
    constraints: str = "writing in {language}"
    desc: str = ""

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.name = WriteTeachingPlanPart.format_value(self.name, self.context)
        self.profile = WriteTeachingPlanPart.format_value(self.profile, self.context)
        self.goal = WriteTeachingPlanPart.format_value(self.goal, self.context)
        self.constraints = WriteTeachingPlanPart.format_value(self.constraints, self.context)
        self.desc = WriteTeachingPlanPart.format_value(self.desc, self.context)

    async def _think(self) -> bool:
        """Everything will be done part by part."""
        if not self.actions:
            if not self.rc.news or self.rc.news[0].cause_by != any_to_str(UserRequirement):
                raise ValueError("Lesson content invalid.")
            actions = []
            print(TeachingPlanBlock.TOPICS)
            for topic in TeachingPlanBlock.TOPICS:
                act = WriteTeachingPlanPart(i_context=self.rc.news[0].content, topic=topic, llm=self.llm)
                actions.append(act)
            self.set_actions(actions)

        if self.rc.todo is None:
            self._set_state(0)
            return True

        if self.rc.state + 1 < len(self.states):
            self._set_state(self.rc.state + 1)
            return True

        self.set_todo(None)
        return False

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Publish the lesson content as a user requirement before the Teacher's turn: env.publish_message(Message(content=lesson, cause_by=UserRequirement))
  2. In teams, ensure Teacher is scheduled to receive the human input first (check subscriptions/ watch rules)
  3. Wrap role startup in try/except ValueError and re-send the requirement if misrouted

Example fix

// before
// Teacher runs first in a team and receives a peer action's message -> ValueError

// after
from metagpt.schema import Message
from metagpt.actions.add_requirement import UserRequirement
env.publish_message(Message(content="Explain the water cycle", cause_by=UserRequirement))
Defensive patterns

Strategy: validation

Validate before calling

from metagpt.actions.add_requirement import UserRequirement
from metagpt.utils.common import any_to_str
news = teacher.rc.news
assert news and any_to_str(news[0].cause_by) == any_to_str(UserRequirement), "publish a user requirement first"

Try / catch

try:
    await teacher.run()
except ValueError as e:
    if "Lesson content invalid" in str(e):
        env.publish_message(Message(content=lesson, cause_by=UserRequirement))
        await teacher.run()
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14). Data as JSON: /api/errors/7f41298d0fc5ce24. Report an issue: GitHub.