{"record":{"id":"d3b724b3ca6cfeac","repo":"microsoft/autogen","slug":"invalid-agent-type-type-allowed-values-must-ma","errorCode":null,"errorMessage":"Invalid agent type: {type}. Allowed values MUST match the regex: `^[\\w\\-\\.]+\\Z`","messagePattern":"Invalid agent type: (.+?)\\. Allowed values MUST match the regex: `\\^\\[\\\\w\\\\-\\\\\\.\\]\\+\\\\Z`","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/_agent_id.py","lineNumber":24,"sourceCode":"\n\ndef is_valid_agent_type(value: str) -> bool:\n    return bool(re.match(r\"^[\\w\\-\\.]+\\Z\", value))\n\n\nclass AgentId:\n    \"\"\"\n    Agent ID uniquely identifies an agent instance within an agent runtime - including distributed runtime. It is the 'address' of the agent instance for receiving messages.\n\n    See here for more information: :ref:`agentid_and_lifecycle`\n    \"\"\"\n\n    def __init__(self, type: str | AgentType, key: str) -> None:\n        if isinstance(type, AgentType):\n            type = type.type\n\n        if not is_valid_agent_type(type):\n            raise ValueError(rf\"Invalid agent type: {type}. Allowed values MUST match the regex: `^[\\w\\-\\.]+\\Z`\")\n\n        self._type = type\n        self._key = key\n\n    def __hash__(self) -> int:\n        return hash((self._type, self._key))\n\n    def __str__(self) -> str:\n        return f\"{self._type}/{self._key}\"\n\n    def __repr__(self) -> str:\n        return f'AgentId(type=\"{self._type}\", key=\"{self._key}\")'\n\n    def __eq__(self, value: object) -> bool:\n        if not isinstance(value, AgentId):\n            return False\n        return self._type == value.type and self._key == value.key\n","sourceCodeStart":6,"sourceCodeEnd":42,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_agent_id.py#L6-L42","documentation":"autogen_core.AgentId.__init__ raises ValueError when the type string fails the regex ^[\\w\\-\\.]+$ (word characters, hyphens, dots only). Agent types become topic/routing identifiers in the runtime, so characters like '/', ':', spaces, or '#' are rejected to keep addresses unambiguous (type/key are joined with '/').","triggerScenarios":"Constructing AgentId(type=\"my agent\", key=\"1\") or AgentId(\"ns:worker\", ...); passing a class-qualified name, a path, or any string containing whitespace, slashes, or punctuation as the agent type; AgentType(...) with the same invalid string.","commonSituations":"Deriving agent type names from file paths, URLs, or free-form user input; using 'module.Class' is fine (dots allowed) but 'module::Class' or 'a/b' fails; migrating code that used arbitrary strings in older versions.","solutions":["Sanitize the type to allowed characters: re.sub(r'[^\\w\\-\\.]', '_', type_str).","Use simple identifiers, module-qualified names ('my_pkg.MyAgent'), or dotted namespaces instead of paths with slashes.","Validate early with autogen_core._agent_id.is_valid_agent_type (or the same regex) before constructing AgentId."],"exampleFix":"# before\nagent_id = AgentId(type=\"workers/http-agent\", key=\"1\")  # ValueError: '/' not allowed\n\n# after\nimport re\nagent_type = re.sub(r\"[^\\w\\-\\.]\", \"_\", \"workers/http-agent\")  # 'workers_http-agent'\nagent_id = AgentId(type=agent_type, key=\"1\")","handlingStrategy":"validation","validationCode":"import re\n\ndef safe_agent_type(raw: str) -> str:\n    return re.sub(r\"[^\\w\\-\\.]\", \"_\", raw)\n\nagent_id = AgentId(type=safe_agent_type(raw_name), key=\"1\")","typeGuard":"import re\n\ndef is_valid_agent_type(type_str: str) -> bool:\n    return re.fullmatch(r\"[\\w\\-\\.]+\", type_str) is not None","tryCatchPattern":"from autogen_core import AgentId\ntry:\n    agent_id = AgentId(type=raw_type, key=key)\nexcept ValueError:\n    agent_id = AgentId(type=re.sub(r\"[^\\w\\-\\.]\", \"_\", raw_type), key=key)","preventionTips":["Restrict agent type names to letters, digits, underscore, hyphen, and dot.","Sanitize user-supplied or path-derived names before building AgentId.","Remember '/' is reserved as the type/key separator in AgentId.__str__."],"tags":["autogen-core","agent-id","validation","regex","naming"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}