Python: Exclude conversation_id from chat completions API options#4517
Open
moonbox3 wants to merge 4 commits intomicrosoft:mainfrom
Open
Python: Exclude conversation_id from chat completions API options#4517moonbox3 wants to merge 4 commits intomicrosoft:mainfrom
moonbox3 wants to merge 4 commits intomicrosoft:mainfrom
Conversation
…oft#4315) When a session with service_session_id is passed to an agent using the Chat Completions client, conversation_id leaked through _prepare_options() into AsyncCompletions.create(), causing an 'unexpected keyword argument' error. The Responses client already excluded conversation_id but the Chat Completions client did not. Added conversation_id to the exclusion set in _prepare_options(). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
moonbox3
commented
Mar 6, 2026
Contributor
Author
moonbox3
left a comment
There was a problem hiding this comment.
Automated Code Review
Reviewers: 4 | Confidence: 95% | Result: All clear
Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach
Automated review by moonbox3's agents
Member
Python Test Coverage Report •
Python Unit Test Overview
|
||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a Python bug where conversation_id (propagated from agent sessions) was being forwarded into the OpenAI/Azure Chat Completions API call options, triggering AsyncCompletions.create() unexpected keyword argument errors.
Changes:
- Filter
conversation_idout ofRawOpenAIChatClient._prepare_options()so it is never passed tochat.completions.create(). - Add unit tests for OpenAI and Azure chat clients to ensure
conversation_idis excluded (including agent-with-session and streaming paths for Azure). - Apply minor formatting/import-order cleanup in several workflow test files.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| python/packages/core/agent_framework/openai/_chat_client.py | Excludes conversation_id from prepared Chat Completions options to prevent invalid SDK kwargs. |
| python/packages/core/tests/openai/test_openai_chat_client.py | Adds unit test asserting _prepare_options() drops conversation_id. |
| python/packages/core/tests/azure/test_azure_chat_client.py | Adds unit tests asserting conversation_id is not passed to AsyncChatCompletions.create() (non-streaming, streaming, agent session). |
| python/packages/core/tests/workflow/test_workflow_states.py | Formatting-only change to list comprehension for readability/line length. |
| python/packages/core/tests/workflow/test_workflow_kwargs.py | Formatting-only changes to overload signatures. |
| python/packages/core/tests/workflow/test_workflow_agent.py | Formatting-only changes to overload signatures. |
| python/packages/core/tests/workflow/test_executor.py | Fixes import placement for Never (typing_extensions). |
| python/packages/core/tests/workflow/test_edge.py | Normalizes import grouping/order. |
| python/packages/core/tests/workflow/test_agent_utils.py | Formatting-only changes to overload signatures. |
| python/packages/core/tests/workflow/test_agent_executor.py | Minor import-spacing formatting change. |
You can also share your feedback on Copilot code review. Take the survey.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Motivation and Context
When using Azure OpenAI agents with a session that has a
service_session_id, theconversation_idfield leaks through to theAsyncCompletions.create()call, causing an API error becauseconversation_idis not a valid parameter for the chat completions endpoint.Fixes #4315
Description
The
OpenAIResponsesClientcorrectly excludedconversation_idfrom its API call options, butRawOpenAIChatClient._prepare_options()did not filter it out. This fix adds"conversation_id"to the exclusion set in the options dict comprehension so it is no longer passed toAsyncCompletions.create(). Tests are added for both Azure and OpenAI chat clients covering non-streaming, streaming, and agent-with-session paths.Contribution Checklist