{"record":{"id":"8b65bbb063c00ba2","repo":"microsoft/semantic-kernel","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":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/runtime/core/agent_id.py","lineNumber":59,"sourceCode":"        ...\n\n    def __str__(self) -> str:\n        \"\"\"String representation of the AgentId, e.g. 'type/key'.\"\"\"\n        ...\n\n\n@experimental\nclass CoreAgentId(AgentId):\n    \"\"\"Core implementation of the AgentId protocol.\"\"\"\n\n    def __init__(self, type: str | AgentType, key: str) -> None:\n        \"\"\"Initialize the AgentId with the given type and key.\"\"\"\n        # If `type` is itself an AgentType, extract the string property.\n        if isinstance(type, AgentType):\n            type = type.type\n\n        if not is_valid_agent_type(type):\n            raise ValueError(\n                rf\"Invalid agent type: {type}. \"\n                r\"Allowed values MUST match the regex: `^[\\w\\-\\.]+\\Z`\"\n            )\n\n        self._type = type\n        self._key = key\n\n    @classmethod\n    def from_str(cls, agent_id: str) -> Self:\n        \"\"\"Convert a string of the format ``type/key`` into a CoreAgentId.\"\"\"\n        items = agent_id.split(\"/\", maxsplit=1)\n        if len(items) != 2:\n            raise ValueError(f\"Invalid agent id: {agent_id}\")\n        t, k = items[0], items[1]\n        return cls(t, k)\n\n    @property\n    def type(self) -> str:","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/runtime/core/agent_id.py#L41-L77","documentation":"Raised by CoreAgentId.__init__ when the supplied agent type string fails the regex ^[\\w\\-\\.]+\\Z (letters, digits, underscore, hyphen, period only). Agent types are used in topic/subscription routing identifiers, so disallowed characters would break the runtime's name-based dispatch.","triggerScenarios":"Constructing a CoreAgentId (or registering an agent whose type derives from a class name) where the type contains spaces, slashes, colons, or any punctuation outside [A-Za-z0-9_\\-.]. Common when the type is auto-derived from a class with a namespace path or from user free text.","commonSituations":"Passing an agent type like 'my agent', 'foo/bar', 'type:1', or an empty string; using a fully-qualified class name (with dots and module separators that include other chars) as the type; copy-pasting a UUID with braces.","solutions":["Sanitize the type to contain only [A-Za-z0-9_.-] characters.","Use a short stable identifier (e.g. 'my-agent' or 'MyAgent') instead of a free-form label.","If deriving from a class, strip module path: type = cls.__name__.","Validate with is_valid_agent_type(value) before constructing CoreAgentId."],"exampleFix":"// before\nagent_id = CoreAgentId(type=\"my namespace/agent\", key=\"k\")\n// after\nfrom semantic_kernel.agents.runtime.core.validation_utils import is_valid_agent_type\ntype_str = \"my-namespace-agent\"\nassert is_valid_agent_type(type_str)\nagent_id = CoreAgentId(type=type_str, key=\"k\")","handlingStrategy":"validation","validationCode":"import re\n_AGENT_TYPE_REGEX = re.compile(r\"^[\\w\\-\\.]+\\Z\")\ndef is_valid_agent_type(value: str) -> bool:\n    return bool(_AGENT_TYPE_REGEX.match(value))","typeGuard":"import re\n\ndef is_valid_agent_type_str(value: object) -> bool:\n    return isinstance(value, str) and bool(re.match(r\"^[\\w\\-\\.]+\\Z\", value))","tryCatchPattern":"try:\n    agent_id = CoreAgentId(type=type_str, key=key)\nexcept ValueError as e:\n    if \"Invalid agent type\" in str(e):\n        import re\n        type_str = re.sub(r\"[^\\w\\-.]\", \"-\", type_str or \"agent\")\n        agent_id = CoreAgentId(type=type_str, key=key)\n    else:\n        raise","preventionTips":["Use only [A-Za-z0-9_.-] in agent types.","Derive types from cls.__name__, not full module paths.","Sanitize user-supplied or config-derived type strings.","Validate with is_valid_agent_type before constructing CoreAgentId."],"tags":["runtime","agent-id","validation","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}