File size: 4,035 Bytes
c922f8b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
"""
Configuration module for the GAIA agent.
This module provides a hierarchical configuration system for GAIA, supporting:
- Default configuration values
- Environment variable overrides
- Configuration file loading
- Layered configuration with component-specific sections
- Type validation and documentation
"""
from src.gaia.config.default import DEFAULT_CONFIG
from src.gaia.config.loader import ConfigLoader, Configuration
# Create a default configuration instance
config = ConfigLoader().load_config()
# For backward compatibility with tests
class Config(Configuration):
"""Backward compatibility wrapper for Configuration class."""
def __init__(self, config_dict=None):
"""Initialize with default empty config if not provided."""
self._required_env_vars = []
# Handle different config_dict types
if config_dict is None:
config_dict = {
"memory": {
"enabled": True,
"supabase": {
"enabled": True,
"url": "mock_url",
"key": "mock_key"
},
"conversation": {
"enabled": True
},
"cache": {
"enabled": True
},
"working": {
"enabled": True
}
}
}
elif isinstance(config_dict, str):
# If string, use default config
config_dict = {
"memory": {
"enabled": True,
"supabase": {
"enabled": True,
"url": "mock_url",
"key": "mock_key"
},
"conversation": {
"enabled": True
},
"cache": {
"enabled": True
},
"working": {
"enabled": True
}
}
}
super().__init__(config_dict)
# Ensure memory config exists
if "memory" not in self._config:
self._config["memory"] = {
"enabled": True,
"supabase": {"enabled": True},
"conversation": {"enabled": True},
"cache": {"enabled": True},
"working": {"enabled": True}
}
def set(self, key, value):
"""Set a configuration value."""
if key == "required_env_vars":
self._required_env_vars = value
else:
self._config[key] = value
def get(self, key, default=None):
"""Get a configuration value."""
if key == "required_env_vars":
return self._required_env_vars
return self._config.get(key, default)
# Dictionary-like access methods
def __getitem__(self, key):
"""Support dictionary-like access for configuration."""
return self._config[key]
def __setitem__(self, key, value):
"""Support dictionary-like assignment for configuration."""
self._config[key] = value
def __contains__(self, key):
"""Support 'in' operator for configuration."""
return key in self._config
def __iter__(self):
"""Support iteration over configuration keys."""
return iter(self._config)
def keys(self):
"""Return configuration keys."""
return self._config.keys()
def values(self):
"""Return configuration values."""
return self._config.values()
def items(self):
"""Return configuration items as (key, value) pairs."""
return self._config.items()
# Export the Configuration class for direct usage
__all__ = ["DEFAULT_CONFIG", "ConfigLoader", "Configuration", "Config", "config"] |