microsoft/autogen · error · InvalidOperationException
The content has more than one choice. Please try another inp
Error message
The content has more than one choice. Please try another input.
What it means
Thrown by AutoGen.OpenAI's OpenAIChatRequestMessageConnector when post-processing a chat completion whose Content collection contains more than one entry. The connector maps a single completion choice into exactly one AutoGen IMessage, so a multi-part/multi-choice response cannot be represented. It is a guard against model or request configurations that produce multiple content parts.
Source
Thrown at dotnet/src/AutoGen.OpenAI/Middleware/OpenAIChatRequestMessageConnector.cs:164
{
IMessage<ChatCompletion> m => PostProcessChatCompletions(m),
_ when strictMode is false => message,
_ => throw new InvalidOperationException($"Invalid return message type {message.GetType().Name}"),
};
}
private IMessage PostProcessChatCompletions(IMessage<ChatCompletion> message)
{
// throw exception if prompt filter results is not null
if (message.Content.FinishReason == ChatFinishReason.ContentFilter)
{
throw new InvalidOperationException("The content is filtered because its potential risk. Please try another input.");
}
// throw exception is there is more than on choice
if (message.Content.Content.Count > 1)
{
throw new InvalidOperationException("The content has more than one choice. Please try another input.");
}
return PostProcessChatResponseMessage(message.Content, message.From);
}
private IMessage PostProcessChatResponseMessage(ChatCompletion chatCompletion, string? from)
{
// throw exception if prompt filter results is not null
if (chatCompletion.FinishReason == ChatFinishReason.ContentFilter)
{
throw new InvalidOperationException("The content is filtered because its potential risk. Please try another input.");
}
// throw exception is there is more than on choice
if (chatCompletion.Content.Count > 1)
{
throw new InvalidOperationException("The content has more than one choice. Please try another input.");
}View on GitHub (pinned to 027ecf0a37)
Solutions
- Set ChatOptions.ChoiceCount = 1 (or omit it) on the agent's reply options so the service returns a single choice.
- Remove the OpenAIChatRequestMessageConnector middleware if you truly need raw multi-choice completions and process ChatCompletion yourself.
- If multiple content parts come from a vision model, ensure the response contains one text part; inspect message.Content.Content in a debug hook to see what the service actually returned.
- Catch InvalidOperationException around the agent call and retry with simplified input as a last resort.
Example fix
// before
var chatOptions = new ChatOptions { ChoiceCount = 3 };
await agent.SendAsync(chatMessages, chatOptions);
// after
var chatOptions = new ChatOptions { ChoiceCount = 1 };
await agent.SendAsync(chatMessages, chatOptions); Defensive patterns
Strategy: validation
Validate before calling
// Before invoking the agent, pin single-choice output
if (chatOptions.ChoiceCount is > 1)
{
throw new ArgumentOutOfRangeException(nameof(chatOptions), "AutoGen.OpenAI message connector requires ChoiceCount == 1.");
} Try / catch
try { var reply = await agent.SendAsync(msgs, chatOptions); }
catch (InvalidOperationException ex) when (ex.Message.Contains("more than one choice"))
{
logger.LogError(ex, "Multi-choice completion returned; set ChoiceCount=1");
throw;
} Prevention
- Default ChatOptions.ChoiceCount to 1 in agent factory code and assert it before every call.
- Wrap ChatOptions creation in one helper so multi-choice configs cannot leak into AutoGen agents.
- Add an integration test that round-trips one completion through the connector in CI.
When it happens
Trigger: Calling an OpenAI agent whose ChatOptions.ChoiceCount (n) is set greater than 1, or a model/endpoint that returns a ChatCompletion with multiple items in Content. Raised inside PostProcessChatCompletions when message.Content.Content.Count > 1.
Common situations: Developer copies ChatOptions from a sample that sets ChoiceCount = 3 for A/B testing; using a custom endpoint/proxy that always returns multiple choices; upgrading to an SDK version where Content became a collection of parts and refactoring sent several parts.
Related errors
- Invalid ChatResponseMessage
- Please set OPENAI_API_KEY environment variable.
- Please set OPENAI_API_KEY environment variable.
- Please set OPENAI_API_KEY environment variable.
- Please set OPENAI_API_KEY environment variable.
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/091903db63a46d6d.
Report an issue: GitHub.