Skip to content

Python: Exclude conversation_id from chat completions API options#4517

Open
moonbox3 wants to merge 4 commits intomicrosoft:mainfrom
moonbox3:agent/fix-4315-1
Open

Python: Exclude conversation_id from chat completions API options#4517
moonbox3 wants to merge 4 commits intomicrosoft:mainfrom
moonbox3:agent/fix-4315-1

Conversation

@moonbox3
Copy link
Contributor

@moonbox3 moonbox3 commented Mar 6, 2026

Motivation and Context

When using Azure OpenAI agents with a session that has a service_session_id, the conversation_id field leaks through to the AsyncCompletions.create() call, causing an API error because conversation_id is not a valid parameter for the chat completions endpoint.

Fixes #4315

Description

The OpenAIResponsesClient correctly excluded conversation_id from its API call options, but RawOpenAIChatClient._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 to AsyncCompletions.create(). Tests are added for both Azure and OpenAI chat clients covering non-streaming, streaming, and agent-with-session paths.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Note: PR autogenerated by moonbox3's agent

moonbox3 and others added 3 commits March 6, 2026 12:37
…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 moonbox3 self-assigned this Mar 6, 2026
Copilot AI review requested due to automatic review settings March 6, 2026 03:41
Copy link
Contributor Author

@moonbox3 moonbox3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated Code Review

Reviewers: 4 | Confidence: 95% | Result: All clear

Reviewed: Correctness, Security Reliability, Test Coverage, Design Approach


Automated review by moonbox3's agents

@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Mar 6, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/core/agent_framework/openai
   _chat_client.py3072791%210, 240–241, 245, 370, 377, 453–460, 462–465, 475, 553, 555, 572, 610, 623, 647, 663, 703
TOTAL22676281187% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
4708 20 💤 0 ❌ 0 🔥 1m 18s ⏱️

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id out of RawOpenAIChatClient._prepare_options() so it is never passed to chat.completions.create().
  • Add unit tests for OpenAI and Azure chat clients to ensure conversation_id is 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Azure open ai agent session error

3 participants