Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open Beginner friendly
#14,481 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api

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

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

Dominant language
C#
Stars
28.6k
Forks
4.8k
Avg merge
12h 20m
Merged PRs (30d)
12

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/semantic-kernel

All issues in microsoft/semantic-kernel

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.