Application configuration definitions and loading utilities.
This module defines the top-level configuration model for the MADA
multi-agent application. It provides AppConfig, which aggregates model,
agent, database, MCP server, and interface configuration objects, along with
load_config_from_json for loading a complete application configuration from
a JSON file.
AppConfig
dataclass
Top-level configuration for the MADA multi-agent application.
This configuration aggregates model settings, interface layout
settings, and agent definitions. It can be loaded from a JSON file
using the from_dict method.
Attributes:
| Name |
Type |
Description |
model |
ModelConfig
|
Provider-specific configuration for the model backend.
|
agents |
List[AgentConfig]
|
List of agent definitions including server paths and descriptions.
|
database |
DatabaseConfig
|
Configuration for the database connection.
|
interface |
InterfaceConfig
|
Configuration for the Gradio interface layout and options.
|
Source code in src/mada/core/config/app.py
| @dataclass
class AppConfig:
"""
Top-level configuration for the MADA multi-agent application.
This configuration aggregates model settings, interface layout
settings, and agent definitions. It can be loaded from a JSON file
using the `from_dict` method.
Attributes:
model (ModelConfig): Provider-specific configuration for the model backend.
agents (List[AgentConfig]): List of agent definitions including server paths and descriptions.
database (DatabaseConfig): Configuration for the database connection.
interface (InterfaceConfig): Configuration for the Gradio interface layout and options.
"""
model: ModelConfig
agents: List[AgentConfig]
database: DatabaseConfig
mcp_servers: Dict[str, MCPServerConfig] = None # MCP server configurations
interface: InterfaceConfig = None # Optional, used only by the Gradio app
@classmethod
def from_dict(cls, config_dict: Dict[str, Any]) -> "AppConfig":
"""
Create an AppConfig instance from a dictionary.
This method extracts and constructs the model, interface, and
agent configurations from a flat configuration dictionary.
Args:
config_dict (Dict[str, Any]): Dictionary containing keys 'model', 'interface', and 'agents'.
Returns:
AppConfig: The fully populated application configuration.
Raises:
ValueError: If the 'agents' list is missing or empty.
"""
app_conf = {}
# Load model configuration
model_settings = config_dict.get("model")
if not model_settings:
raise ValueError(
"Please provide 'model' settings in the configuration for your app."
)
model_cfg = load_model_config(model_settings)
app_conf["model"] = model_cfg
# Load agents
agent_entries = config_dict.get("agents")
if not agent_entries:
raise ValueError(
"No agents were provided. Please define at least one agent."
)
agent_cfgs = [AgentConfig.from_dict(agent) for agent in agent_entries]
app_conf["agents"] = agent_cfgs
# Load database
database_config = config_dict.get("database", {})
app_conf["database"] = load_database_config(database_config)
# Load MCP servers configuration (optional)
python_exe = config_dict.get("python_executable", sys.executable)
mcp_servers_entry = config_dict.get("mcp_servers")
if mcp_servers_entry:
mcp_servers_cfg = {}
for name, server_config in mcp_servers_entry.items():
if "python_executable" not in server_config:
server_config = {**server_config, "python_executable": python_exe}
mcp_servers_cfg[name] = MCPServerConfig(**server_config)
app_conf["mcp_servers"] = mcp_servers_cfg
# Load interface configuration (optional for multiagent app)
interface_entry = config_dict.get("interface")
if interface_entry:
interface_cfg = InterfaceConfig(**config_dict["interface"])
app_conf["interface"] = interface_cfg
return cls(**app_conf)
|
from_dict(config_dict)
classmethod
Create an AppConfig instance from a dictionary.
This method extracts and constructs the model, interface, and
agent configurations from a flat configuration dictionary.
Parameters:
| Name |
Type |
Description |
Default |
config_dict
|
Dict[str, Any]
|
Dictionary containing keys 'model', 'interface', and 'agents'.
|
required
|
Returns:
| Name | Type |
Description |
AppConfig |
AppConfig
|
The fully populated application configuration.
|
Raises:
| Type |
Description |
ValueError
|
If the 'agents' list is missing or empty.
|
Source code in src/mada/core/config/app.py
| @classmethod
def from_dict(cls, config_dict: Dict[str, Any]) -> "AppConfig":
"""
Create an AppConfig instance from a dictionary.
This method extracts and constructs the model, interface, and
agent configurations from a flat configuration dictionary.
Args:
config_dict (Dict[str, Any]): Dictionary containing keys 'model', 'interface', and 'agents'.
Returns:
AppConfig: The fully populated application configuration.
Raises:
ValueError: If the 'agents' list is missing or empty.
"""
app_conf = {}
# Load model configuration
model_settings = config_dict.get("model")
if not model_settings:
raise ValueError(
"Please provide 'model' settings in the configuration for your app."
)
model_cfg = load_model_config(model_settings)
app_conf["model"] = model_cfg
# Load agents
agent_entries = config_dict.get("agents")
if not agent_entries:
raise ValueError(
"No agents were provided. Please define at least one agent."
)
agent_cfgs = [AgentConfig.from_dict(agent) for agent in agent_entries]
app_conf["agents"] = agent_cfgs
# Load database
database_config = config_dict.get("database", {})
app_conf["database"] = load_database_config(database_config)
# Load MCP servers configuration (optional)
python_exe = config_dict.get("python_executable", sys.executable)
mcp_servers_entry = config_dict.get("mcp_servers")
if mcp_servers_entry:
mcp_servers_cfg = {}
for name, server_config in mcp_servers_entry.items():
if "python_executable" not in server_config:
server_config = {**server_config, "python_executable": python_exe}
mcp_servers_cfg[name] = MCPServerConfig(**server_config)
app_conf["mcp_servers"] = mcp_servers_cfg
# Load interface configuration (optional for multiagent app)
interface_entry = config_dict.get("interface")
if interface_entry:
interface_cfg = InterfaceConfig(**config_dict["interface"])
app_conf["interface"] = interface_cfg
return cls(**app_conf)
|
load_config_from_json(path)
Load application configuration from a JSON file.
Parameters:
| Name |
Type |
Description |
Default |
path
|
str
|
Path to the JSON configuration file.
|
required
|
Returns:
| Name | Type |
Description |
AppConfig |
AppConfig
|
The parsed application configuration object.
|
Source code in src/mada/core/config/app.py
| def load_config_from_json(path: str) -> AppConfig:
"""
Load application configuration from a JSON file.
Args:
path (str): Path to the JSON configuration file.
Returns:
AppConfig: The parsed application configuration object.
"""
with open(path, "r") as f:
config_dict = json.load(f)
return AppConfig.from_dict(config_dict)
|