Skip to content

Python: Fix AzureAIClient failure when conversation history contains assistant messages - #3076

Merged
Evan Mattson (moonbox3) merged 5 commits into
microsoft:mainfrom
moonbox3:2926-fix
Jan 5, 2026
Merged

Evan Mattson (moonbox3) merged 5 commits into
microsoft:mainfrom
moonbox3:2926-fix

Conversation

@moonbox3

Copy link
Copy Markdown
Contributor

Motivation and Context

AzureAIClient fails with 400 invalid_payload errors when sending requests that include prior assistant messages in the conversation history. This affects any multi-turn conversation scenario, including sequential workflows.

The issue is related to a schema divergence between OpenAI's Responses API and Azure AI Projects' "create responses" API:

  • Azure requires type: "message" at the input item level
  • Azure requires annotations field on output_text content items
  • Azure does NOT accept annotations on input_text content items

A tracked upstream Azure SDK issue: Azure/azure-sdk-for-python#44493

To unblock: added _transform_input_for_azure_ai() workaround in AzureAIClient that transforms input payloads to match Azure's expected schema before sending requests. The workaround is clearly marked with TODO comments linking to both issues for easy removal once Azure SDK aligns with OpenAI.

Description

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.

@moonbox3 Evan Mattson (moonbox3) added the agents Usage: [Issues, PRs], Target: Single agent label Jan 5, 2026
Copilot AI review requested due to automatic review settings January 5, 2026 01:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical bug in AzureAIClient that caused 400 invalid_payload errors when handling multi-turn conversations with assistant messages in the conversation history. The issue stems from schema divergence between OpenAI's Responses API and Azure AI Projects' "create responses" API.

Key Changes

  • Added _transform_input_for_azure_ai() workaround method to transform input payloads to match Azure's schema requirements
  • Integrated the transformation into _prepare_options() to apply it before sending requests to Azure
  • Added 3 unit tests to verify the transformation logic handles various scenarios correctly

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
python/packages/azure-ai/agent_framework_azure_ai/_client.py Added _transform_input_for_azure_ai() method to transform input items by adding required type: "message" field at item level and annotations field to output_text content items; integrated transformation into _prepare_options() method
python/packages/azure-ai/tests/test_azure_ai_client.py Added 3 unit tests covering basic transformation, preservation of existing fields, and handling of non-dict content items

@moonbox3

Copy link
Copy Markdown
Contributor Author

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
packages/azure-ai/agent_framework_azure_ai
   _client.py1853978%221–224, 229, 232–235, 240, 243–244, 247, 254, 293, 295–298, 300, 389, 446, 482–485, 490, 492–493, 495–503, 505
TOTAL16869262584% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
2566 149 💤 0 ❌ 0 🔥 1m 0s ⏱️