iflytek/astron-agent · error · ValueError
Unsupported model source
Error message
Unsupported model source: {model_source} What it means
ChatAIFactory.get_chat_ai dispatches on the model_source string against ModelProviderEnum values (OPENAI, ANTHROPIC, GOOGLE, ...). If model_source does not match any known provider, it raises a plain ValueError 'Unsupported model source: {model_source}'. This is a configuration/enum-validation guard so unknown providers fail fast instead of producing a None client.
Solutions
- Check the model_source value configured for the agent and correct it to an exact ModelProviderEnum value (openai/anthropic/google as defined in the enum).
- Trim and lower-case/normalize the stored model_source before calling the factory.
- If a new provider is intended, add an elif branch in get_chat_ai mapping it to its ChatAI implementation.
- Add a startup-time validation that rejects unknown model_source values with a clear message.
Example fix
// before
model_source = config['model_source'] # e.g. 'OpenAI'
llm = ChatAIFactory.get_chat_ai(model_source, **kwargs)
// after
model_source = str(config['model_source']).strip().lower()
assert model_source in [e.value for e in ModelProviderEnum], f'unknown provider {model_source}'
llm = ChatAIFactory.get_chat_ai(model_source, **kwargs) Defensive patterns
Strategy: validation
Validate before calling
VALID = {e.value for e in ModelProviderEnum}
def validate_model_source(src: str) -> str:
s = (src or '').strip().lower()
if s not in VALID:
raise ValueError(f'model_source must be one of {sorted(VALID)}, got {src!r}')
return s
Try / catch
try:
llm = ChatAIFactory.get_chat_ai(model_source, **kwargs)
except ValueError as e:
log.error('bad model_source: %s', e)
llm = ChatAIFactory.get_chat_ai(ModelProviderEnum.OPENAI.value, **kwargs) # fallback default
Prevention
- Always build model_source from ModelProviderEnum values, never raw strings
- Normalize (trim/lowercase) config values at load time
- Add a unit test enumerating every ModelProviderEnum member against the factory
- Fail fast at startup, not at request time
When it happens
Trigger: get_chat_ai receives a model_source string that is not one of the ModelProviderEnum values — e.g. a typo like 'anthropicc', an uppercase/untrimmed value like 'Anthropic ', or a newly added provider not yet handled by the factory's if/elif chain.
Common situations: Misconfigured agent model settings in the database/console, hand-written config with wrong casing or whitespace, or a contributor adding a new ModelProviderEnum member without adding a branch in chat_ai_factory.
Related errors
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/4ada7164e5c4fd2e.
Report an issue: GitHub.
Appendix: source
Thrown at core/workflow/infra/providers/llm/chat_ai_factory.py:53
Create and return a chat AI instance based on the specified model source.
:param model_source: The model provider identifier (e.g., 'xinghuo', 'openai')
:param kwargs: Additional keyword arguments to pass to the chat AI constructor
:return: An instance of the appropriate chat AI class
:raises ValueError: If the specified model source is not supported
"""
# Retrieve the chat AI class from the registry
if model_source == ModelProviderEnum.XINGHUO.value:
return SparkChatAi(**kwargs)
elif model_source == ModelProviderEnum.OPENAI.value:
return OpenAIChatAI(**kwargs)
elif model_source == ModelProviderEnum.ANTHROPIC.value:
return AnthropicChatAI(**kwargs) # Use new implementation
elif model_source == ModelProviderEnum.GOOGLE.value:
return GoogleChatAI(**kwargs) # Use new implementation
else:
raise ValueError(f"Unsupported model source: {model_source}")
View on GitHub (pinned to 5e758547a8)