{"record":{"id":"43b4a8d66a4bdea3","repo":"microsoft/semantic-kernel","slug":"missing-required-client-in-azureaiagent-from-di","errorCode":null,"errorMessage":"Missing required 'client' in AzureAIAgent._from_dict()","messagePattern":"Missing required 'client' in AzureAIAgent\\._from_dict\\(\\)","errorType":"exception","errorClass":"AgentInitializationException","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/azure_ai/azure_ai_agent.py","lineNumber":503,"sourceCode":"        *,\n        kernel: Kernel,\n        prompt_template_config: PromptTemplateConfig | None = None,\n        **kwargs,\n    ) -> _T:\n        \"\"\"Create an Azure AI Agent from the provided dictionary.\n\n        Args:\n            data: The dictionary containing the agent data.\n            kernel: The kernel to use for the agent.\n            prompt_template_config: The prompt template configuration.\n            kwargs: Additional keyword arguments. Note: unsupported keys may raise validation errors.\n\n        Returns:\n            AzureAIAgent: The Azure AI Agent instance.\n        \"\"\"\n        client: AIProjectClient = kwargs.pop(\"client\", None)\n        if client is None:\n            raise AgentInitializationException(\"Missing required 'client' in AzureAIAgent._from_dict()\")\n\n        spec = AgentSpec.model_validate(data)\n\n        if \"settings\" in kwargs:\n            kwargs.pop(\"settings\")\n\n        args = data.pop(\"arguments\", None)\n        arguments = None\n        if args:\n            arguments = KernelArguments(**args)\n\n        # Handle arguments from kwargs, merging with any arguments from data\n        if \"arguments\" in kwargs and kwargs[\"arguments\"] is not None:\n            incoming_args = kwargs[\"arguments\"]\n            arguments = arguments | incoming_args if arguments is not None else incoming_args\n\n        if spec.id:\n            existing_definition = await client.agents.get_agent(spec.id)","sourceCodeStart":485,"sourceCodeEnd":521,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/azure_ai/azure_ai_agent.py#L485-L521","documentation":"Raised by AzureAIAgent._from_dict when the 'client' kwarg is absent or None. Declarative restoration needs an AIProjectClient to fetch/create the agent definition, so a missing client aborts early. Surfaced as AgentInitializationException.","triggerScenarios":"Calling the declarative restore path (e.g. via the agent YAML loader) without supplying client=... in kwargs; passing client=None explicitly; the orchestrator that loads the spec forgot to inject the client.","commonSituations":"Using a higher-level helper that wraps _from_dict but does not forward the client; switching from direct AzureAIAgent(...) construction to the declarative path and not realizing a client is mandatory; copy-paste from an example that built the client in a different variable.","solutions":["Build the client first (AzureAIAgent.create_client) and pass it as client=client to the declarative loader.","Check your loader/framework forwards **kwargs including 'client' down to _from_dict.","If the spec references an existing agent (spec.id set), you still need the client to fetch its definition."],"exampleFix":"// before\nagent = await AzureAIAgent._from_dict(data, kernel=kernel)  // no client\n// after\nclient = await AzureAIAgent.create_client(credential, endpoint)\nagent = await AzureAIAgent._from_dict(data, kernel=kernel, client=client)","handlingStrategy":"validation","validationCode":"def ensure_client_for_restore(kwargs):\n    if kwargs.get('client') is None:\n        raise ValueError('client= must be provided to AzureAIAgent._from_dict')\n    return kwargs","typeGuard":"def has_client_kwarg(kwargs) -> bool:\n    c = kwargs.get('client')\n    return c is not None and hasattr(c, 'agents')","tryCatchPattern":"try:\n    agent = await AzureAIAgent._from_dict(data, kernel=kernel, **kwargs)\nexcept AgentInitializationException as e:\n    if \"Missing required 'client'\" in str(e):\n        log.error('Build and pass client=client to the declarative loader')\n    raise","preventionTips":["Always create the client first and inject it as client= into the loader kwargs.","Ensure any framework wrapper forwards **kwargs including client.","Add a pre-check that kwargs contains a non-None client before calling _from_dict."],"tags":["azure-ai","declarative-spec","client","configuration","agent-initialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}