{"record":{"id":"7b8f8a4cdb5121c5","repo":"microsoft/autogen","slug":"unsupported-config-type-config-gettype","errorCode":null,"errorMessage":"Unsupported config type {config.GetType()}","messagePattern":"Unsupported config type (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/AutoGen.OpenAI.V1/Agent/GPTAgent.cs","lineNumber":51,"sourceCode":"    private readonly OpenAIClient openAIClient;\n    private readonly IStreamingAgent _innerAgent;\n\n    public GPTAgent(\n        string name,\n        string systemMessage,\n        ILLMConfig config,\n        float temperature = 0.7f,\n        int maxTokens = 1024,\n        int? seed = null,\n        ChatCompletionsResponseFormat? responseFormat = null,\n        IEnumerable<FunctionDefinition>? functions = null,\n        IDictionary<string, Func<string, Task<string>>>? functionMap = null)\n    {\n        openAIClient = config switch\n        {\n            AzureOpenAIConfig azureConfig => new OpenAIClient(new Uri(azureConfig.Endpoint), new Azure.AzureKeyCredential(azureConfig.ApiKey)),\n            OpenAIConfig openAIConfig => new OpenAIClient(openAIConfig.ApiKey),\n            _ => throw new ArgumentException($\"Unsupported config type {config.GetType()}\"),\n        };\n\n        var modelName = config switch\n        {\n            AzureOpenAIConfig azureConfig => azureConfig.DeploymentName,\n            OpenAIConfig openAIConfig => openAIConfig.ModelId,\n            _ => throw new ArgumentException($\"Unsupported config type {config.GetType()}\"),\n        };\n\n        _innerAgent = new OpenAIChatAgent(openAIClient, name, modelName, systemMessage, temperature, maxTokens, seed, responseFormat, functions)\n            .RegisterMessageConnector();\n\n        if (functionMap is not null)\n        {\n            var functionMapMiddleware = new FunctionCallMiddleware(functionMap: functionMap);\n            _innerAgent = _innerAgent.RegisterStreamingMiddleware(functionMapMiddleware);\n        }\n","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/dotnet/src/AutoGen.OpenAI.V1/Agent/GPTAgent.cs#L33-L69","documentation":"Thrown by the GPTAgent constructor when the supplied ILLMConfig is neither AzureOpenAIConfig nor OpenAIConfig. The first switch in the constructor builds an OpenAIClient and only knows how to materialize a client from those two concrete config types.","triggerScenarios":"Calling new GPTAgent(name, systemMessage, config) with a custom ILLMConfig implementation, a config from another provider package (e.g. GeminiConfig), or a partially-initialized config object.","commonSituations":"Mixing config classes across AutoGen provider packages; deserializing config from JSON into a generic ILLMConfig variable; upgrading AutoGen where config type names moved between namespaces.","solutions":["Pass an OpenAIConfig (ApiKey + ModelId) for openai.com endpoints","Pass an AzureOpenAIConfig (Endpoint + ApiKey + DeploymentName) for Azure OpenAI","If you have a custom config type, construct OpenAIChatAgent directly with an OpenAIClient instead of going through GPTAgent"],"exampleFix":"// before\nILLMConfig cfg = LoadConfigFromSomewhere();\nvar agent = new GPTAgent(\"gpt\", \"sys\", cfg);\n\n// after\nvar cfg = new OpenAIConfig { ApiKey = apiKey, ModelId = \"gpt-4o-mini\" };\nvar agent = new GPTAgent(\"gpt\", \"sys\", cfg);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"static bool IsSupportedConfig(ILLMConfig config) =>\n    config is OpenAIConfig or AzureOpenAIConfig;","tryCatchPattern":"try { var agent = new GPTAgent(name, sys, config); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Unsupported config type\"))\n{\n    throw new ConfigurationErrorsException($\"Bad LLM config: {config.GetType().Name}\", ex);\n}","preventionTips":["Construct OpenAIConfig/AzureOpenAIConfig at startup and fail fast","Do not accept arbitrary ILLMConfig from untyped sources","Add a startup smoke test that instantiates each agent"],"tags":["openai","configuration","constructor","validation"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}