{"record":{"id":"e5c507f246aa8e15","repo":"microsoft/autogen","slug":"invalid-agent-id-agent-id","errorCode":null,"errorMessage":"Invalid agent id: {agent_id}","messagePattern":"Invalid agent id: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/_agent_id.py","lineNumber":48,"sourceCode":"        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\n    @classmethod\n    def from_str(cls, agent_id: str) -> Self:\n        \"\"\"Convert a string of the format ``type/key`` into an AgentId\"\"\"\n        items = agent_id.split(\"/\", maxsplit=1)\n        if len(items) != 2:\n            raise ValueError(f\"Invalid agent id: {agent_id}\")\n        type, key = items[0], items[1]\n        return cls(type, key)\n\n    @property\n    def type(self) -> str:\n        \"\"\"\n        An identifier that associates an agent with a specific factory function.\n\n        Strings may only be composed of alphanumeric letters (a-z) and (0-9), or underscores (_).\n        \"\"\"\n        return self._type\n\n    @property\n    def key(self) -> str:\n        \"\"\"\n        Agent instance identifier.\n\n        Strings may only be composed of alphanumeric letters (a-z) and (0-9), or underscores (_).","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_agent_id.py#L30-L66","documentation":"AgentId.from_str() parses strings of the exact format 'type/key' (split on the first '/'). If the input contains no '/' — or is empty — the split yields fewer than two parts and the constructor raises ValueError('Invalid agent id: ...'). The key may itself contain slashes (maxsplit=1), but the type portion may not be empty.","triggerScenarios":"Calling AgentId.from_str(\"my_agent\") (no slash), AgentId.from_str(\"\") , or passing a bare agent type where an 'type/key' string is expected (e.g. AgentId.from_str(agent.type) instead of str(agent.id)). Also hits when deserializing IDs from config/env vars that stored only the type.","commonSituations":"Reading agent IDs from environment variables, CLI args, JSON/YAML config, or message payloads where only the agent type was persisted; refactoring code that previously used plain strings as identifiers.","solutions":["Ensure the string is in 'type/key' form, e.g. AgentId.from_str(\"assistant/default\").","If you only have a type, construct the ID directly: AgentId(\"assistant\", \"default\").","When persisting IDs, store str(agent_id) (which yields 'type/key') so round-tripping through from_str works.","Sanitize/validate external input before calling from_str (see validation code)."],"exampleFix":"# before\nagent_id = AgentId.from_str(\"assistant\")  # ValueError\n\n# after\nagent_id = AgentId(\"assistant\", \"default\")\n# or\nagent_id = AgentId.from_str(\"assistant/default\")","handlingStrategy":"validation","validationCode":"def is_valid_agent_id_str(s: str) -> bool:\n    return isinstance(s, str) and len(s.split(\"/\", maxsplit=1)) == 2 and all(s.split(\"/\", maxsplit=1))\n\n# before: AgentId.from_str(raw)\nif not is_valid_agent_id_str(raw):\n    raise ValueError(f\"expected 'type/key', got {raw!r}\")\nagent_id = AgentId.from_str(raw)","typeGuard":"def is_agent_id_str(s: object) -> TypeGuard[str]:\n    if not isinstance(s, str):\n        return False\n    parts = s.split(\"/\", maxsplit=1)\n    return len(parts) == 2 and bool(parts[0]) and bool(parts[1])","tryCatchPattern":"try:\n    agent_id = AgentId.from_str(raw)\nexcept ValueError as e:\n    if \"Invalid agent id\" in str(e):\n        # handle bad input: log, default, or re-raise with context\n        raise ValueError(f\"Bad agent id from config: {raw!r}\") from e\n    raise","preventionTips":["Persist agent IDs with str(agent_id) so they always round-trip through from_str.","Validate ID strings at the config boundary (pydantic field with a 'type/key' pattern validator).","Prefer constructing AgentId(type, key) explicitly when components are known."],"tags":["agent-id","parsing","validation","autogen-core"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}