FoundationAgents/MetaGPT · error · ValueError

Invalid mode: {self.args.rs_mode}

Error message

Invalid mode: {self.args.rs_mode}

What it means

Raised by RandomSearchRunner when args.rs_mode is neither 'single' (sample one experiment per run from the pool) nor 'set' (sample and join an instruction set per run). The string dispatch has a final else that raises.

Source

Thrown at metagpt/ext/sela/runner/random_search.py:33

    async def run_experiment(self):
        # state = create_initial_state(self.args.task, start_task_id=1, data_config=self.data_config, low_is_better=self.args.low_is_better, name="")
        user_requirement = self.state["requirement"]
        exp_pool_path = get_exp_pool_path(self.args.task, self.data_config, pool_name="ds_analysis_pool")
        exp_pool = InstructionGenerator.load_insight_pool(
            exp_pool_path, use_fixed_insights=self.args.use_fixed_insights
        )
        if self.args.rs_mode == "single":
            exps = InstructionGenerator._random_sample(exp_pool, self.args.num_experiments)
            exps = [exp["Analysis"] for exp in exps]
        elif self.args.rs_mode == "set":
            exps = []
            for i in range(self.args.num_experiments):
                exp_set = InstructionGenerator.sample_instruction_set(exp_pool)
                exp_set_text = "\n".join([f"{exp['task_id']}: {exp['Analysis']}" for exp in exp_set])
                exps.append(exp_set_text)
        else:
            raise ValueError(f"Invalid mode: {self.args.rs_mode}")

        results = []
        for i in range(self.args.num_experiments):
            di = Experimenter(node_id=str(i), use_reflection=self.args.reflection, role_timeout=self.args.role_timeout)
            di.role_dir = f"{di.role_dir}_{self.args.task}"
            requirement = user_requirement + EXPS_PROMPT.format(experience=exps[i])
            print(requirement)
            score_dict = await self.run_di(di, requirement, run_idx=i)
            results.append(
                {
                    "idx": i,
                    "score_dict": score_dict,
                    "rs_mode": self.args.rs_mode,
                    "insights": exps[i],
                    "user_requirement": requirement,
                    "args": vars(self.args),
                }
            )

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Pass --rs_mode single or --rs_mode set explicitly
  2. Check for case-sensitive typos in the argument
  3. Check the argument default in get_args() for your version and set it accordingly

Example fix

# before
--exp_mode rs --rs_mode sets

# after
--exp_mode rs --rs_mode set
Defensive patterns

Strategy: validation

Validate before calling

assert args.rs_mode in {"single", "set"}, f"bad rs_mode {args.rs_mode}"

Type guard

def is_valid_rs_mode(mode: str) -> bool:
    return mode in {"single", "set"}

Prevention

When it happens

Trigger: Running run_experiment.py with --exp_mode rs and --rs_mode set to anything other than 'single' or 'set' (typos, or omitting rs_mode so it is None).

Common situations: Missing --rs_mode argument when the arg parser default is None; typo like 'Set' or 'sets'; flags from an incompatible SELA version.

Related errors


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