FoundationAgents/MetaGPT · error · ValueError
req_version should be (3, 9) or (3, 10, 13)
Error message
req_version should be (3, 9) or (3, 10, 13)
What it means
require_python_version(req_version) in metagpt/utils/common.py validates that the req_version tuple has between 2 and 3 components (e.g. (3, 9) or (3, 10, 13)). Passing a 1-tuple like (3,) or a 4-component tuple raises this ValueError before the version comparison runs.
Source
Thrown at metagpt/utils/common.py:69
from metagpt.utils.json_to_markdown import json_to_markdown
def check_cmd_exists(command) -> int:
"""检查命令是否存在
:param command: 待检查的命令
:return: 如果命令存在,返回0,如果不存在,返回非0
"""
if platform.system().lower() == "windows":
check_command = "where " + command
else:
check_command = "command -v " + command + ' >/dev/null 2>&1 || { echo >&2 "no mermaid"; exit 1; }'
result = os.system(check_command)
return result
def require_python_version(req_version: Tuple) -> bool:
if not (2 <= len(req_version) <= 3):
raise ValueError("req_version should be (3, 9) or (3, 10, 13)")
return bool(sys.version_info > req_version)
class OutputParser:
@classmethod
def parse_blocks(cls, text: str):
# 首先根据"##"将文本分割成不同的block
blocks = text.split(MARKDOWN_TITLE_PREFIX)
# 创建一个字典,用于存储每个block的标题和内容
block_dict = {}
# 遍历所有的block
for block in blocks:
# 如果block不为空,则继续处理
if block.strip() != "":
# 将block的标题和内容分开,并分别去掉前后的空白字符
block_title, block_content = block.split("\n", 1)View on GitHub (pinned to 11cdf466d0)
Solutions
- Pass a 2- or 3-element tuple: require_python_version((3, 10)).
- If building from a string, slice it: tuple(map(int, v.split('.')))[:3].
- Check the call site and fix the tuple literal that has 1 or 4+ components.
Example fix
# before require_python_version((3,)) # raises # after require_python_version((3, 9))
Defensive patterns
Strategy: validation
Validate before calling
def valid_version_tuple(v) -> bool:
return isinstance(v, tuple) and 2 <= len(v) <= 3 and all(isinstance(x, int) for x in v) Type guard
from typing import Tuple
def is_req_version(v) -> bool: # type guard for the API contract
return isinstance(v, tuple) and 2 <= len(v) <= 3 Prevention
- Only pass (major, minor) or (major, minor, patch) tuples.
- When parsing a version string, slice to at most 3 parts.
When it happens
Trigger: require_python_version((3,)); require_python_version((3, 10, 13, 2)); require_python_version(()) (empty tuple is also outside 2..3).
Common situations: Callers constructing the version tuple dynamically (e.g. from a string split on '.') without bounding its length; copy-paste of a full 4-part sys.version_info-like tuple; passing sys.version_info itself is fine (it compares > tuple) but passing a sliced/wrongly-built tuple is not.
Related errors
- Cannot insert and append at the same time.
- Either filename or mime_type must be valid.
- Invalid request type. Valid types: {', '.join([t.value for t
- Line number must be between 1 and {total_lines}
- Invalid start line number: {start}. Line numbers must be bet
AI-assisted analysis of FoundationAgents/MetaGPT@11cdf466d0 (2026-08-14).
Data as JSON: /api/errors/5874fd4195e64e74.
Report an issue: GitHub.