Skip to content

Python: Improve function call invocation parameter consistency#14014

Merged
SergeyMenshykh merged 1 commit into
microsoft:mainfrom
SergeyMenshykh:python/improve-function-call-parameter-handling
May 18, 2026
Merged

Python: Improve function call invocation parameter consistency#14014
SergeyMenshykh merged 1 commit into
microsoft:mainfrom
SergeyMenshykh:python/improve-function-call-parameter-handling

Conversation

@SergeyMenshykh
Copy link
Copy Markdown
Contributor

@SergeyMenshykh SergeyMenshykh commented May 15, 2026

Description

This PR improves the consistency of how the function_behavior parameter is passed through internal invoke_function_call callsites.

Changes

  • Thread function_behavior parameter through all internal invoke_function_call callsites for consistent parameter handling:
    • Realtime connector (_open_ai_realtime.py)
    • Responses agent (responses_agent_thread_actions.py)
    • Assistant agent (assistant_thread_actions.py)
    • Azure AI agent (agent_thread_actions.py)
    • Bedrock agent (bedrock_agent.py)
  • Add defensive logging in kernel.py when function_behavior is not provided
  • Add unit tests covering parameter handling scenarios

Testing

  • All existing tests pass (678 passed, 0 failed)
  • 5 new tests added covering the updated parameter handling

Copilot AI review requested due to automatic review settings May 15, 2026 18:11
@SergeyMenshykh SergeyMenshykh requested a review from a team as a code owner May 15, 2026 18:11
@SergeyMenshykh SergeyMenshykh self-assigned this May 15, 2026
@SergeyMenshykh SergeyMenshykh moved this to In Review in Agent Framework May 15, 2026
@SergeyMenshykh SergeyMenshykh enabled auto-merge May 15, 2026 18:12
@moonbox3 moonbox3 added the python Pull requests for the Python Semantic Kernel label May 15, 2026
@SergeyMenshykh SergeyMenshykh force-pushed the python/improve-function-call-parameter-handling branch from b0cc638 to d47910b Compare May 15, 2026 18:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR standardizes passing function_behavior into Kernel.invoke_function_call across multiple internal call sites, adds a warning when it’s omitted, and introduces unit tests around allowlist/filter behavior.

Changes:

  • Thread function_behavior through realtime + agent invocation paths for consistent allowlist/filter validation behavior.
  • Add warning log in Kernel.invoke_function_call when function_behavior is omitted.
  • Add unit tests covering allow/deny filtering and missing function_behavior scenarios.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
python/semantic_kernel/kernel.py Adds warning when function_behavior is missing (no allowlist validation).
python/semantic_kernel/connectors/ai/open_ai/services/_open_ai_realtime.py Passes execution settings’ function_choice_behavior into invoke_function_call.
python/semantic_kernel/agents/open_ai/responses_agent_thread_actions.py Threads function_behavior through internal async function-call gather.
python/semantic_kernel/agents/open_ai/assistant_thread_actions.py Adds function_behavior parameter and forwards it into invocation.
python/semantic_kernel/agents/azure_ai/agent_thread_actions.py Adds function_behavior parameter and forwards it into invocation.
python/semantic_kernel/agents/bedrock/bedrock_agent.py Forwards agent’s configured function_choice_behavior into invocation.
python/tests/unit/kernel/test_kernel.py Adds tests for filter blocking/allowing and warning when behavior omitted.
python/tests/unit/connectors/ai/open_ai/services/test_openai_realtime.py Adds tests ensuring realtime path forwards function_behavior and enforces filters.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread python/tests/unit/kernel/test_kernel.py Outdated
Comment thread python/semantic_kernel/kernel.py
Comment thread python/tests/unit/kernel/test_kernel.py Outdated
@moonbox3
Copy link
Copy Markdown
Collaborator

moonbox3 commented May 15, 2026

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
kernel.py2365875%149, 160, 164, 320–321, 323, 412, 418–419, 423–424, 477–481, 483–484, 497–506, 508, 510–511, 513–533, 535–540
agents/bedrock
   bedrock_agent.py2625678%79, 85–86, 95, 161, 288, 301, 320, 336–339, 345, 347, 350, 355, 387, 390, 403, 435–436, 443–446, 454–455, 459, 492, 495, 508, 527–530, 532–535, 577, 588–589, 601, 637–638, 648, 659, 676–677, 690, 707, 709, 711, 713–714, 716
