{"record":{"id":"3d1b7eab794dc040","repo":"FoundationAgents/MetaGPT","slug":"unsupported-react-mode-self-rc-react-mode","errorCode":null,"errorMessage":"Unsupported react mode: {self.rc.react_mode}","messagePattern":"Unsupported react mode: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"metagpt/roles/role.py","lineNumber":519,"sourceCode":"        Args:\n            current_task (Task): current task to take on\n\n        Raises:\n            NotImplementedError: Specific Role must implement this method if expected to use planner\n\n        Returns:\n            TaskResult: Result from the actions\n        \"\"\"\n        raise NotImplementedError\n\n    async def react(self) -> Message:\n        \"\"\"Entry to one of three strategies by which Role reacts to the observed Message\"\"\"\n        if self.rc.react_mode == RoleReactMode.REACT or self.rc.react_mode == RoleReactMode.BY_ORDER:\n            rsp = await self._react()\n        elif self.rc.react_mode == RoleReactMode.PLAN_AND_ACT:\n            rsp = await self._plan_and_act()\n        else:\n            raise ValueError(f\"Unsupported react mode: {self.rc.react_mode}\")\n        self._set_state(state=-1)  # current reaction is complete, reset state to -1 and todo back to None\n        if isinstance(rsp, AIMessage):\n            rsp.with_agent(self._setting)\n        return rsp\n\n    def get_memories(self, k=0) -> list[Message]:\n        \"\"\"A wrapper to return the most recent k memories of this role, return all when k=0\"\"\"\n        return self.rc.memory.get(k=k)\n\n    @role_raise_decorator\n    async def run(self, with_message=None) -> Message | None:\n        \"\"\"Observe, and think and act based on the results of the observation\"\"\"\n        if with_message:\n            msg = None\n            if isinstance(with_message, str):\n                msg = Message(content=with_message)\n            elif isinstance(with_message, Message):\n                msg = with_message","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/roles/role.py#L501-L537","documentation":"Role.react dispatches on rc.react_mode and supports only REACT, BY_ORDER, and PLAN_AND_ACT. Any other value (including react_mode=None or a string that failed enum coercion in some path) raises this ValueError. The mode comes from RoleReactMode configured via the role's options (react_mode key).","triggerScenarios":"Creating a Role subclass with self.rc.react_mode set to an invalid value, e.g. RoleConfig/react_mode=\"plan-execute\" or assigning an arbitrary string to rc.react_mode before calling role.run().","commonSituations":"Typo in react_mode in role kwargs (e.g. \"by-order\" vs \"by_order\"); copying a custom role that sets react_mode from unvalidated user input; version changes renaming enum members.","solutions":["Use a valid RoleReactMode member: from metagpt.roles.role import RoleReactMode; role = MyRole(react_mode=RoleReactMode.BY_ORDER)","Check valid values via list(RoleReactMode) before assigning","If a string must cross a boundary, validate it against {e.value for e in RoleReactMode} first"],"exampleFix":"// before\nrole = MyRole(react_mode=\"byorder\")  # ValueError in react()\n\n// after\nfrom metagpt.roles.role import RoleReactMode\nrole = MyRole(react_mode=RoleReactMode.BY_ORDER)","handlingStrategy":"type-guard","validationCode":"from metagpt.roles.role import RoleReactMode\nassert role.rc.react_mode in (RoleReactMode.REACT, RoleReactMode.BY_ORDER, RoleReactMode.PLAN_AND_ACT)","typeGuard":"from enum import Enum\nfrom metagpt.roles.role import RoleReactMode\n\ndef is_valid_react_mode(mode) -> bool:\n    return isinstance(mode, Enum) and mode in set(RoleReactMode)","tryCatchPattern":"try:\n    rsp = await role.run()\nexcept ValueError as e:\n    if \"Unsupported react mode\" in str(e):\n        role.rc.react_mode = RoleReactMode.REACT  # reset to safe default\n        rsp = await role.run()\n    else:\n        raise","preventionTips":["Set react_mode from RoleReactMode members only, not raw strings","Validate external input against {m.value for m in RoleReactMode} before constructing roles","Add a unit test asserting custom roles' react_mode is valid"],"tags":["role","react-mode","enum","configuration"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}