Skip to content

Conversation

@milderhc
Copy link
Contributor

@milderhc milderhc commented Apr 29, 2025

Motivation and Context

Description

Fixes #312 #303

Contribution Checklist

@johnoliver johnoliver requested a review from Copilot April 29, 2025 17:01
Copy link
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

This PR introduces support for a new FunctionChoiceBehavior, which provides an alternative to the existing ToolCallBehavior for invoking functions with OpenAI. Key changes include updating the maximum inflight auto-invokes, enhancing InvocationContext and FunctionInvocation to include a new functionChoiceBehavior field and respective builder methods, and updating sample and service code to leverage the new behavior.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
semantickernel-api/src/main/java/com/microsoft/semantickernel/services/TextAIService.java Increased MAXIMUM_INFLIGHT_AUTO_INVOKES from 5 to 128 to support higher concurrency.
semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/InvocationContext.java Introduced a new functionChoiceBehavior property along with getters and builder support.
semantickernel-api/src/main/java/com/microsoft/semantickernel/orchestration/FunctionInvocation.java Added a withFunctionChoiceBehavior method and updated invocation chaining to pass the new behavior.
semantickernel-api/src/main/java/com/microsoft/semantickernel/functionchoice/*.java Added new classes and options to define the behavior for function choice (auto, required, and none).
samples/semantickernel-concepts/... Updated sample code to use withFunctionChoiceBehavior in place of ToolCallBehavior where applicable.
aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/*.java Modified OpenAI chat completion logic to integrate the new function choice behavior and updated tool call configuration.
agents/semantickernel-agents-core/src/main/java/com/microsoft/semantickernel/agents/chatcompletion/ChatCompletionAgent.java Updated the invocation context builder to pass both tool and function choice behaviors.

@johnoliver johnoliver requested a review from Copilot May 1, 2025 19:59
Copy link
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

This PR introduces support for FunctionChoiceBehavior for OpenAI to improve how function calls are automatically invoked, replacing the previous ToolCallBehavior where appropriate. Key changes include:

  • Updating multiple agent and service methods to use FunctionChoiceBehavior with new overloads and chained configuration.
  • Refactoring internal logic in OpenAIChatCompletion and ChatCompletionAgent to distinguish auto-invoke behavior for function calls.
  • Adjusting sample code and annotations to reflect the new API design.

Reviewed Changes

Copilot reviewed 35 out of 35 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
semantickernel-api/src/main/java/com/microsoft/semantickernel/agents/AgentInvokeOptions.java Added @nullable annotations and removed extraneous empty lines in the builder.
semantickernel-api/src/main/java/com/microsoft/semantickernel/agents/Agent.java Added new overloaded invokeAsync methods supporting FunctionChoiceBehavior.
semantickernel-api/src/main/java/com/microsoft/semantickernel/Kernel.java Minor formatting style change for multi-line method declaration.
samples/semantickernel-concepts/semantickernel-syntax-examples/.../Example59_OpenAIFunctionCalling.java Updated to use FunctionChoiceBehavior instead of ToolCallBehavior with model ID update.
aiservices/openai/.../OpenAIChatCompletion.java Extended auto-invoke check by integrating FunctionChoiceBehavior logic and refactored tool call configuration.
agents/semantickernel-agents-core/.../ChatCompletionAgent.java Refactored internalInvokeAsync to use FunctionChoiceBehavior and support streamlined thread notifications.
Comments suppressed due to low confidence (2)

aiservices/openai/src/main/java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java:203

  • Consider refactoring the nested conditional chain that checks for auto-invoke conditions to improve readability and maintainability.
if (invocationContext != null && invocationContext.getFunctionChoiceBehavior() != null && invocationContext.getFunctionChoiceBehavior() instanceof AutoFunctionChoiceBehavior && ((AutoFunctionChoiceBehavior) invocationContext.getFunctionChoiceBehavior()).isAutoInvoke()) {

samples/semantickernel-concepts/semantickernel-syntax-examples/src/main/java/com/microsoft/semantickernel/samples/syntaxexamples/functions/Example59_OpenAIFunctionCalling.java:42

  • [nitpick] Ensure that the updated model ID 'gpt-4o' is supported by the deployment configuration and documented in related release notes.
.getOrDefault("MODEL_ID", "gpt-4o");

@milderhc milderhc merged commit d39be65 into microsoft:main May 1, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement FunctionChoiceBehavior for OpenAI

2 participants