Python: [Python] as_agent_framework_tool drops parameter defaults (optionals become required)
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 85/100
Hướng nghiên cứu
Bắt đầu trong semantic_kernel/functions/kernel_function.py, tại as_agent_framework_tool và vòng lặp xây dựng các field của nó. Chạy bản tái hiện tối thiểu từ issue hoặc kiểm tra schema InputModel được tạo ra để xác nhận các field hiện đang bắt buộc. Được xem là hoàn tất khi các tham số có giá trị mặc định vẫn là tùy chọn và giữ nguyên top_k=5 cùng include_meta=False, trong khi query vẫn bắt buộc.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.)
- Ngôn ngữ chính
- C#
- Star
- 28.6k
- Fork
- 4.8k
- Merge trung bình
- 12 giờ 20 phút
- Pull request đã merge (30 ngày)
- 12
Chuẩn bị môi trường
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/semantic-kernel
-
python triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
microsoft/semantic-kernel#14491 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
python triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microsoft/semantic-kernel#14490 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Python: [Python] structured_outputs_transform reuses ChatHistory across calls (prompt pollution)Đang mởpython triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/semantic-kernel#14483 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
.NET python triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
microsoft/semantic-kernel#14482 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
python triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/semantic-kernel#14460 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/semantic-kernel
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
fluentassertions/fluentassertions#3353 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
-
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 78/100
unoplatform/uno#24769 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
AvaloniaUI/Avalonia#22323 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
microsoft/onnxruntime-genai#2633 ·
Maintainer thường phản hồi trong vòng 1 ngày