Repository navigation
Python: Fix default result_parser arity on kernel function strategies - #14595
Li-john1021 wants to merge 2 commits into
Conversation
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
There was a problem hiding this comment.
🟢 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.
|
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):
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! |
Motivation and Context
KernelFunctionSelectionStrategyandKernelFunctionTerminationStrategydeclare optionalresult_parserfields whose defaults are zero-argument lambdas, butselect_agent/should_agent_terminatealways callself.result_parser(result)with one argument. Using either strategy without a custom parser therefore always raisesTypeError.Fixes #14589
Description
Update the defaults so they accept the function result:
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).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 tolambda _: Truefor .NET parity if maintainers prefer that.Also adds regression tests that construct both strategies without a custom
result_parser.Contribution Checklist