Skip to content

Python: Invoke the model one more time after auto invoke has exhausted - #13236

Open
Tao Chen (TaoChenOSU) wants to merge 3 commits into
mainfrom
taochen/python-invoke-model-after-auto-invoke-exhausted
Open

Tao Chen (TaoChenOSU) wants to merge 3 commits into
mainfrom
taochen/python-invoke-model-after-auto-invoke-exhausted

Conversation

@TaoChenOSU

Copy link
Copy Markdown
Contributor

Motivation and Context

Related to: #13006

Description

Invoke the chat completion streaming service one more time after the auto function invocation limit has been reached to generate a text response. This has been done in the non-streaming case.

TODO: unit tests

Contribution Checklist

@TaoChenOSU Tao Chen (TaoChenOSU) self-assigned this Oct 8, 2025
@TaoChenOSU
Tao Chen (TaoChenOSU) requested a review from a team as a code owner October 8, 2025 19:07
@TaoChenOSU Tao Chen (TaoChenOSU) added python Pull requests for the Python Semantic Kernel ai connector Anything related to AI connectors labels Oct 8, 2025
@github-actions github-actions Bot changed the title Invoke the model one more time after auto invoke has exhausted Python: Invoke the model one more time after auto invoke has exhausted Oct 8, 2025
@eavanvalkenburg
Eduard van Valkenburg (eavanvalkenburg) force-pushed the taochen/python-invoke-model-after-auto-invoke-exhausted branch from 777f3f0 to 4383883 Compare February 10, 2026 08:53
Copilot AI review requested due to automatic review settings April 8, 2026 01:15

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.

Pull request overview

Aligns streaming auto function invocation behavior with the non streaming implementation by performing one final model call after the auto invoke attempt limit is exhausted, so streaming scenarios can still produce a final text response.

Changes:

  • Simplifies local imports of function result merge helpers.
  • Adds a for ... else final streaming call path after maximum_auto_invoke_attempts is reached, resetting function calling settings before the final call.

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

# Do a final call, without function calling when the max has been reached.
self._reset_function_choice_settings(settings)
async for streaming_chat_message_contents in self._inner_get_streaming_chat_message_contents(
chat_history, settings

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

In the final non function calling call, _inner_get_streaming_chat_message_contents is invoked without passing function_invoke_attempt, so derived connectors will default it to 0. That can produce duplicate function_invoke_attempt values across attempts and may break consumers that group, dedupe, or combine streaming messages by attempt. Pass an explicit attempt index for this final call, for example settings.function_choice_behavior.maximum_auto_invoke_attempts.

Suggested change
chat_history, settings
chat_history,
settings,
function_invoke_attempt=settings.function_choice_behavior.maximum_auto_invoke_attempts,

Copilot uses AI. Check for mistakes.
Comment on lines +315 to +321
else:
# Do a final call, without function calling when the max has been reached.
self._reset_function_choice_settings(settings)
async for streaming_chat_message_contents in self._inner_get_streaming_chat_message_contents(
chat_history, settings
):
yield streaming_chat_message_contents

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

This adds new control flow for streaming auto invoke exhaustion (the for ... else final call after maximum_auto_invoke_attempts). Please add a unit test that exercises this path and asserts that a final model invocation happens after the last tool call and that function calling is disabled for that final invocation (via _reset_function_choice_settings).

Copilot uses AI. Check for mistakes.

This branch was previously deployed

1 inactive deployment
github-app-auth — af604d9a Deployed Sep 28, 2026 by eavanvalkenburg via add_label #29077
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai connector Anything related to AI connectors python Pull requests for the Python Semantic Kernel

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants