Skip to content

Python: Preserve reusable declarative model options - #9068

Merged
Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
ktz03:fix/declarative-reusable-options
Oct 12, 2026
Merged

Eduard van Valkenburg (eavanvalkenburg) merged 1 commit into
microsoft:mainfrom
ktz03:fix/declarative-reusable-options

Conversation

@ktz03

Copy link
Copy Markdown
Contributor

Motivation & Context

Creating an agent consumes chatToolMode from the caller's ModelOptions.additionalProperties. Reusing the same definition therefore gives later agents different tool-choice settings and changes the caller's configuration. Sync and async agent creation should preserve reusable definitions.

Description & Review Guide

  • What are the major changes? Copy the additional-properties mapping before extracting chatToolMode. Add eight public-factory regressions covering repeated sync and async creation with auto, required, none, and an omitted tool mode.
  • What is the impact of these changes? Repeated creation retains the same tool choice, passes through custom properties, and leaves the input definition unchanged. The declarative unit suite passes 1355 tests with 93% coverage, including all eight new cases. The untouched implementation fails six of those cases while the two omitted-mode controls pass. Ruff, source Pyright, all five test type checkers, pre-commit checks, and the wheel/sdist build pass. Factory clients are mocked; no external model or deployed provider was invoked. This is a shallow mapping copy and does not add deep isolation for later mutations of nested custom objects.
  • What do you want reviewers to focus on? Preservation of the reusable input mapping and identical option parsing across repeated sync and async creation. The change is limited to private option parsing; public signatures and tool execution are unchanged.

Related Issue

Fixes #9066

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI balanced review requested due to automatic review settings October 5, 2026 17:00
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Oct 5, 2026

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.

Copilot review overview

🟢 Approval recommended

The focused fix preserves existing behavior while adequately covering reusable definitions and input immutability.

Review effort: Balanced
Findings: None

What changed in this PR

Preserves reusable declarative model options by avoiding mutation while extracting chatToolMode.

Changes:

  • Copies additional properties before parsing tool choice.
  • Adds sync and async regression coverage for all supported tool modes.
File Description
python/​packages/​declarative/​agent_framework_declarative/​_loader.py Prevents mutation of caller-provided options.
python/​packages/​declarative/​tests/​test_declarative_loader.py Tests repeated sync and async agent creation.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Merged via the queue into microsoft:main with commit f9480ea Oct 12, 2026
52 of 53 checks passed

This branch was previously deployed

1 inactive deployment
github-app-auth — c0d6ed66 Deployed Oct 9, 2026 by ktz03 via team_check #6414
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: Declarative agent creation mutates reusable model options

3 participants