FoundationAgents/MetaGPT · error · ValueError

Error loading configuration for model '{model}': {str(e)}

Error message

Error loading configuration for model '{model}': {str(e)}

What it means

A catch-all wrapper thrown by SPO_LLM._load_llm_config: any exception other than AttributeError raised while looking up or copying the model configuration is re-raised as ValueError with the original message appended. The inner exception string is the real diagnostic; common inner causes are malformed models yaml, missing required config fields, or model_copy failing on an incomplete config object.

Source

Thrown at metagpt/ext/spo/utils/llm_client.py:51

            raise ValueError("'model' parameter is required")

        try:
            model_config = ModelsConfig.default().get(model)
            if model_config is None:
                raise ValueError(f"Model '{model}' not found in configuration")

            config = model_config.model_copy()

            for key, value in kwargs.items():
                if hasattr(config, key):
                    setattr(config, key, value)

            return config

        except AttributeError:
            raise ValueError(f"Model '{model}' not found in configuration")
        except Exception as e:
            raise ValueError(f"Error loading configuration for model '{model}': {str(e)}")

    async def responser(self, request_type: RequestType, messages: List[dict]) -> str:
        llm_mapping = {
            RequestType.OPTIMIZE: self.optimize_llm,
            RequestType.EVALUATE: self.evaluate_llm,
            RequestType.EXECUTE: self.execute_llm,
        }

        llm = llm_mapping.get(request_type)
        if not llm:
            raise ValueError(f"Invalid request type. Valid types: {', '.join([t.value for t in RequestType])}")

        response = await llm.acompletion(messages)
        return response.choices[0].message.content

    @classmethod
    def initialize(cls, optimize_kwargs: dict, evaluate_kwargs: dict, execute_kwargs: dict) -> None:
        """Initialize the global instance"""

View on GitHub (pinned to 11cdf466d0)

Solutions

  1. Read the embedded '{str(e)}' portion — it carries the underlying exception; fix that root cause first.
  2. Validate the models yaml loads cleanly: yaml.safe_load it in a REPL before running SPO.
  3. Check that every model entry contains all required fields for the current MetaGPT version's config schema.
  4. Ensure kwargs passed to initialize contain only valid, correctly-typed fields for the model config.

Example fix

// before
# models.yaml entry missing api_key causes inner validation error
my-model:
  api_type: openai

// after
my-model:
  api_type: openai
  base_url: https://api.openai.com/v1
  api_key: YOUR_KEY
  timeout: 600
Defensive patterns

Strategy: try-catch

Validate before calling

import yaml
from pathlib import Path

def yaml_ok(p: Path) -> bool:
    try:
        yaml.safe_load(p.read_text(encoding="utf-8"))
        return True
    except yaml.YAMLError:
        return False

Try / catch

try:
    SPO_LLM.initialize(opt, eva, exe)
except ValueError as e:
    if str(e).startswith("Error loading configuration"):
        logger.error("SPO model config failed: %s", e)  # inner cause is embedded
        raise
    raise

Prevention

When it happens

Trigger: ModelsConfig.default().get(model) raises a non-AttributeError error (e.g. yaml parse error inside the config loader, pydantic validation error in model_copy, missing required api field); or setattr on the copied config triggers pydantic validation failure for one of the kwargs values.

Common situations: Malformed models.yaml (tabs, bad indentation, duplicate keys); a model entry missing mandatory fields so pydantic rejects it during copy; passing kwargs with wrong types (e.g. temperature as string); version upgrade changing the ModelsConfig schema so old yaml entries fail validation.

Related errors


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