Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Python: [Python] as_agent_framework_tool drops parameter defaults (optionals become required)

Đang mở Phù hợp với người mới
#14,481 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

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
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
api

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ả

python triage

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

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/semantic-kernel

Tất cả issue của microsoft/semantic-kernel

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.