agents/open_ai
   responses_agent_thread_actions.py44312871%177, 194, 207, 218–219, 227, 234, 247, 407–408, 410, 424, 429, 436, 451–452, 462, 469, 471–472, 481, 488, 490–491, 502, 509, 511–512, 522, 529, 534–535, 539, 551, 585–587, 590, 608–609, 620–622, 626, 630–631, 635–637, 648–650, 672, 674–675, 682–683, 685–686, 688, 690–691, 693–694, 792, 797, 805–806, 808, 814, 819, 824–826, 832–834, 839–840, 842–847, 849, 853–854, 856, 860, 864, 869–870, 875, 878–879, 939–942, 965, 1011–1014, 1055–1056, 1060–1062, 1064, 1089–1090, 1092–1096, 1098, 1108–1109, 1121, 1127, 1134, 1140, 1221, 1224, 1227
connectors/ai/open_ai/services
   _open_ai_realtime.py4539678%288, 290, 292, 329, 384, 392, 436–440, 464–467, 559–560, 563–564, 574, 582–585, 592, 594, 597–598, 648–651, 660–663, 675–676, 720–722, 724–725, 728–729, 732, 743, 745, 747–749, 788–789, 796–798, 817, 824, 829–831, 833–836, 843–845, 853–854, 858–862, 885–886, 891–893, 928, 931, 934–937, 942–944, 947–953
TOTAL28650563880% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3929 23 💤 0 ❌ 0 🔥 1m 51s ⏱️

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 92%

✗ Correctness

The PR correctly threads function_behavior to kernel.invoke_function_call from the Bedrock agent and Realtime connector paths, and updates the _invoke_function_calls helper signatures in Azure AI, Assistant, and Responses agent thread actions to accept the parameter. However, the callers of those helpers (e.g., azure_ai/agent_thread_actions.py:234-236, azure_ai/agent_thread_actions.py:1123-1124, assistant_thread_actions.py:262-264, assistant_thread_actions.py:565-567) are not updated to pass function_behavior through, so it always arrives as None for those agent paths. Combined with the new elif function_behavior is None: warning in kernel.py, this means every function call from the Azure AI and OpenAI Assistant agents will now emit a warning-level log message that did not exist before — producing log noise in production for legitimate agent usage without any actual security benefit.

✓ Security Reliability

This PR correctly threads function_behavior through the realtime connector and bedrock agent to enable allowlist validation for function calls, closing a real security gap. The kernel.py defensive warning is well-placed. The agent plumbing (azure_ai, assistant, responses) adds the parameter to _invoke_function_calls signatures but calers don't pass it yet, meaning those paths remain unprotected—this is not a regression and is consistent with the stated incremental approach. No blocking security or reliability issues found.

✓ Test Coverage

The PR adds function_behavior parameter plumbing to several agents and the realtime connector. Tests adequately cover the realtime connector path and kernel-level behavior (blocking, allowing, warning). However, there are notable test coverage gaps: (1) the callers of _invoke_function_calls in Azure AI and OpenAI Assistant agents were NOT updated to pass function_behavior, so the new parameter always defaults to None — no tests catch this incomplete threading; (2) the Bedrock agent is the only agent that actually passes function_behavior at its call site, yet has no test; (3) the Responses agent's _invoke_function_calls method appears to be dead code (never called within the file) while the actual direct calls at lines 256 and 561 already pass function_behavior independently of this PR's changes.

✗ Design Approach

The PR improves Kernel.invoke_function_call() and the realtime/Bedrock/Responses paths, but the assistant and Azure agent requires-action flows are still not actually threaded with function_behavior. In both files, the new optional parameter is added only to the local _invoke_function_calls() helper; the live callers still omit it, so those paths continue to hit Kernel.invoke_function_call() with function_behavior=None and skip the allowlist validation this PR is meant to make consistent.

Suggestions

  • Thread function_behavior from the assistant requires-action entry points (assistant_thread_actions.py:262-264 and :565-567) and the Azure AI requires-action entry points (azure_ai/agent_thread_actions.py:234-236 and :1123-1125) into _invoke_function_calls(), rather than only widening the helper signatures.

Automated review by SergeyMenshykh's agents

Comment thread python/semantic_kernel/agents/azure_ai/agent_thread_actions.py
Thread function_behavior parameter through internal invoke_function_call
callsites where it is available but was not being passed.
Add defensive debug logging when parameter is not provided.
Update and add unit tests for parameter handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SergeyMenshykh SergeyMenshykh force-pushed the python/improve-function-call-parameter-handling branch from d47910b to 180aee8 Compare May 15, 2026 18:31
@SergeyMenshykh SergeyMenshykh added this pull request to the merge queue May 18, 2026
Merged via the queue into microsoft:main with commit 58f4a66 May 18, 2026
32 checks passed
@SergeyMenshykh SergeyMenshykh deleted the python/improve-function-call-parameter-handling branch May 18, 2026 10:03
@github-project-automation github-project-automation Bot moved this from In Review to Done in Agent Framework May 18, 2026
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

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants