microsoft/semantic-kernel · error · AgentInitializationException

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

Error message

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

What it means

Raised by AzureResponsesAgent.resolve_placeholders() when the settings argument is not None and is not an AzureOpenAISettings instance. The method reads responses_deployment_name, api_key, etc. directly off the object, so a wrong type would produce incorrect substitutions; it fails fast instead.

Source

Thrown at python/semantic_kernel/agents/open_ai/azure_responses_agent.py:259

    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": getattr(settings, "responses_deployment_name", None),
            "AgentId": getattr(settings, "agent_id", None),
            "ApiKey": getattr(settings, "api_key", None),
            "ApiVersion": getattr(settings, "api_version", None),
            "BaseUrl": getattr(settings, "base_url", None),
            "Endpoint": getattr(settings, "endpoint", None),
            "TokenEndpoint": 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, AzureOpenAI:ApiKey
            section, _, key = full_key.partition(":")

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass an AzureOpenAISettings instance, or None.
  2. Build AzureOpenAISettings(...) from your shared config before calling resolve_placeholders.
  3. Verify the import path resolves to AzureOpenAISettings (not OpenAISettings).

Example fix

# before
AzureResponsesAgent.resolve_placeholders(yaml, settings=my_generic_config)
# after
AzureResponsesAgent.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)

if settings is not None and not is_azure_openai_settings(settings):
    settings = AzureOpenAISettings()

Prevention

When it happens

Trigger: Calling AzureResponsesAgent.resolve_placeholders(yaml_str, settings=<wrong type>) such as OpenAISettings, a dict, or another pydantic model. Passing None is allowed (defaults to AzureOpenAISettings()).

Common situations: Sharing a generic config object across agents; importing the wrong settings class; passing a dict of resolved values instead of an AzureOpenAISettings instance.

Related errors


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