Main configuration class
| 64 | |
| 65 | |
| 66 | class Config(BaseModel): |
| 67 | """Main configuration class""" |
| 68 | |
| 69 | llm: LLMConfig |
| 70 | agent: AgentConfig |
| 71 | tools: ToolsConfig |
| 72 | |
| 73 | @classmethod |
| 74 | def load(cls) -> "Config": |
| 75 | """Load configuration from the default search path.""" |
| 76 | config_path = cls.get_default_config_path() |
| 77 | if not config_path.exists(): |
| 78 | raise FileNotFoundError("Configuration file not found. Run scripts/setup-config.sh or place config.yaml in mini_agent/config/.") |
| 79 | return cls.from_yaml(config_path) |
| 80 | |
| 81 | @classmethod |
| 82 | def from_yaml(cls, config_path: str | Path) -> "Config": |
| 83 | """Load configuration from YAML file |
| 84 | |
| 85 | Args: |
| 86 | config_path: Configuration file path |
| 87 | |
| 88 | Returns: |
| 89 | Config instance |
| 90 | |
| 91 | Raises: |
| 92 | FileNotFoundError: Configuration file does not exist |
| 93 | ValueError: Invalid configuration format or missing required fields |
| 94 | """ |
| 95 | config_path = Path(config_path) |
| 96 | |
| 97 | if not config_path.exists(): |
| 98 | raise FileNotFoundError(f"Configuration file does not exist: {config_path}") |
| 99 | |
| 100 | with open(config_path, encoding="utf-8") as f: |
| 101 | data = yaml.safe_load(f) |
| 102 | |
| 103 | if not data: |
| 104 | raise ValueError("Configuration file is empty") |
| 105 | |
| 106 | # Parse LLM configuration |
| 107 | if "api_key" not in data: |
| 108 | raise ValueError("Configuration file missing required field: api_key") |
| 109 | |
| 110 | if not data["api_key"] or data["api_key"] == "YOUR_API_KEY_HERE": |
| 111 | raise ValueError("Please configure a valid API Key") |
| 112 | |
| 113 | # Parse retry configuration |
| 114 | retry_data = data.get("retry", {}) |
| 115 | retry_config = RetryConfig( |
| 116 | enabled=retry_data.get("enabled", True), |
| 117 | max_retries=retry_data.get("max_retries", 3), |
| 118 | initial_delay=retry_data.get("initial_delay", 1.0), |
| 119 | max_delay=retry_data.get("max_delay", 60.0), |
| 120 | exponential_base=retry_data.get("exponential_base", 2.0), |
| 121 | ) |
| 122 | |
| 123 | llm_config = LLMConfig( |