Python: Fix Agent Framework tool parameter defaults - #14346
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Python KernelFunction.as_agent_framework_tool() so Agent Framework tool input models preserve parameter defaults (instead of incorrectly making optional parameters required), and adds a regression test to validate the behavior.
Changes:
- Prevent overwriting Pydantic fields that already include a non-
Nonedefault when building the Agent Framework tool input model. - Add a unit test asserting a parameter with
default=5remains optional in the generated tool schema.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
python/semantic_kernel/functions/kernel_function.py |
Adjusts field-building logic in as_agent_framework_tool() to avoid overwriting defaulted fields. |
python/tests/unit/functions/test_kernel_function_from_method.py |
Adds a regression test verifying optionality is preserved when a default value is present. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
MAF Automated Review — Iteration 1
Result: No findings
Scope: full PR (1 commit(s)): a60b81246da8
Model: claude-opus-4.8
Overview
The PR converts an unconditional field-overwrite into an else branch in
KernelFunction.as_agent_framework_tool(), so a Semantic Kernel parameter carrying a
non-None default is preserved as an optional field instead of being clobbered into a
required one. The change is minimal, API-compatible, and touches no shared state,
serialization, or trust boundary. It is backed by a focused regression test that fails
against the pre-fix code and passes after, and the full test_kernel_function_from_method
suite stays green. No Critical/High/Medium defect introduced by the PR was found.
Reviewed the supplied pull-request change set across correctness, security/reliability, architecture, and failure behavior.
No publishable findings remained after source verification for this scope.
- 依据参数必填元数据构造 Pydantic 字段 - 覆盖显式 None 与非 None 两类可选默认值
Motivation and Context
KernelFunction.as_agent_framework_tool()currently builds a field with a parameter default and then immediately overwrites it with a required field. As a result, optional Semantic Kernel parameters become required in the Agent Framework tool schema.Description
is_requiredas the source of truth, including explicitNonedefaultsdefault=5anddefault=Noneremain optionalValidation:
uv run pytest tests/unit/functions/test_kernel_function_from_method.py -q— 37 passeduv run ruff check semantic_kernel/functions/kernel_function.py tests/unit/functions/test_kernel_function_from_method.py— passeduv run ruff format --check semantic_kernel/functions/kernel_function.py tests/unit/functions/test_kernel_function_from_method.py— passedgit diff --check— passedContribution Checklist