Skip to content

Python: preserve shared extension data when overriding prompt settings - #14854

Open
Twiink wants to merge 1 commit into
microsoft:mainfrom
Twiink:fix/settings-input-copy-20261122
Open

Twiink wants to merge 1 commit into
microsoft:mainfrom
Twiink:fix/settings-input-copy-20261122

Conversation

@Twiink

@Twiink Twiink commented Nov 22, 2026

Copy link
Copy Markdown

Motivation and Context

Reusing a configuration dictionary across agents can silently change a later agent's generation parameters:

base = {"temperature": 0.2}
first = OpenAIChatPromptExecutionSettings(extension_data=base, temperature=0.8)
second = OpenAIChatPromptExecutionSettings(extension_data=base)
# Before: both prepare_settings_dict() results contain temperature=0.8.
# After: first contains 0.8 and second retains the configured 0.2.

Description

Copy extension_data before merging keyword overrides. This preserves the caller's mapping and keeps the existing per-instance override precedence. The regression checks the public provider settings dictionaries for both instances.

Related #14752 addresses a different mapping in FunctionChoiceBehavior.from_dict; its diff does not cover PromptExecutionSettings.__init__ merging extension data.

Contribution Checklist

  • Regression fails on unchanged main and passes with the fix.
  • Prompt settings, OpenAI connector, and chat completion agent unit tests passed locally.
  • Ruff check, Ruff format, and git diff --check passed on the changed files.
  • Existing API and wire parameter shapes are preserved.

Validation used Python 3.13.16 and the current source checkout. Provider calls in the existing unit suite use its transport fixtures; no paid model requests were made.

AI assistance: OpenAI Codex prepared, reviewed, and validated this change under the account owner's authorization.

@Twiink
Twiink requested a review from a team as a code owner November 22, 2026 05:28
Copilot AI balanced review requested due to automatic review settings November 22, 2026 05:28
@Twiink
Twiink temporarily deployed to github-app-auth November 22, 2026 05:28 — with GitHub Actions Inactive

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.

🟢 Approval recommended

No active review issues block the change preventing constructor overrides from mutating shared configuration data.

No open issues 🎉

What changed in this PR

This PR prevents constructor overrides in Python prompt execution settings from modifying shared extension_data, so reusing a configuration does not leak overrides into later instances.

Changes:

  • Shallow-copy extension_data before merging keyword arguments, preserving per-instance override precedence.
  • Add a regression test verifying both instances’ provider settings and the unchanged caller dictionary.
File Description
python/​tests/​unit/​connectors/​ai/​test_prompt_execution_settings.py Tests shared dictionary preservation and independent temperature settings.
python/​semantic_kernel/​connectors/​ai/​prompt_execution_settings.py Copies extension data before applying constructor overrides.

Review effort: Balanced

This branch was previously deployed

1 inactive deployment
github-app-auth — 7e37cba6 Deployed Nov 22, 2026 by Twiink via add_label #29790
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants