chat_client_factory
Factory utilities for creating chat clients from provider-specific adapters.
This module exposes
MADAChatClientFactory,
which registers built-in provider adapters and creates
agent_framework.BaseChatClient
instances from a BaseModelConfig.
MADAChatClientFactory
Factory for registering provider adapters and creating chat clients.
The factory maintains a mapping of provider names to ProviderAdapter
instances. Each adapter is responsible for validating configuration and
constructing the provider-specific client.
Attributes:
| Name | Type | Description |
|---|---|---|
_adapters |
Dict[str, ProviderAdapter]
|
Mapping of provider names to registered provider adapters. |
Methods:
| Name | Description |
|---|---|
register_provider_adapter |
Register a provider adapter with the factory. |
get_adapter |
Return the adapter registered for a provider. |
create |
Create a chat client from a model configuration. |
Source code in src/mada/core/chat_clients/chat_client_factory.py
__init__()
Initialize the factory and register built-in provider adapters.
create(model_config)
Create a chat client for the provider and model in model_config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_config
|
BaseModelConfig
|
Model configuration containing the target provider and model details. |
required |
Returns:
| Type | Description |
|---|---|
BaseChatClient
|
A provider-specific chat client instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no adapter is registered for the requested provider, or if client creation fails. |
Source code in src/mada/core/chat_clients/chat_client_factory.py
get_adapter(provider)
Return the registered adapter for a provider, if available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
Provider name. |
required |
Returns:
| Type | Description |
|---|---|
Optional[ProviderAdapter]
|
The matching provider adapter, or |
Optional[ProviderAdapter]
|
registered. |
Source code in src/mada/core/chat_clients/chat_client_factory.py
register_provider_adapter(adapter)
Register a provider adapter with the factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
ProviderAdapter
|
Provider adapter to register, keyed by its |
required |