microsoft/autogen · error · ArgumentException
Unsupported config type {config.GetType()}
Error message
Unsupported config type {config.GetType()} What it means
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.
Source
Thrown at dotnet/src/AutoGen.OpenAI.V1/Agent/GPTAgent.cs:51
private readonly OpenAIClient openAIClient;
private readonly IStreamingAgent _innerAgent;
public GPTAgent(
string name,
string systemMessage,
ILLMConfig config,
float temperature = 0.7f,
int maxTokens = 1024,
int? seed = null,
ChatCompletionsResponseFormat? responseFormat = null,
IEnumerable<FunctionDefinition>? functions = null,
IDictionary<string, Func<string, Task<string>>>? functionMap = null)
{
openAIClient = config switch
{
AzureOpenAIConfig azureConfig => new OpenAIClient(new Uri(azureConfig.Endpoint), new Azure.AzureKeyCredential(azureConfig.ApiKey)),
OpenAIConfig openAIConfig => new OpenAIClient(openAIConfig.ApiKey),
_ => throw new ArgumentException($"Unsupported config type {config.GetType()}"),
};
var modelName = config switch
{
AzureOpenAIConfig azureConfig => azureConfig.DeploymentName,
OpenAIConfig openAIConfig => openAIConfig.ModelId,
_ => throw new ArgumentException($"Unsupported config type {config.GetType()}"),
};
_innerAgent = new OpenAIChatAgent(openAIClient, name, modelName, systemMessage, temperature, maxTokens, seed, responseFormat, functions)
.RegisterMessageConnector();
if (functionMap is not null)
{
var functionMapMiddleware = new FunctionCallMiddleware(functionMap: functionMap);
_innerAgent = _innerAgent.RegisterStreamingMiddleware(functionMapMiddleware);
}
View on GitHub (pinned to 027ecf0a37)
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
Example fix
// before
ILLMConfig cfg = LoadConfigFromSomewhere();
var agent = new GPTAgent("gpt", "sys", cfg);
// after
var cfg = new OpenAIConfig { ApiKey = apiKey, ModelId = "gpt-4o-mini" };
var agent = new GPTAgent("gpt", "sys", cfg); Defensive patterns
Strategy: type-guard
Type guard
static bool IsSupportedConfig(ILLMConfig config) =>
config is OpenAIConfig or AzureOpenAIConfig; Try / catch
try { var agent = new GPTAgent(name, sys, config); }
catch (ArgumentException ex) when (ex.Message.Contains("Unsupported config type"))
{
throw new ConfigurationErrorsException($"Bad LLM config: {config.GetType().Name}", ex);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Messages should not be provided in options
- Timeout must be greater than or equal to 1.
- Required create args are missing: {required_create_args - cr
- model is required for OpenAIChatCompletionClient
- Please set OPENAI_API_KEY environment variable.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/7b8f8a4cdb5121c5.
Report an issue: GitHub.