FoundationAgents/MetaGPT · error · ModelRequired
Model is required!
Error message
Model is required!
What it means
Companion guard in DashScope Generation.acall: after the prompt/messages check, a falsy model (None or '') raises ModelRequired('Model is required!'). The model positional must be a non-empty string naming a DashScope model.
Source
Thrown at metagpt/provider/dashscope_api.py:122
return request
class AGeneration(Generation, BaseAioApi):
@classmethod
async def acall(
cls,
model: str,
prompt: Any = None,
history: list = None,
api_key: str = None,
messages: List[Message] = None,
plugins: Union[str, Dict[str, Any]] = None,
**kwargs,
) -> Union[GenerationResponse, AsyncGenerator[GenerationResponse, None]]:
if (prompt is None or not prompt) and (messages is None or not messages):
raise InputRequired("prompt or messages is required!")
if model is None or not model:
raise ModelRequired("Model is required!")
task_group, function = "aigc", "generation" # fixed value
if plugins is not None:
headers = kwargs.pop("headers", {})
if isinstance(plugins, str):
headers["X-DashScope-Plugin"] = plugins
else:
headers["X-DashScope-Plugin"] = json.dumps(plugins)
kwargs["headers"] = headers
input, parameters = cls._build_input_parameters(model, prompt, history, messages, **kwargs)
api_key, model = BaseAioApi._validate_params(api_key, model)
request = build_api_arequest(
model=model,
input=input,
task_group=task_group,
task=Generation.task,
function=function,
api_key=api_key,View on GitHub (pinned to 11cdf466d0)
Solutions
- Pass an explicit model id, e.g. 'qwen-max', 'qwen-plus', 'qwen-turbo'.
- Validate/fail fast at startup that the configured model name is non-empty.
- Check the provider config (models.yaml dashscope entry) has its model field set.
Example fix
// before
resp = await Generation.acall(model=os.getenv("DS_MODEL"), prompt="hi") # None if unset
// after
model = os.environ["DS_MODEL"] # fail fast if missing
resp = await Generation.acall(model=model, prompt="hi") Defensive patterns
Strategy: validation
Validate before calling
def model_ok(model) -> bool:
return isinstance(model, str) and bool(model.strip())
assert model_ok(cfg_model), f"model must be a non-empty string, got {cfg_model!r}" Type guard
def is_nonempty_model_str(m: object) -> bool:
return isinstance(m, str) and len(m.strip()) > 0 Try / catch
try:
resp = await Generation.acall(model=model, prompt=prompt)
except Exception as e:
if "Model is required" in str(e):
raise ValueError(f"model unset; check env/config (got {model!r})") from e
raise Prevention
- Fail fast at startup when a required model env var is missing.
- Use os.environ[...] (KeyError) instead of os.getenv(...) for mandatory values.
When it happens
Trigger: Calling Generation.acall(model=None) or model=''; commonly when model is read from config/env and the key is missing, defaulting to None.
Common situations: Config-driven model names with a typo'd env var; version upgrades renaming model fields; failing to set the model in the dashscope LLM provider config.
Related errors
- Unsupported protocol: %s, support [http, https, websocket]
- There is no input data and form data
- prompt or messages is required!
- Only support for python, markdown, but got {language}
- Only support for language: python, markdown, but got {langua
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/a41ee3faf6b11b95.
Report an issue: GitHub.