{"record":{"id":"224330ccda2d40f8","repo":"microsoft/autogen","slug":"agent-with-name-agent-id-type-not-found","errorCode":null,"errorMessage":"Agent with name {agent_id.type} not found.","messagePattern":"Agent with name (.+?) not found\\.","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py","lineNumber":981,"sourceCode":"                    agent = cast(T, await agent)\n                return agent\n\n            except BaseException as e:\n                event_logger.info(\n                    AgentConstructionExceptionEvent(\n                        agent_id=agent_id,\n                        exception=e,\n                    )\n                )\n                logger.error(f\"Error constructing agent {agent_id}\", exc_info=True)\n                raise\n\n    async def _get_agent(self, agent_id: AgentId) -> Agent:\n        if agent_id in self._instantiated_agents:\n            return self._instantiated_agents[agent_id]\n\n        if agent_id.type not in self._agent_factories:\n            raise LookupError(f\"Agent with name {agent_id.type} not found.\")\n\n        agent_factory = self._agent_factories[agent_id.type]\n        agent = await self._invoke_agent_factory(agent_factory, agent_id)\n        self._instantiated_agents[agent_id] = agent\n        return agent\n\n    # TODO: uncomment out the following type ignore when this is fixed in mypy: https://github.com/python/mypy/issues/3737\n    async def try_get_underlying_agent_instance(self, id: AgentId, type: Type[T] = Agent) -> T:  # type: ignore[assignment]\n        if id.type not in self._agent_factories:\n            raise LookupError(f\"Agent with name {id.type} not found.\")\n\n        # TODO: check if remote\n        agent_instance = await self._get_agent(id)\n\n        if not isinstance(agent_instance, type):\n            raise TypeError(\n                f\"Agent with name {id.type} is not of type {type.__name__}. It is of type {type_func_alias(agent_instance).__name__}\"\n            )","sourceCodeStart":963,"sourceCodeEnd":999,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-core/src/autogen_core/_single_threaded_agent_runtime.py#L963-L999","documentation":"_get_agent raises LookupError when an AgentId's type has neither an instantiated agent nor a registered factory. It is the internal resolution path behind send_message, publish delivery, and save/load state, so any reference to an unknown type surfaces here (the send path raises the sibling error 'Agent type does not exist' earlier; this one fires for non-send resolution such as lazy instantiation during topic delivery or direct _get_agent use).","triggerScenarios":"Resolving AgentId('unknown_type', key) via runtime.try_get_underlying_agent_instance, agent_save_state/agent_load_state, or indirectly when a subscription maps a topic to an agent type that was never registered; referencing a type after renaming its registration string.","commonSituations":"Subscriptions pointing at stale/misspelled agent types; orchestration code iterating expected agent names that were registered on a different runtime; tests that query agent state without registering the agent first.","solutions":["Register a factory (or instance) for every type any subscription or send targets before publishing/sending","Validate ids up front: keep a canonical list/dict of AgentType constants and check runtime._agent_factories membership (or catch LookupError) before resolution","Fix typos/renames by centralizing type strings (constants or RuntimeAgentType classes) shared by producers and consumers"],"exampleFix":"# before\nawait runtime.agent_save_state(AgentId(\"woker\", \"1\"))  # typo -> LookupError\n\n# after\nWORKER = AgentType(\"worker\")\nawait runtime.register_factory(WORKER, Worker.create)\nawait runtime.agent_save_state(AgentId(WORKER.type, \"1\"))","handlingStrategy":"validation","validationCode":"def agent_type_registered(runtime, t: str) -> bool:\n    return t in runtime._agent_factories","typeGuard":"def is_known_type(runtime, agent_id) -> bool:\n    return agent_id.type in runtime._agent_factories or agent_id in runtime._instantiated_agents","tryCatchPattern":"try:\n    await runtime.try_get_underlying_agent_instance(agent_id, Agent)\nexcept LookupError as e:\n    if \"not found\" in str(e):\n        log_and_register_or_skip(agent_id)\n    else:\n        raise","preventionTips":["Maintain a registry map of topic -> agent type and validate it at startup","Share AgentType constants across publisher and subscriber code","Await registrations before publishing/sending in orchestration code"],"tags":["autogen-core","runtime","agent-registration","lookuperror"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}