Skip to content

provider_adapter

Provider adapter abstractions.

This module defines the shared abstract base class used to implement provider-specific chat client adapters.

A provider adapter is responsible for:

  • validating that a model configuration object is compatible with the provider
  • performing any provider-specific setup before client creation
  • constructing a Microsoft Agent Framework chat client instance directly from the user-supplied model configuration

ProviderAdapter

Bases: ABC

Abstract base class for provider-specific chat client adapters.

Attributes:

Name Type Description
provider_name str

Name of the provider handled by the adapter.

chat_client Type[BaseChatClient]

Chat client class used to instantiate provider-specific clients.

Methods:

Name Description
validate_model_config

Validate a model configuration before client creation.

pre_create

Perform provider-specific setup before client creation.

create_client

Validate configuration and create a chat client instance.

Source code in src/mada/core/chat_clients/provider_adapter.py
class ProviderAdapter(ABC):
    """
    Abstract base class for provider-specific chat client adapters.

    Attributes:
        provider_name:
            Name of the provider handled by the adapter.
        chat_client:
            Chat client class used to instantiate provider-specific clients.

    Methods:
        validate_model_config:
            Validate a model configuration before client creation.
        pre_create:
            Perform provider-specific setup before client creation.
        create_client:
            Validate configuration and create a chat client instance.
    """

    provider_name: str
    chat_client: Type[BaseChatClient]

    @abstractmethod
    def validate_model_config(self, model_config: BaseModelConfig) -> None:
        """
        Validate a model configuration for this provider.

        Args:
            model_config:
                Model configuration to validate.

        Raises:
            ValueError:
                If the configuration is invalid for the provider.
        """
        pass

    def pre_create(self, model_config: BaseModelConfig) -> None:
        """
        Run provider-specific logic before constructing the chat client.

        This hook allows subclasses to inspect configuration or perform setup
        before the client instance is created.

        Args:
            model_config:
                Model configuration being used to create the client.
        """
        pass

    def create_client(self, model_config: BaseModelConfig) -> BaseChatClient:
        """
        Create a provider-specific chat client from a model configuration.

        This method validates the configuration, executes any provider-specific
        pre-creation hook, and instantiates the configured chat client using
        the exact user-supplied model name.

        Args:
            model_config:
                Model configuration used to build the client.

        Returns:
            An initialized provider-specific chat client.
        """
        self.validate_model_config(model_config)
        self.pre_create(model_config)

        kwargs = model_config.to_client_kwargs()
        return self.chat_client(**kwargs)

create_client(model_config)

Create a provider-specific chat client from a model configuration.

This method validates the configuration, executes any provider-specific pre-creation hook, and instantiates the configured chat client using the exact user-supplied model name.

Parameters:

Name Type Description Default
model_config BaseModelConfig

Model configuration used to build the client.

required

Returns:

Type Description
BaseChatClient

An initialized provider-specific chat client.

Source code in src/mada/core/chat_clients/provider_adapter.py
def create_client(self, model_config: BaseModelConfig) -> BaseChatClient:
    """
    Create a provider-specific chat client from a model configuration.

    This method validates the configuration, executes any provider-specific
    pre-creation hook, and instantiates the configured chat client using
    the exact user-supplied model name.

    Args:
        model_config:
            Model configuration used to build the client.

    Returns:
        An initialized provider-specific chat client.
    """
    self.validate_model_config(model_config)
    self.pre_create(model_config)

    kwargs = model_config.to_client_kwargs()
    return self.chat_client(**kwargs)

pre_create(model_config)

Run provider-specific logic before constructing the chat client.

This hook allows subclasses to inspect configuration or perform setup before the client instance is created.

Parameters:

Name Type Description Default
model_config BaseModelConfig

Model configuration being used to create the client.

required
Source code in src/mada/core/chat_clients/provider_adapter.py
def pre_create(self, model_config: BaseModelConfig) -> None:
    """
    Run provider-specific logic before constructing the chat client.

    This hook allows subclasses to inspect configuration or perform setup
    before the client instance is created.

    Args:
        model_config:
            Model configuration being used to create the client.
    """
    pass

validate_model_config(model_config) abstractmethod

Validate a model configuration for this provider.

Parameters:

Name Type Description Default
model_config BaseModelConfig

Model configuration to validate.

required

Raises:

Type Description
ValueError

If the configuration is invalid for the provider.

Source code in src/mada/core/chat_clients/provider_adapter.py
@abstractmethod
def validate_model_config(self, model_config: BaseModelConfig) -> None:
    """
    Validate a model configuration for this provider.

    Args:
        model_config:
            Model configuration to validate.

    Raises:
        ValueError:
            If the configuration is invalid for the provider.
    """
    pass