mada 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mada/__init__.py +11 -0
- mada/common/__init__.py +14 -0
- mada/common/exceptions.py +12 -0
- mada/core/__init__.py +64 -0
- mada/core/chat_clients/__init__.py +47 -0
- mada/core/chat_clients/bedrock_adapter.py +120 -0
- mada/core/chat_clients/chat_client_factory.py +123 -0
- mada/core/chat_clients/livai_adapter.py +34 -0
- mada/core/chat_clients/openai_adapter.py +58 -0
- mada/core/chat_clients/provider_adapter.py +96 -0
- mada/core/config/__init__.py +65 -0
- mada/core/config/agents.py +126 -0
- mada/core/config/app.py +121 -0
- mada/core/config/database.py +172 -0
- mada/core/config/interface.py +54 -0
- mada/core/config/mcp_servers.py +38 -0
- mada/core/config/models.py +347 -0
- mada/core/config/utils.py +41 -0
- mada/core/coordinator.py +87 -0
- mada/core/database/__init__.py +21 -0
- mada/core/database/base_db.py +133 -0
- mada/core/database/db_factory.py +151 -0
- mada/core/database/postgresql.py +197 -0
- mada/core/database/session_manager.py +180 -0
- mada/core/database/sqlite.py +186 -0
- mada/core/orchestrator.py +839 -0
- mada/interfaces/__init__.py +10 -0
- mada/interfaces/cli/__init__.py +4 -0
- mada/interfaces/cli/main.py +349 -0
- mada/interfaces/gradio/__init__.py +4 -0
- mada/interfaces/gradio/assets/__init__.py +9 -0
- mada/interfaces/gradio/assets/gradio.css +29 -0
- mada/interfaces/gradio/assets/gradio.js +77 -0
- mada/interfaces/gradio/interface.py +344 -0
- mada/interfaces/gradio/main.py +188 -0
- mada/interfaces/gradio/mcp_client_wrapper.py +290 -0
- mada/interfaces/gradio/utils.py +114 -0
- mada/interfaces/openai_api/__init__.py +4 -0
- mada/interfaces/openai_api/main.py +565 -0
- mada/main.py +197 -0
- mada-0.1.0.dist-info/METADATA +354 -0
- mada-0.1.0.dist-info/RECORD +46 -0
- mada-0.1.0.dist-info/WHEEL +5 -0
- mada-0.1.0.dist-info/entry_points.txt +5 -0
- mada-0.1.0.dist-info/licenses/LICENSE +207 -0
- mada-0.1.0.dist-info/top_level.txt +1 -0
mada/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
MADA - Multi-agent orchestration system for MADA workflows.
|
|
6
|
+
|
|
7
|
+
This package provides orchestration capabilities for coordinating multiple
|
|
8
|
+
autonomous agents that interact with MCP servers to execute complex workflows.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
__version__ = "0.1.0"
|
mada/common/__init__.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
The common package includes code commonly used across the entire
|
|
6
|
+
MADA project.
|
|
7
|
+
|
|
8
|
+
Modules:
|
|
9
|
+
exceptions: Custom exceptions for MADA.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from mada.common.exceptions import MADAUnsupportedDatabase
|
|
13
|
+
|
|
14
|
+
__all__ = ["MADAUnsupportedDatabase"]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Custom exceptions for MADA.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
class MADAUnsupportedDatabase(Exception):
|
|
9
|
+
"""
|
|
10
|
+
Used when trying to initialize a connection to an unsupported
|
|
11
|
+
database type.
|
|
12
|
+
"""
|
mada/core/__init__.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Core orchestration functionality.
|
|
6
|
+
|
|
7
|
+
This module contains the fundamental components for orchestrating multi-agent workflows.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
from mada.core.chat_clients import (
|
|
12
|
+
BedrockAdapter,
|
|
13
|
+
LivAIAdapter,
|
|
14
|
+
MADAChatClientFactory,
|
|
15
|
+
OpenAIAdapter,
|
|
16
|
+
ProviderAdapter,
|
|
17
|
+
chat_client_factory,
|
|
18
|
+
)
|
|
19
|
+
from mada.core.config import (
|
|
20
|
+
AgentConfig,
|
|
21
|
+
AppConfig,
|
|
22
|
+
BaseModelConfig,
|
|
23
|
+
BedrockModelConfig,
|
|
24
|
+
DatabaseConfig,
|
|
25
|
+
InterfaceConfig,
|
|
26
|
+
MCPServerConfig,
|
|
27
|
+
ModelConfig,
|
|
28
|
+
OpenAIModelConfig,
|
|
29
|
+
PostgreSQLConfig,
|
|
30
|
+
SQLiteConfig,
|
|
31
|
+
expand_env_vars,
|
|
32
|
+
load_config_from_json,
|
|
33
|
+
load_database_config,
|
|
34
|
+
load_model_config,
|
|
35
|
+
)
|
|
36
|
+
from mada.core.coordinator import MCPAgentManager
|
|
37
|
+
from mada.core.orchestrator import MADAOrchestrator
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"AgentConfig",
|
|
42
|
+
"AppConfig",
|
|
43
|
+
"BaseModelConfig",
|
|
44
|
+
"BedrockAdapter",
|
|
45
|
+
"BedrockModelConfig",
|
|
46
|
+
"DatabaseConfig",
|
|
47
|
+
"InterfaceConfig",
|
|
48
|
+
"LivAIAdapter",
|
|
49
|
+
"MADAChatClientFactory",
|
|
50
|
+
"MADAOrchestrator",
|
|
51
|
+
"MCPAgentManager",
|
|
52
|
+
"MCPServerConfig",
|
|
53
|
+
"ModelConfig",
|
|
54
|
+
"OpenAIAdapter",
|
|
55
|
+
"OpenAIModelConfig",
|
|
56
|
+
"PostgreSQLConfig",
|
|
57
|
+
"ProviderAdapter",
|
|
58
|
+
"SQLiteConfig",
|
|
59
|
+
"chat_client_factory",
|
|
60
|
+
"expand_env_vars",
|
|
61
|
+
"load_config_from_json",
|
|
62
|
+
"load_database_config",
|
|
63
|
+
"load_model_config",
|
|
64
|
+
]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Chat client adapter package.
|
|
6
|
+
|
|
7
|
+
This package provides provider-specific chat client adapters and factory
|
|
8
|
+
utilities for creating chat clients from model configuration objects. It
|
|
9
|
+
exposes adapter implementations for supported providers, along with the shared
|
|
10
|
+
[`ProviderAdapter`][core.chat_clients.provider_adapter.ProviderAdapter] base
|
|
11
|
+
class and the
|
|
12
|
+
[`MADAChatClientFactory`][core.chat_clients.chat_client_factory.MADAChatClientFactory]
|
|
13
|
+
used to create chat clients.
|
|
14
|
+
|
|
15
|
+
Modules:
|
|
16
|
+
bedrock_adapter:
|
|
17
|
+
Provides the [`BedrockAdapter`][core.chat_clients.bedrock_adapter.BedrockAdapter]
|
|
18
|
+
implementation for AWS Bedrock models.
|
|
19
|
+
chat_client_factory:
|
|
20
|
+
Provides [`MADAChatClientFactory`][core.chat_clients.chat_client_factory.MADAChatClientFactory]
|
|
21
|
+
and the shared `chat_client_factory` instance for constructing chat clients.
|
|
22
|
+
livai_adapter:
|
|
23
|
+
Provides the [`LivAIAdapter`][core.chat_clients.livai_adapter.LivAIAdapter]
|
|
24
|
+
implementation for LivAI-hosted models.
|
|
25
|
+
openai_adapter:
|
|
26
|
+
Provides the [`OpenAIAdapter`][core.chat_clients.openai_adapter.OpenAIAdapter]
|
|
27
|
+
implementation for OpenAI models.
|
|
28
|
+
provider_adapter:
|
|
29
|
+
Provides the shared [`ProviderAdapter`][core.chat_clients.provider_adapter.ProviderAdapter]
|
|
30
|
+
base class and related model metadata utilities.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
from mada.core.chat_clients.bedrock_adapter import BedrockAdapter
|
|
34
|
+
from mada.core.chat_clients.chat_client_factory import MADAChatClientFactory, chat_client_factory
|
|
35
|
+
from mada.core.chat_clients.livai_adapter import LivAIAdapter
|
|
36
|
+
from mada.core.chat_clients.openai_adapter import OpenAIAdapter
|
|
37
|
+
from mada.core.chat_clients.provider_adapter import ProviderAdapter
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
__all__ = [
|
|
41
|
+
"BedrockAdapter",
|
|
42
|
+
"LivAIAdapter",
|
|
43
|
+
"MADAChatClientFactory",
|
|
44
|
+
"OpenAIAdapter",
|
|
45
|
+
"ProviderAdapter",
|
|
46
|
+
"chat_client_factory",
|
|
47
|
+
]
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
AWS Bedrock provider adapter implementation.
|
|
6
|
+
|
|
7
|
+
This module defines [`BedrockAdapter`][core.chat_clients.bedrock_adapter.BedrockAdapter],
|
|
8
|
+
a [`ProviderAdapter`][core.chat_clients.provider_adapter.ProviderAdapter] implementation
|
|
9
|
+
for AWS Bedrock chat models. It validates that incoming model configuration objects are
|
|
10
|
+
instances of [`BedrockModelConfig`][core.config.models.BedrockModelConfig] and prepares
|
|
11
|
+
AWS authentication environment variables before chat client creation.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
|
|
16
|
+
from agent_framework.amazon import BedrockChatClient
|
|
17
|
+
|
|
18
|
+
from mada.core.config import BaseModelConfig, BedrockModelConfig
|
|
19
|
+
from mada.core.chat_clients.provider_adapter import ProviderAdapter
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class BedrockAdapter(ProviderAdapter):
|
|
23
|
+
"""
|
|
24
|
+
Provider adapter for AWS Bedrock chat models.
|
|
25
|
+
|
|
26
|
+
This adapter validates Bedrock-specific model configuration objects and sets
|
|
27
|
+
AWS credential-related environment variables before constructing a chat
|
|
28
|
+
client.
|
|
29
|
+
|
|
30
|
+
Attributes:
|
|
31
|
+
provider_name:
|
|
32
|
+
Name of the provider handled by this adapter.
|
|
33
|
+
chat_client:
|
|
34
|
+
Chat client class used to create Bedrock chat clients.
|
|
35
|
+
|
|
36
|
+
Methods:
|
|
37
|
+
validate_model_config:
|
|
38
|
+
Validate that `model_config` is a `BedrockModelConfig` instance.
|
|
39
|
+
_set_env_if_allowed:
|
|
40
|
+
Set an environment variable if permitted by the current
|
|
41
|
+
configuration.
|
|
42
|
+
pre_create:
|
|
43
|
+
Apply environment-based credential configuration before client
|
|
44
|
+
creation.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
provider_name = "aws-bedrock"
|
|
48
|
+
chat_client = BedrockChatClient
|
|
49
|
+
|
|
50
|
+
def validate_model_config(self, model_config: BaseModelConfig) -> None:
|
|
51
|
+
"""
|
|
52
|
+
Validate that `model_config` is compatible with the Bedrock adapter.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
model_config:
|
|
56
|
+
Model configuration to validate.
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
TypeError:
|
|
60
|
+
Raised if `model_config` is not a `BedrockModelConfig`
|
|
61
|
+
instance.
|
|
62
|
+
"""
|
|
63
|
+
if not isinstance(model_config, BedrockModelConfig):
|
|
64
|
+
raise TypeError(
|
|
65
|
+
f"{self.provider_name} adapter requires BedrockModelConfig, "
|
|
66
|
+
f"got {type(model_config).__name__}"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
def _set_env_if_allowed(self, name: str, value: str, override: bool = False) -> None:
|
|
70
|
+
"""
|
|
71
|
+
Set an environment variable if a value is provided and overwriting is
|
|
72
|
+
allowed.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
name:
|
|
76
|
+
Name of the environment variable to set.
|
|
77
|
+
value:
|
|
78
|
+
Value to assign to `name`.
|
|
79
|
+
override:
|
|
80
|
+
Whether an existing conflicting environment variable may be
|
|
81
|
+
overwritten.
|
|
82
|
+
|
|
83
|
+
Raises:
|
|
84
|
+
RuntimeError:
|
|
85
|
+
Raised if `name` is already set to a different value and
|
|
86
|
+
`override` is `False`.
|
|
87
|
+
"""
|
|
88
|
+
if not value:
|
|
89
|
+
return
|
|
90
|
+
|
|
91
|
+
existing = os.environ.get(name)
|
|
92
|
+
if existing and existing != value and not override:
|
|
93
|
+
raise RuntimeError(
|
|
94
|
+
f"Refusing to overwrite existing environment variable '{name}'. "
|
|
95
|
+
f"Set override_env_credentials=True to allow this."
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
os.environ[name] = value
|
|
99
|
+
|
|
100
|
+
def pre_create(self, model_config: BedrockModelConfig) -> None:
|
|
101
|
+
"""
|
|
102
|
+
Prepare AWS credential environment variables before client creation.
|
|
103
|
+
|
|
104
|
+
Args:
|
|
105
|
+
model_config:
|
|
106
|
+
Bedrock model configuration containing credential values and
|
|
107
|
+
override settings.
|
|
108
|
+
|
|
109
|
+
Raises:
|
|
110
|
+
RuntimeError:
|
|
111
|
+
Raised if an existing environment variable would be overwritten
|
|
112
|
+
without permission.
|
|
113
|
+
"""
|
|
114
|
+
override = getattr(model_config, "override_env_credentials", False)
|
|
115
|
+
|
|
116
|
+
self._set_env_if_allowed("AWS_BEARER_TOKEN_BEDROCK", model_config.bearer_token, override)
|
|
117
|
+
self._set_env_if_allowed("AWS_PROFILE", model_config.aws_profile, override)
|
|
118
|
+
self._set_env_if_allowed("AWS_ACCESS_KEY_ID", model_config.aws_access_key_id, override)
|
|
119
|
+
self._set_env_if_allowed("AWS_SECRET_ACCESS_KEY", model_config.aws_secret_access_key, override)
|
|
120
|
+
self._set_env_if_allowed("AWS_SESSION_TOKEN", model_config.aws_session_token, override)
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Factory utilities for creating chat clients from provider-specific adapters.
|
|
6
|
+
|
|
7
|
+
This module exposes
|
|
8
|
+
[`MADAChatClientFactory`][core.chat_clients.chat_client_factory.MADAChatClientFactory],
|
|
9
|
+
which registers built-in provider adapters and creates
|
|
10
|
+
[`agent_framework.BaseChatClient`](https://learn.microsoft.com/en-us/python/api/agent-framework-core/agent_framework.basechatclient?view=agent-framework-python-latest)
|
|
11
|
+
instances from a [`BaseModelConfig`][core.config.models.BaseModelConfig].
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import logging
|
|
15
|
+
from typing import Dict, Optional
|
|
16
|
+
|
|
17
|
+
from agent_framework import BaseChatClient
|
|
18
|
+
|
|
19
|
+
from mada.core.config import BaseModelConfig
|
|
20
|
+
from mada.core.chat_clients.bedrock_adapter import BedrockAdapter
|
|
21
|
+
from mada.core.chat_clients.livai_adapter import LivAIAdapter
|
|
22
|
+
from mada.core.chat_clients.openai_adapter import OpenAIAdapter
|
|
23
|
+
from mada.core.chat_clients.provider_adapter import ProviderAdapter
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
LOG = logging.getLogger("mada-interface")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class MADAChatClientFactory:
|
|
30
|
+
"""
|
|
31
|
+
Factory for registering provider adapters and creating chat clients.
|
|
32
|
+
|
|
33
|
+
The factory maintains a mapping of provider names to `ProviderAdapter`
|
|
34
|
+
instances. Each adapter is responsible for validating configuration and
|
|
35
|
+
constructing the provider-specific client.
|
|
36
|
+
|
|
37
|
+
Attributes:
|
|
38
|
+
_adapters:
|
|
39
|
+
Mapping of provider names to registered provider adapters.
|
|
40
|
+
|
|
41
|
+
Methods:
|
|
42
|
+
register_provider_adapter:
|
|
43
|
+
Register a provider adapter with the factory.
|
|
44
|
+
get_adapter:
|
|
45
|
+
Return the adapter registered for a provider.
|
|
46
|
+
create:
|
|
47
|
+
Create a chat client from a model configuration.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self):
|
|
51
|
+
"""
|
|
52
|
+
Initialize the factory and register built-in provider adapters.
|
|
53
|
+
"""
|
|
54
|
+
self._adapters: Dict[str, ProviderAdapter] = {}
|
|
55
|
+
self._register_builtins()
|
|
56
|
+
|
|
57
|
+
def _register_builtins(self) -> None:
|
|
58
|
+
"""
|
|
59
|
+
Register the default provider adapters supported by the application.
|
|
60
|
+
"""
|
|
61
|
+
self.register_provider_adapter(OpenAIAdapter())
|
|
62
|
+
self.register_provider_adapter(LivAIAdapter())
|
|
63
|
+
self.register_provider_adapter(BedrockAdapter())
|
|
64
|
+
|
|
65
|
+
def register_provider_adapter(self, adapter: ProviderAdapter) -> None:
|
|
66
|
+
"""
|
|
67
|
+
Register a provider adapter with the factory.
|
|
68
|
+
|
|
69
|
+
Args:
|
|
70
|
+
adapter:
|
|
71
|
+
Provider adapter to register, keyed by its `provider_name`
|
|
72
|
+
attribute.
|
|
73
|
+
"""
|
|
74
|
+
self._adapters[adapter.provider_name] = adapter
|
|
75
|
+
LOG.debug("Registered provider adapter '%s'", adapter.provider_name)
|
|
76
|
+
|
|
77
|
+
def get_adapter(self, provider: str) -> Optional[ProviderAdapter]:
|
|
78
|
+
"""
|
|
79
|
+
Return the registered adapter for a provider, if available.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
provider:
|
|
83
|
+
Provider name.
|
|
84
|
+
|
|
85
|
+
Returns:
|
|
86
|
+
The matching provider adapter, or `None` if the provider is not
|
|
87
|
+
registered.
|
|
88
|
+
"""
|
|
89
|
+
return self._adapters.get(provider)
|
|
90
|
+
|
|
91
|
+
def create(self, model_config: BaseModelConfig) -> BaseChatClient:
|
|
92
|
+
"""
|
|
93
|
+
Create a chat client for the provider and model in `model_config`.
|
|
94
|
+
|
|
95
|
+
Args:
|
|
96
|
+
model_config:
|
|
97
|
+
Model configuration containing the target provider and model
|
|
98
|
+
details.
|
|
99
|
+
|
|
100
|
+
Returns:
|
|
101
|
+
A provider-specific chat client instance.
|
|
102
|
+
|
|
103
|
+
Raises:
|
|
104
|
+
ValueError:
|
|
105
|
+
If no adapter is registered for the requested provider, or if
|
|
106
|
+
client creation fails.
|
|
107
|
+
"""
|
|
108
|
+
adapter = self._adapters.get(model_config.provider)
|
|
109
|
+
if adapter is None:
|
|
110
|
+
raise ValueError(
|
|
111
|
+
f"No provider adapter registered for provider '{model_config.provider}'"
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
try:
|
|
115
|
+
return adapter.create_client(model_config)
|
|
116
|
+
except Exception as e:
|
|
117
|
+
raise ValueError(
|
|
118
|
+
f"Failed to create chat client for provider='{model_config.provider}', "
|
|
119
|
+
f"model='{model_config.model}': {e}"
|
|
120
|
+
) from e
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
chat_client_factory = MADAChatClientFactory()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
LivAI provider adapter implementation.
|
|
6
|
+
|
|
7
|
+
This module defines [`LivAIAdapter`][core.chat_clients.livai_adapter.LivAIAdapter],
|
|
8
|
+
an [`OpenAIAdapter`][core.chat_clients.openai_adapter.OpenAIAdapter] specialization
|
|
9
|
+
for LivAI-hosted models.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from agent_framework.openai import OpenAIChatClient
|
|
13
|
+
|
|
14
|
+
from mada.core.chat_clients.openai_adapter import OpenAIAdapter
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class LivAIAdapter(OpenAIAdapter):
|
|
18
|
+
"""
|
|
19
|
+
Provider adapter for LivAI-hosted chat models.
|
|
20
|
+
|
|
21
|
+
LivAI models are served through OpenAI's API, so we can re-use the
|
|
22
|
+
same behavior as the
|
|
23
|
+
[`OpenAIAdapter`][core.chat_clients.openai_adapter.OpenAIAdapter],
|
|
24
|
+
while exposing a different provider name.
|
|
25
|
+
|
|
26
|
+
Attributes:
|
|
27
|
+
provider_name:
|
|
28
|
+
Name of the provider handled by this adapter.
|
|
29
|
+
chat_client:
|
|
30
|
+
Chat client class used to create LivAI chat clients.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
provider_name = "livai"
|
|
34
|
+
chat_client = OpenAIChatClient
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
OpenAI provider adapter implementation.
|
|
6
|
+
|
|
7
|
+
This module defines [`OpenAIAdapter`][core.chat_clients.openai_adapter.OpenAIAdapter],
|
|
8
|
+
a [`ProviderAdapter`][core.chat_clients.provider_adapter.ProviderAdapter] implementation
|
|
9
|
+
for OpenAI chat models. It validates that incoming model configuration objects are
|
|
10
|
+
instances of [`OpenAIModelConfig`][core.config.models.OpenAIModelConfig] before client
|
|
11
|
+
creation.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from agent_framework.openai import OpenAIChatClient
|
|
15
|
+
|
|
16
|
+
from mada.core.config import BaseModelConfig, OpenAIModelConfig
|
|
17
|
+
from mada.core.chat_clients.provider_adapter import ProviderAdapter
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class OpenAIAdapter(ProviderAdapter):
|
|
21
|
+
"""
|
|
22
|
+
Provider adapter for OpenAI chat models.
|
|
23
|
+
|
|
24
|
+
This adapter ensures that client creation uses `OpenAIModelConfig`
|
|
25
|
+
instances.
|
|
26
|
+
|
|
27
|
+
Attributes:
|
|
28
|
+
provider_name:
|
|
29
|
+
Name of the provider handled by this adapter.
|
|
30
|
+
chat_client:
|
|
31
|
+
Chat client class used to create OpenAI chat clients.
|
|
32
|
+
|
|
33
|
+
Methods:
|
|
34
|
+
validate_model_config:
|
|
35
|
+
Validate that `model_config` is an `OpenAIModelConfig` instance.
|
|
36
|
+
"""
|
|
37
|
+
|
|
38
|
+
provider_name = "openai"
|
|
39
|
+
chat_client = OpenAIChatClient
|
|
40
|
+
|
|
41
|
+
def validate_model_config(self, model_config: BaseModelConfig) -> None:
|
|
42
|
+
"""
|
|
43
|
+
Validate that `model_config` is compatible with the OpenAI adapter.
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
model_config:
|
|
47
|
+
Model configuration to validate.
|
|
48
|
+
|
|
49
|
+
Raises:
|
|
50
|
+
TypeError:
|
|
51
|
+
Raised if `model_config` is not an `OpenAIModelConfig`
|
|
52
|
+
instance.
|
|
53
|
+
"""
|
|
54
|
+
if not isinstance(model_config, OpenAIModelConfig):
|
|
55
|
+
raise TypeError(
|
|
56
|
+
f"{self.provider_name} adapter requires OpenAIModelConfig, "
|
|
57
|
+
f"got {type(model_config).__name__}"
|
|
58
|
+
)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Provider adapter abstractions.
|
|
6
|
+
|
|
7
|
+
This module defines the shared abstract base class used to implement
|
|
8
|
+
provider-specific chat client adapters.
|
|
9
|
+
|
|
10
|
+
A provider adapter is responsible for:
|
|
11
|
+
|
|
12
|
+
- validating that a model configuration object is compatible with the provider
|
|
13
|
+
- performing any provider-specific setup before client creation
|
|
14
|
+
- constructing a Microsoft Agent Framework chat client instance directly from
|
|
15
|
+
the user-supplied model configuration
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
from abc import ABC, abstractmethod
|
|
20
|
+
from typing import Type
|
|
21
|
+
|
|
22
|
+
from agent_framework import BaseChatClient
|
|
23
|
+
|
|
24
|
+
from mada.core.config import BaseModelConfig
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class ProviderAdapter(ABC):
|
|
28
|
+
"""
|
|
29
|
+
Abstract base class for provider-specific chat client adapters.
|
|
30
|
+
|
|
31
|
+
Attributes:
|
|
32
|
+
provider_name:
|
|
33
|
+
Name of the provider handled by the adapter.
|
|
34
|
+
chat_client:
|
|
35
|
+
Chat client class used to instantiate provider-specific clients.
|
|
36
|
+
|
|
37
|
+
Methods:
|
|
38
|
+
validate_model_config:
|
|
39
|
+
Validate a model configuration before client creation.
|
|
40
|
+
pre_create:
|
|
41
|
+
Perform provider-specific setup before client creation.
|
|
42
|
+
create_client:
|
|
43
|
+
Validate configuration and create a chat client instance.
|
|
44
|
+
"""
|
|
45
|
+
|
|
46
|
+
provider_name: str
|
|
47
|
+
chat_client: Type[BaseChatClient]
|
|
48
|
+
|
|
49
|
+
@abstractmethod
|
|
50
|
+
def validate_model_config(self, model_config: BaseModelConfig) -> None:
|
|
51
|
+
"""
|
|
52
|
+
Validate a model configuration for this provider.
|
|
53
|
+
|
|
54
|
+
Args:
|
|
55
|
+
model_config:
|
|
56
|
+
Model configuration to validate.
|
|
57
|
+
|
|
58
|
+
Raises:
|
|
59
|
+
ValueError:
|
|
60
|
+
If the configuration is invalid for the provider.
|
|
61
|
+
"""
|
|
62
|
+
pass
|
|
63
|
+
|
|
64
|
+
def pre_create(self, model_config: BaseModelConfig) -> None:
|
|
65
|
+
"""
|
|
66
|
+
Run provider-specific logic before constructing the chat client.
|
|
67
|
+
|
|
68
|
+
This hook allows subclasses to inspect configuration or perform setup
|
|
69
|
+
before the client instance is created.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
model_config:
|
|
73
|
+
Model configuration being used to create the client.
|
|
74
|
+
"""
|
|
75
|
+
pass
|
|
76
|
+
|
|
77
|
+
def create_client(self, model_config: BaseModelConfig) -> BaseChatClient:
|
|
78
|
+
"""
|
|
79
|
+
Create a provider-specific chat client from a model configuration.
|
|
80
|
+
|
|
81
|
+
This method validates the configuration, executes any provider-specific
|
|
82
|
+
pre-creation hook, and instantiates the configured chat client using
|
|
83
|
+
the exact user-supplied model name.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
model_config:
|
|
87
|
+
Model configuration used to build the client.
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
An initialized provider-specific chat client.
|
|
91
|
+
"""
|
|
92
|
+
self.validate_model_config(model_config)
|
|
93
|
+
self.pre_create(model_config)
|
|
94
|
+
|
|
95
|
+
kwargs = model_config.to_client_kwargs()
|
|
96
|
+
return self.chat_client(**kwargs)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Copyright 2026, Lawrence Livermore National Security, LLC and MADA contributors
|
|
2
|
+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
3
|
+
|
|
4
|
+
"""
|
|
5
|
+
Configuration package for the MADA orchestrator.
|
|
6
|
+
|
|
7
|
+
This package provides configuration models and helper utilities used to define
|
|
8
|
+
application behavior, model backends, agents, database settings, MCP server
|
|
9
|
+
connections, interface settings, and environment variable expansion.
|
|
10
|
+
|
|
11
|
+
Modules:
|
|
12
|
+
agents:
|
|
13
|
+
Defines [`AgentConfig`][core.config.agents.AgentConfig] for individual
|
|
14
|
+
agent configuration and serialization helpers.
|
|
15
|
+
app:
|
|
16
|
+
Defines [`AppConfig`][core.config.app.AppConfig] and utilities for loading
|
|
17
|
+
full application configuration from JSON.
|
|
18
|
+
database:
|
|
19
|
+
Defines database configuration models for SQLite and PostgreSQL, along
|
|
20
|
+
with database config loading helpers.
|
|
21
|
+
interface:
|
|
22
|
+
Defines [`InterfaceConfig`][core.config.interface.InterfaceConfig] for
|
|
23
|
+
multi-agent interface layout and UI customization settings.
|
|
24
|
+
mcp_servers:
|
|
25
|
+
Defines [`MCPServerConfig`][core.config.mcp_servers.MCPServerConfig] for
|
|
26
|
+
individual MCP server connection and launch settings.
|
|
27
|
+
models:
|
|
28
|
+
Defines provider model configuration classes and model config loading
|
|
29
|
+
helpers.
|
|
30
|
+
utils:
|
|
31
|
+
Defines shared utility helpers, including environment variable
|
|
32
|
+
expansion.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
from mada.core.config.agents import AgentConfig
|
|
36
|
+
from mada.core.config.app import AppConfig, load_config_from_json
|
|
37
|
+
from mada.core.config.database import DatabaseConfig, PostgreSQLConfig, SQLiteConfig, load_database_config
|
|
38
|
+
from mada.core.config.interface import InterfaceConfig
|
|
39
|
+
from mada.core.config.mcp_servers import MCPServerConfig
|
|
40
|
+
from mada.core.config.models import (
|
|
41
|
+
ModelConfig,
|
|
42
|
+
BaseModelConfig,
|
|
43
|
+
BedrockModelConfig,
|
|
44
|
+
OpenAIModelConfig,
|
|
45
|
+
load_model_config,
|
|
46
|
+
)
|
|
47
|
+
from mada.core.config.utils import expand_env_vars
|
|
48
|
+
|
|
49
|
+
__all__ = [
|
|
50
|
+
"AgentConfig",
|
|
51
|
+
"AppConfig",
|
|
52
|
+
"BaseModelConfig",
|
|
53
|
+
"BedrockModelConfig",
|
|
54
|
+
"DatabaseConfig",
|
|
55
|
+
"InterfaceConfig",
|
|
56
|
+
"MCPServerConfig",
|
|
57
|
+
"ModelConfig",
|
|
58
|
+
"OpenAIModelConfig",
|
|
59
|
+
"PostgreSQLConfig",
|
|
60
|
+
"SQLiteConfig",
|
|
61
|
+
"expand_env_vars",
|
|
62
|
+
"load_config_from_json",
|
|
63
|
+
"load_database_config",
|
|
64
|
+
"load_model_config",
|
|
65
|
+
]
|