Add include_name_in_message parameter to make name field optional in OpenAI messages
#6845
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Many OpenAI-compatible model providers (like Groq, Together AI, etc.) don't support the
namefield in chat completion messages, causing API errors when using AutoGen with these providers.This PR adds an
include_name_in_messageparameter toBaseOpenAIChatCompletionClientthat controls whether thenamefield is included in message parameters sent to the API.Changes
include_name_in_message: boolparameter toBaseOpenAIClientConfigurationand related Pydantic modelsBaseOpenAIChatCompletionClient,OpenAIChatCompletionClient, andAzureOpenAIChatCompletionClientconstructors to handle the new parameter_set_name()function to conditionally include the name field based on contextto_oai_type()andcount_tokens_openai()functions to pass the parameter through the transformation pipelineUsage
Standard OpenAI (default behavior)
Groq (disable name field)
Alternative: Use name prefixes instead
Message Transformation
With name field (
include_name_in_message=True):{ "role": "user", "content": "Hello there!", "name": "User123" }Without name field (
include_name_in_message=False):{ "role": "user", "content": "Hello there!" }Backward Compatibility
This change is fully backward compatible:
include_name_in_messagedefaults toTrueFalseThe implementation follows existing patterns (similar to how Mistral models already exclude the name field) and provides consistent control across all model types.
Fixes #6034.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.