-
Notifications
You must be signed in to change notification settings - Fork 54
Add FunctionChoiceBehavior for OpenAI #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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. |
...el-api/src/main/java/com/microsoft/semantickernel/functionchoice/FunctionChoiceBehavior.java
Show resolved
Hide resolved
...java/com/microsoft/semantickernel/aiservices/openai/chatcompletion/OpenAIChatCompletion.java
Outdated
Show resolved
Hide resolved
Avoid notify thread when auto-invoke is not active
There was a problem hiding this 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");
Motivation and Context
Description
Fixes #312 #303
Contribution Checklist