Python: [Python] as_agent_framework_tool drops parameter defaults (optionals become required)
维护者通常 2 天内回复
还没有人认领这个 Issue。
评估
调研方向
从 semantic_kernel/functions/kernel_function.py 中的 as_agent_framework_tool 及其字段构建循环开始。运行 issue 中的最小复现,或检查生成的 InputModel schema,以确认当前必需的字段。完成的标准是:带有默认值的参数仍保持可选,并保留 top_k=5 和 include_meta=False,而 query 仍为必需字段。
由索引模型根据 Issue 内容生成。
描述
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.)
- 主要语言
- C#
- 星标
- 28.6k
- 派生
- 4.8k
- 平均合并
- 13 小时 24 分钟
- 30 天内合并 PR
- 11
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/semantic-kernel 的其他 Issue
-
python triage
难度 2/5 1-3 小时 新手友好度 85/100
microsoft/semantic-kernel#14491 · 1 条评论 ·
维护者通常 2 天内回复
-
python triage
难度 2/5 1-3 小时 新手友好度 82/100
microsoft/semantic-kernel#14490 · 1 条评论 ·
维护者通常 2 天内回复
-
Python: [Python] structured_outputs_transform reuses ChatHistory across calls (prompt pollution)未关闭python triage
难度 2/5 1-3 小时 新手友好度 88/100
microsoft/semantic-kernel#14483 · 2 条评论 ·
维护者通常 2 天内回复
-
.NET python triage
难度 2/5 1-3 小时 新手友好度 74/100
microsoft/semantic-kernel#14482 · 3 条评论 ·
维护者通常 2 天内回复
-
python triage
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/semantic-kernel#14460 ·
维护者通常 2 天内回复
查看 microsoft/semantic-kernel 的全部 Issue
相似的 Issue
-
agentic-workflows area/Docs partner/agentic-workflows
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/fluentui-blazor#5364 ·
维护者通常 1 天内回复
-
.NET triage
难度 2/5 1-3 小时 新手友好度 74/100
microsoft/agent-framework#8811 ·
维护者通常 1 天内回复
-
.NET Docs
难度 1/5 1 小时以内 新手友好度 82/100
getsentry/sentry-dotnet#5637 · 1 条评论 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
QuantConnect/Lean#9842 ·
维护者通常 1 天内回复