{"record":{"id":"df5704a586086a6d","repo":"FoundationAgents/MetaGPT","slug":"invalid-strategy-strategy-only-support-bfs-dfs","errorCode":null,"errorMessage":"Invalid strategy: {strategy}, only support BFS/DFS/MCTS currently!","messagePattern":"Invalid strategy: (.+?), only support BFS/DFS/MCTS currently!","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"metagpt/strategy/tot.py","lineNumber":264,"sourceCode":"\n    def _initialize_solver(self, strategy):\n        \"\"\"\n        Initialize the solver based on the chosen strategy.\n\n        Args:\n            strategy (Strategy): The strategy to use for solving.\n\n        Returns:\n            ThoughtSolverBase: An instance of the appropriate solver.\n        \"\"\"\n        if strategy == Strategy.BFS:\n            self.solver = BFSSolver(config=self.config)\n        elif strategy == Strategy.DFS:\n            self.solver = DFSSolver(config=self.config)\n        elif strategy == Strategy.MCTS:\n            self.solver = MCTSSolver(config=self.config)\n        else:\n            raise NotImplementedError(f\"Invalid strategy: {strategy}, only support BFS/DFS/MCTS currently!\")\n\n    async def solve(self, init_prompt=\"\"):\n        \"\"\"\n        Solve the problem using the specified strategy.\n\n        Args:\n            init_prompt (str): The initial prompt for the solver.\n            strategy (str): The strategy to use for solving.\n\n        Returns:\n            Any: The solution obtained using the selected strategy.\n        \"\"\"\n        await self.solver.solve(init_prompt)\n","sourceCodeStart":246,"sourceCodeEnd":278,"githubUrl":"https://github.com/FoundationAgents/MetaGPT/blob/11cdf466d042aece04fc6cfd13b28e1a70341b1f/metagpt/strategy/tot.py#L246-L278","documentation":"TreeofThought._initialize_solver maps the Strategy enum to solver classes: BFS->BFSSolver, DFS->DFSSolver, MCTS->MCTSSolver. Any other strategy value hits an explicit NotImplementedError. In practice this fires when a strategy is injected that is not one of the three enum members (note MCTSSolver.solve itself is also unimplemented upstream).","triggerScenarios":"Constructing TreeofThought(strategy=<something not Strategy.BFS/DFS/MCTS>) — e.g. a raw string that bypassed validation or a custom enum member added to Strategy without a solver.","commonSituations":"Passing strings like \"beam\" or \"best-first\" expecting support; extending the Strategy enum without registering a solver; note also that choosing MCTS currently raises NotImplementedError at solve() time since MCTSSolver.solve is a stub.","solutions":["Use Strategy.BFS or Strategy.DFS (these have working solvers)","Avoid Strategy.MCTS for now — MCTSSolver.solve raises NotImplementedError at runtime","To add a custom strategy, subclass TreeofThought and extend _initialize_solver with your solver class"],"exampleFix":"// before\ntot = TreeofThought(strategy=Strategy.MCTS)  # constructs, but solve() raises NotImplementedError\n\n// after\nfrom metagpt.strategy.tot import TreeofThought, Strategy\ntot = TreeofThought(strategy=Strategy.BFS)\nanswer = await tot.solve(prompt)","handlingStrategy":"type-guard","validationCode":"from metagpt.strategy.tot import Strategy\nassert strategy in (Strategy.BFS, Strategy.DFS), \"MCTS solver is not implemented; use BFS or DFS\"","typeGuard":"from metagpt.strategy.tot import Strategy\n\ndef is_implemented_strategy(strategy) -> bool:\n    return strategy in (Strategy.BFS, Strategy.DFS)","tryCatchPattern":"try:\n    tot = TreeofThought(config=cfg, strategy=strategy)\n    answer = await tot.solve(prompt)\nexcept NotImplementedError as e:\n    if \"only support BFS/DFS/MCTS\" in str(e) or \"solve\" in str(e):\n        tot = TreeofThought(config=cfg, strategy=Strategy.BFS)\n        answer = await tot.solve(prompt)\n    else:\n        raise","preventionTips":["Default to Strategy.BFS; only use strategies you have verified have working solvers","Guard custom strategy input against the three enum members","Wrap TreeofThought construction and solve() together — both can raise NotImplementedError"],"tags":["strategy","tree-of-thought","enum","not-implemented"],"backgroundTag":null,"analyzedSha":"11cdf466d042aece04fc6cfd13b28e1a70341b1f","analyzedAt":"2026-08-14T23:20:02.994Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}