Python: [Python] as_agent_framework_tool drops parameter defaults (optionals become required)
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
Research direction
Start in semantic_kernel/functions/kernel_function.py at as_agent_framework_tool and its field-building loop. Run the minimal reproduction from the issue, or inspect the generated InputModel schema, to confirm the current required fields. Done means parameters with defaults remain optional and retain top_k=5 and include_meta=False, while query remains required.
Written by the indexing model from the issue text.
Description
Description
KernelFunction.as_agent_framework_tool builds an agent-framework InputModel but drops parameter defaults. After assigning a Field(..., default=...) for optional params, the next line unconditionally overwrites the same key with a no-default Field, so every optional becomes required in the JSON schema.
Environment
semantic-kernel==1.44.1(Python)- Python 3.13
Minimal repro
The bug is in the field-building loop (exact code from as_agent_framework_tool):
from typing import Annotated
from pydantic import Field, create_model
from semantic_kernel.functions import KernelPlugin, kernel_function
@kernel_function(name="search", description="search things")
def search(
query: Annotated[str, "search query"],
top_k: Annotated[int, "number of results"] = 5,
include_meta: Annotated[bool, "include metadata"] = False,
) -> str:
return f"{query}:{top_k}:{include_meta}"
fn = KernelPlugin(name="S", functions=[search])["search"]
fields = {}
for param in fn.parameters:
if param.include_in_function_choices:
if param.default_value is not None:
fields[param.name] = (
param.type_,
Field(description=param.description, default=param.default_value),
)
fields[param.name] = (param.type_, Field(description=param.description)) # overwrites
Model = create_model("InputModel", **fields)
print(Model.model_json_schema().get("required"))
# ACTUAL: ['query', 'top_k', 'include_meta']
# EXPECTED: ['query'] (top_k / include_meta optional with defaults)
(as_agent_framework_tool() itself also needs agent-framework-core; the loop above is the same code path.)
Expected
Optional kernel function parameters with defaults remain optional in the agent-framework InputModel / schema (top_k=5, include_meta=False).
Actual
All included params are required; defaults are discarded. Especially misleading for False/0 because default_value is not None is true, yet the default is still overwritten.
Root cause (pointer)
semantic_kernel/functions/kernel_function.py — as_agent_framework_tool (~field loop): missing else: around the no-default assignment.
Suggested fix direction
if param.default_value is not None:
fields[param.name] = (..., Field(..., default=param.default_value))
else:
fields[param.name] = (..., Field(...))
(Also prefer param.type_object over the string param.type_ if available.)
- Dominant language
- C#
- Stars
- 28.6k
- Forks
- 4.8k
- Avg merge
- 12h 20m
- Merged PRs (30d)
- 12
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/semantic-kernel
-
python triage
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
microsoft/semantic-kernel#14491 ·
Maintainers usually reply within 2 days
-
python triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
microsoft/semantic-kernel#14490 ·
Maintainers usually reply within 2 days
-
Python: [Python] structured_outputs_transform reuses ChatHistory across calls (prompt pollution)Openpython triage
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
microsoft/semantic-kernel#14483 · 1 comment ·
Maintainers usually reply within 2 days
-
.NET python triage
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
microsoft/semantic-kernel#14482 · 1 comment ·
Maintainers usually reply within 2 days
-
python triage
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/semantic-kernel#14460 ·
Maintainers usually reply within 2 days
All issues in microsoft/semantic-kernel
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
AvaloniaUI/Avalonia#22323 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
microsoft/onnxruntime-genai#2633 ·
Maintainers usually reply within 1 day
-
Not reproducible
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
microsoft/fluentui-blazor#5350 · 4 comments ·
Maintainers usually reply within 1 day
-
area:jobads-cv FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1878 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
ValveSoftware/Unity#19 ·