microsoft/semantic-kernel · error · AgentInitializationException

Expected AzureOpenAISettings, got {type(settings).__name__}

Error message

Expected AzureOpenAISettings, got {type(settings).__name__}

What it means

Raised by AzureAssistantAgent.resolve_placeholders() when a caller passes a non-None settings object that is not an instance of AzureOpenAISettings. resolve_placeholders reads fields like chat_deployment_name and api_key directly off the object, so a wrong type yields silent garbage or AttributeError later; the guard fails fast instead.

Source

Thrown at python/semantic_kernel/agents/open_ai/azure_assistant_agent.py:252

    def resolve_placeholders(
        cls: type[Self],
        yaml_str: str,
        settings: "KernelBaseSettings | None" = None,
        extras: dict[str, Any] | None = None,
    ) -> str:
        """Substitute ${AzureOpenAI:Key} placeholders with fields from AzureOpenAIAgentSettings and extras."""
        import re

        pattern = re.compile(r"\$\{([^}]+)\}")

        # Build the mapping only if settings is provided and valid
        field_mapping: dict[str, Any] = {}

        if settings is None:
            settings = AzureOpenAISettings()

        if not isinstance(settings, AzureOpenAISettings):
            raise AgentInitializationException(f"Expected AzureOpenAISettings, got {type(settings).__name__}")

        field_mapping.update({
            "ChatModelId": cls._get_setting(getattr(settings, "chat_deployment_name", None)),
            "AgentId": cls._get_setting(getattr(settings, "agent_id", None)),
            "ApiKey": cls._get_setting(getattr(settings, "api_key", None)),
            "ApiVersion": cls._get_setting(getattr(settings, "api_version", None)),
            "BaseUrl": cls._get_setting(getattr(settings, "base_url", None)),
            "Endpoint": cls._get_setting(getattr(settings, "endpoint", None)),
            "TokenEndpoint": cls._get_setting(getattr(settings, "token_endpoint", None)),
        })

        if extras:
            field_mapping.update(extras)

        def replacer(match: re.Match[str]) -> str:
            """Replace the matched placeholder with the corresponding value from field_mapping."""
            full_key = match.group(1)  # for example, OpenAI:ApiKey
            section, _, key = full_key.partition(":")

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass an AzureOpenAISettings instance, or pass None to let the method build one from env.
  2. If you have a shared config object, construct AzureOpenAISettings(...) from its fields before calling resolve_placeholders.
  3. Double-check imports: ensure you imported AzureOpenAISettings from semantic_kernel.connectors.ai.open_ai.settings, not OpenAISettings.

Example fix

# before
AzureAssistantAgent.resolve_placeholders(yaml, settings=openai_settings)  # wrong type
# after
AzureAssistantAgent.resolve_placeholders(yaml, settings=AzureOpenAISettings())  # or None
Defensive patterns

Strategy: type-guard

Type guard

from semantic_kernel.connectors.ai.open_ai.settings import AzureOpenAISettings

def is_azure_openai_settings(s) -> bool:
    return isinstance(s, AzureOpenAISettings)

# before calling resolve_placeholders
if settings is not None and not is_azure_openai_settings(settings):
    settings = AzureOpenAISettings()  # or raise explicitly

Prevention

When it happens

Trigger: Calling AzureAssistantAgent.resolve_placeholders(yaml_str, settings=<some other settings object>) where settings is e.g. an OpenAISettings, a plain dict, or a custom pydantic model. Passing None is fine (it defaults to AzureOpenAISettings()); only a non-None, wrong-type value triggers this.

Common situations: Reusing an OpenAISettings (non-Azure) instance by mistake; feeding a manually-built dataclass/dict as 'settings'; refactoring shared config holders and changing the concrete class without updating call sites.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/dbd49959ffa09058. Report an issue: GitHub.