FoundationAgents/MetaGPT · error · NotImplementedError

Invalid strategy: , only support BFS/DFS/MCTS currently!

Error message

Invalid strategy: {strategy}, only support BFS/DFS/MCTS currently!

What it means

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).

Solutions

  1. Use Strategy.BFS or Strategy.DFS (these have working solvers)
  2. Avoid Strategy.MCTS for now — MCTSSolver.solve raises NotImplementedError at runtime
  3. To add a custom strategy, subclass TreeofThought and extend _initialize_solver with your solver class

Example fix

// before
tot = TreeofThought(strategy=Strategy.MCTS)  # constructs, but solve() raises NotImplementedError

// after
from metagpt.strategy.tot import TreeofThought, Strategy
tot = TreeofThought(strategy=Strategy.BFS)
answer = await tot.solve(prompt)
Defensive patterns

Strategy: type-guard

Validate before calling

from metagpt.strategy.tot import Strategy
assert strategy in (Strategy.BFS, Strategy.DFS), "MCTS solver is not implemented; use BFS or DFS"

Type guard

from metagpt.strategy.tot import Strategy

def is_implemented_strategy(strategy) -> bool:
    return strategy in (Strategy.BFS, Strategy.DFS)

Try / catch

try:
    tot = TreeofThought(config=cfg, strategy=strategy)
    answer = await tot.solve(prompt)
except NotImplementedError as e:
    if "only support BFS/DFS/MCTS" in str(e) or "solve" in str(e):
        tot = TreeofThought(config=cfg, strategy=Strategy.BFS)
        answer = await tot.solve(prompt)
    else:
        raise

Prevention

When it happens

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

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

Related errors


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

Appendix: source

Thrown at metagpt/strategy/tot.py:264

    def _initialize_solver(self, strategy):
        """
        Initialize the solver based on the chosen strategy.

        Args:
            strategy (Strategy): The strategy to use for solving.

        Returns:
            ThoughtSolverBase: An instance of the appropriate solver.
        """
        if strategy == Strategy.BFS:
            self.solver = BFSSolver(config=self.config)
        elif strategy == Strategy.DFS:
            self.solver = DFSSolver(config=self.config)
        elif strategy == Strategy.MCTS:
            self.solver = MCTSSolver(config=self.config)
        else:
            raise NotImplementedError(f"Invalid strategy: {strategy}, only support BFS/DFS/MCTS currently!")

    async def solve(self, init_prompt=""):
        """
        Solve the problem using the specified strategy.

        Args:
            init_prompt (str): The initial prompt for the solver.
            strategy (str): The strategy to use for solving.

        Returns:
            Any: The solution obtained using the selected strategy.
        """
        await self.solver.solve(init_prompt)

View on GitHub (pinned to 11cdf466d0)