Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン 初心者向け
#14,481 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
85/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api

調査の方向性

semantic_kernel/functions/kernel_function.py の as_agent_framework_tool と、そのフィールド構築ループから始めます。issue の最小再現を実行するか、生成された InputModel スキーマを調べて、現在必須となっているフィールドを確認します。パラメーターにデフォルト値がある場合はオプションのままになり、top_k=5 と include_meta=False が維持され、query は引き続き必須であれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.)

主要言語
C#
スター
28.6k
フォーク
4.8k
平均マージ
12時間 20分
マージ済み PR(30日)
12

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/semantic-kernel のほかの issue

microsoft/semantic-kernel の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。