{"record":{"id":"4ada7164e5c4fd2e","repo":"iflytek/astron-agent","slug":"unsupported-model-source-model-source","errorCode":null,"errorMessage":"Unsupported model source: {model_source}","messagePattern":"Unsupported model source: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/workflow/infra/providers/llm/chat_ai_factory.py","lineNumber":53,"sourceCode":"        Create and return a chat AI instance based on the specified model source.\n\n        :param model_source: The model provider identifier (e.g., 'xinghuo', 'openai')\n        :param kwargs: Additional keyword arguments to pass to the chat AI constructor\n        :return: An instance of the appropriate chat AI class\n        :raises ValueError: If the specified model source is not supported\n        \"\"\"\n\n        # Retrieve the chat AI class from the registry\n        if model_source == ModelProviderEnum.XINGHUO.value:\n            return SparkChatAi(**kwargs)\n        elif model_source == ModelProviderEnum.OPENAI.value:\n            return OpenAIChatAI(**kwargs)\n        elif model_source == ModelProviderEnum.ANTHROPIC.value:\n            return AnthropicChatAI(**kwargs)  # Use new implementation\n        elif model_source == ModelProviderEnum.GOOGLE.value:\n            return GoogleChatAI(**kwargs)  # Use new implementation\n        else:\n            raise ValueError(f\"Unsupported model source: {model_source}\")\n","sourceCodeStart":35,"sourceCodeEnd":54,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/infra/providers/llm/chat_ai_factory.py#L35-L54","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nmodel_source = config['model_source']  # e.g. 'OpenAI'\nllm = ChatAIFactory.get_chat_ai(model_source, **kwargs)\n// after\nmodel_source = str(config['model_source']).strip().lower()\nassert model_source in [e.value for e in ModelProviderEnum], f'unknown provider {model_source}'\nllm = ChatAIFactory.get_chat_ai(model_source, **kwargs)","handlingStrategy":"validation","validationCode":"VALID = {e.value for e in ModelProviderEnum}\ndef validate_model_source(src: str) -> str:\n    s = (src or '').strip().lower()\n    if s not in VALID:\n        raise ValueError(f'model_source must be one of {sorted(VALID)}, got {src!r}')\n    return s\n","typeGuard":null,"tryCatchPattern":"try:\n    llm = ChatAIFactory.get_chat_ai(model_source, **kwargs)\nexcept ValueError as e:\n    log.error('bad model_source: %s', e)\n    llm = ChatAIFactory.get_chat_ai(ModelProviderEnum.OPENAI.value, **kwargs)  # fallback default\n","preventionTips":["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"],"tags":["configuration","enum","factory","validation"],"backgroundTag":"unsupported-enum-value","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}