Skip to content

Python: Fix default result_parser arity on kernel function strategies - #14595

Open
Li-john1021 wants to merge 2 commits into
microsoft:mainfrom
Li-john1021:fix/14589-result-parser-arity
Open

Li-john1021 wants to merge 2 commits into
microsoft:mainfrom
Li-john1021:fix/14589-result-parser-arity

Conversation

@Li-john1021

Copy link
Copy Markdown

Motivation and Context

KernelFunctionSelectionStrategy and KernelFunctionTerminationStrategy declare optional result_parser fields whose defaults are zero-argument lambdas, but select_agent / should_agent_terminate always call self.result_parser(result) with one argument. Using either strategy without a custom parser therefore always raises TypeError.

Fixes #14589

Description

Update the defaults so they accept the function result:

  • Selection: lambda result: str(result).strip() — use the function output as the agent name (aligned with the .NET default that reads a string from the result).
  • Termination: lambda result: str(result).strip().lower() == "true" — treat a case-insensitive "true" as terminate.

For termination, .NET’s default is (_) => true (always terminate). I followed the issue’s suggestion instead, because an always-true default would ignore the kernel function output and stop the chat on the first check. Happy to switch to lambda _: True for .NET parity if maintainers prefer that.

Also adds regression tests that construct both strategies without a custom result_parser.

Contribution Checklist

KernelFunctionSelectionStrategy and KernelFunctionTerminationStrategy
used zero-argument default result_parser lambdas, but select_agent and
should_agent_terminate call them with the function result. Defaults now
accept that argument: selection uses str(result).strip(), termination
treats a case-insensitive "true" as terminate.

Fixes microsoft#14589
@Li-john1021
Li-john1021 requested a review from a team as a code owner October 14, 2026 05:34
Copilot AI balanced review requested due to automatic review settings October 14, 2026 05:34
@semantic-kernel-automation semantic-kernel-automation Bot added the python Pull requests for the Python Semantic Kernel label Oct 14, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The defaults now match their call sites, and regression tests cover both strategies.

0 open findings

What changed in this PR

Fixes default parser arity and behavior for Python kernel-function agent strategies.

Changes:

  • Parses function results into agent names or termination decisions.
  • Adds regression tests for default parser behavior.
File Description
test_kernel_function_termination_strategy.py Tests true and false default parsing.
test_kernel_function_selection_strategy.py Tests default agent-name parsing.
kernel_function_termination_strategy.py Adds a one-argument boolean parser.
kernel_function_selection_strategy.py Adds a one-argument agent-name parser.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 26, 2026
@Li-john1021

Copy link
Copy Markdown
Author

Thanks for the approval and for queuing this, Eduard van Valkenburg (@eavanvalkenburg)!

It looks like the PR was removed from the merge queue because the merge-group Python Pre-Merge Integration Tests - Agents hit an Azure infra timeout (unrelated to this change):

test_file_search_invoke → azure.core.exceptions.DecodeError / vector_stores request timed out
(run 40325498196)

Unit tests and other checks on the PR itself are green. I don’t have permission to re-enable auto-merge / re-queue — would you mind adding it back to the merge queue when convenient? Happy to help if anything else is needed. Thank you!

This branch was previously deployed

1 inactive deployment
github-app-auth — af7ddaa9 Deployed Oct 16, 2026 by Li-john1021 via add_label #29368
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Pull requests for the Python Semantic Kernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: Bug: KernelFunctionSelectionStrategy and KernelFunctionTerminationStrategy default result_parser raises TypeError

3 participants