Python: fix FoundryChatClient/FoundryAgent dropping default_headers#5433
Open
he-yufeng wants to merge 1 commit intomicrosoft:mainfrom
Open
Python: fix FoundryChatClient/FoundryAgent dropping default_headers#5433he-yufeng wants to merge 1 commit intomicrosoft:mainfrom
he-yufeng wants to merge 1 commit intomicrosoft:mainfrom
Conversation
default_headers was accepted by the constructor and stored on the instance but never forwarded to the AsyncOpenAI client obtained from AIProjectClient.get_openai_client(), so custom headers never reached outbound requests. Forward default_headers through get_openai_client(**kwargs) -- the Azure SDK already supports this kwarg and passes it on to AsyncOpenAI. Added two regression tests and updated the mock-based header test so we cover both the stored-attribute path and the actually-forwarded path. Fixes microsoft#5416.
|
@he-yufeng please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
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
Fixes #5416.
FoundryChatClient(default_headers=...)andFoundryAgent(default_headers=...)are documented to set additional HTTP headers on outbound requests. The constructor accepted the parameter, stored it onself.default_headers, and then forgot about it — the underlyingAsyncOpenAIclient was obtained viaproject_client.get_openai_client()without forwarding the headers, so custom headers never reached the wire.This is a silent failure: the parameter looks wired up, existing unit test (
test_init_with_default_header) even asserts the stored attribute is populated, but the reporter still spent hours tracking down why their header wasn't appearing in requests.Description
AIProjectClient.get_openai_client(**kwargs)already forwardsdefault_headers(and friends) toAsyncOpenAI, so the fix is just to pass them through from the two Foundry entry points:agent_framework_foundry/_chat_client.py(RawFoundryChatClient.__init__)agent_framework_foundry/_agent.py(FoundryAgent.__init__)I deliberately didn't touch
load_openai_service_settingsin the sharedopenaipackage — while that is where the headers are dropped for the pre-built-client path, the reported bug is Foundry-specific and going throughget_openai_clientis the Azure-native way. The existingself.default_headersstorage on the instance is kept intact for serialization/reflection.Tests
test_default_headers_forwarded_to_openai_client— regression test: asserts the headers actually land on theget_openai_clientcall.test_get_openai_client_not_called_with_headers_kwarg_when_unset— don't inject an empty dict when the user didn't ask for headers.test_init_with_default_headerstill passes (storage attribute behavior unchanged).Full foundry test suite:
102 passed, 14 skipped(skips are the integration tests needing a real endpoint).Contribution Checklist