{"record":{"id":"133fc82c1baafc23","repo":"microsoft/semantic-kernel","slug":"agent-with-name-id-type-not-found","errorCode":null,"errorMessage":"Agent with name {id.type} not found.","messagePattern":"Agent with name (.+?) not found\\.","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/runtime/in_process/in_process_runtime.py","lineNumber":811,"sourceCode":"                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(evmattso): 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        \"\"\"Try to get the underlying agent instance by name and namespace.\"\"\"\n        if id.type not in self._agent_factories:\n            raise LookupError(f\"Agent with name {id.type} not found.\")\n\n        # TODO(evmattso): 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__}. \"\n                f\"It is of type {type_func_alias(agent_instance).__name__}\"\n            )\n\n        return agent_instance\n\n    async def add_subscription(self, subscription: Subscription) -> None:\n        \"\"\"Add a subscription to the runtime.\"\"\"\n        await self._subscription_manager.add_subscription(subscription)\n\n    async def remove_subscription(self, id: str) -> None:\n        \"\"\"Remove a subscription from the runtime.\"\"\"","sourceCodeStart":793,"sourceCodeEnd":829,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/runtime/in_process/in_process_runtime.py#L793-L829","documentation":"try_get_underlying_agent_instance checks if the agent type exists in _agent_factories before attempting retrieval. If not found, LookupError is raised. This is the public API entry point for typed agent access, with the same registration requirement as _get_agent.","triggerScenarios":"Calling await runtime.try_get_underlying_agent_instance(AgentId('Unknown', 'key'), MyAgent) where 'Unknown' was never registered. The check happens before instantiation is attempted.","commonSituations":"Requesting an agent instance before registration, or after the runtime was recreated/reset. Type string mismatch between registration and retrieval.","solutions":["Register the factory for the agent type before calling try_get_underlying_agent_instance.","Verify the type string matches exactly (case-sensitive).","Handle LookupError gracefully if the agent may legitimately not exist."],"exampleFix":"# before\nagent = await runtime.try_get_underlying_agent_instance(\n    AgentId('my_agent', 'default'), MyAgent\n)  # raises LookupError\n\n# after\nawait runtime.register_factory('my_agent', lambda: MyAgent())\nagent = await runtime.try_get_underlying_agent_instance(\n    AgentId('my_agent', 'default'), MyAgent\n)","handlingStrategy":"try-catch","validationCode":"# Track registered types and check before calling\nif id.type not in my_registered_types:\n    raise ValueError(f'Agent {id.type} not registered')\nagent = await runtime.try_get_underlying_agent_instance(id, MyAgent)","typeGuard":"null","tryCatchPattern":"try:\n    agent = await runtime.try_get_underlying_agent_instance(id, MyAgent)\nexcept LookupError:\n    # agent not registered — handle gracefully\n    agent = None","preventionTips":["Register factories before calling try_get_underlying_agent_instance.","Use try/except LookupError for optional agent retrieval patterns.","Verify type strings match registration exactly."],"tags":["agent-runtime","try-get-agent","factory","registration","lookup","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}