iflytek/astron-agent · error · ValueError
Unknown strategy
Error message
Unknown strategy: {strategy} What it means
ConfigLoader.create raises ValueError when the configured strategy string matches neither EnvStrategy.Local nor EnvStrategy.Polaris. It is the factory guard for the configuration-management loader selection, failing fast at startup before any config is loaded.
Solutions
- Set the strategy config to one of the exact EnvStrategy values ('local' or 'polaris')
- Strip/normalize the strategy string (lower(), .strip()) before calling create
- Print EnvStrategy values or check the enum definition to confirm accepted values
- Add the missing loader branch in configs/__init__.py if a new backend is genuinely required
Example fix
// before
loader = ConfigLoader.create(os.getenv("CONFIG_STRATEGY"))
// after
strategy = (os.getenv("CONFIG_STRATEGY") or "local").strip().lower()
loader = ConfigLoader.create(strategy) Defensive patterns
Strategy: validation
Validate before calling
from workflow.configs import EnvStrategy, ConfigLoader
strategy = (raw or "").strip().lower()
if strategy not in (s.value for s in EnvStrategy):
raise ValueError(f"strategy must be one of {[s.value for s in EnvStrategy]}") Try / catch
try:
loader = ConfigLoader.create(strategy)
except ValueError as e:
logger.error("config loader strategy invalid: %s", e)
raise SystemExit(2) Prevention
- Keep strategy values sourced from EnvStrategy enum, never free strings
- Normalize case/whitespace on env-derived strategy values
- Document accepted values next to the deployment config template
- Fail fast at startup with the list of valid strategies
When it happens
Trigger: Calling ConfigLoader.create(strategy) with a string other than 'local' or 'polaris' (exact value match against EnvStrategy enum); typo in the strategy config value; strategy env var set with wrong casing or whitespace.
Common situations: Deployment sets CONFIG_STRATEGY=polaris-hr or 'Polaris' (capitalized) instead of the enum's exact value; copy-pasted config from another service with a different strategy name; new loader added to docs but not implemented.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- KAFKA_SERVERS environment variable is not configured…
- Unsupported protocol
- Unsupported model source
- server port is required
- WORKFLOW_INTERNAL_API_KEY must contain a non-default value…
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/9f2865cb6f7c5b6b.
Report an issue: GitHub.
Appendix: source
Thrown at core/workflow/configs/__init__.py:205
class EnvLoaderFactory:
"""
Factory class to create EnvLoader instances based on strategy.
"""
@staticmethod
def create(strategy: str) -> "EnvLoader":
"""
Create an EnvLoader instance based on the given strategy.
:param strategy: The environment loading strategy (e.g., 'local', 'polaris')
:return: An instance of EnvLoader
"""
if strategy == EnvStrategy.Local.value:
logger.info("🔍 Using Local file for configuration management.")
return LocalLoader()
if strategy == EnvStrategy.Polaris.value:
logger.info("🔍 Using Polaris for configuration management.")
return PolarisLoader()
raise ValueError(f"Unknown strategy: {strategy}")
def set_env() -> None:
"""
Set environment variables by loading configuration from environment files.
This function determines the appropriate configuration file based on the
runtime environment (local vs production) and loads the environment
variables from the corresponding .env file.
:raises ValueError: If no configuration file is found
:raises Exception: Re-raises any other exceptions that occur during loading
"""
strategy = os.getenv("CONFIG_TYPE", EnvStrategy.Local.value)
loader = EnvLoaderFactory.create(strategy)
loader.load()
View on GitHub (pinned to 5e758547a8)