-
Notifications
You must be signed in to change notification settings - Fork 4k
.Net: Function calling abstraction #6083
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
.Net: Function calling abstraction #6083
Conversation
Co-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
…lling.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
…Content.cs Co-authored-by: Stephen Toub <stoub@microsoft.com>
…eyMenshykh/semantic-kernel into function-call-content-types
Co-authored-by: Stephen Toub <stoub@microsoft.com>
…alifiedFunctionName utility class.
…r one of the KernelArguments constructors.
…eyMenshykh/semantic-kernel into function-call-content-types
…e `FunctionName` utility class.
…/SergeyMenshykh/semantic-kernel into function-calling-abstraction-poc
…/SergeyMenshykh/semantic-kernel into function-calling-abstraction-poc
…ors/FunctionChoiceBehavior.cs Co-authored-by: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com>
…/SergeyMenshykh/semantic-kernel into function-calling-abstraction-poc
…ling if no functions provided by funciton choice behavior.
…rent parameters LLM may have.
…/SergeyMenshykh/semantic-kernel into function-calling-abstraction-poc
} | ||
|
||
// If both behaviors are specified, we can't handle that. | ||
if (executionSettings.FunctionChoiceBehavior is not null && executionSettings.ToolCallBehavior is not null) |
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.
Reading this again, it's still really confusing to me that both of these things exist. If we're going to delete the existing one as part of OpenAI SDK update work, maybe for now we just mark it editor browsable never and obsolete with a message telling folks to use the new one? Altough that's odd as well if the new surface area is marked experimental. Ugh.
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.
In Python, while still in v1, we're marking the FunctionCallBehavior
as deprecated, and logging warnings to use the new FunctionChoiceBehavior
. If a customer still configures the FunctionCallBehavior
class, we're using a model validator to map the FunctionCallBehavior
to FunctionChoiceBehavior
. Anytime the old FunctionCallBehavior
gets an update, so does FunctionChoiceBehavior
. This allows us to only make decisions based off of FunctionChoiceBehavior
and makes for easier cleanup when we do remove FunctionCallBehavior
.
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.
Reading this again, it's still really confusing to me that both of these things exist. If we're going to delete the existing one as part of OpenAI SDK update work, maybe for now we just mark it editor browsable never and obsolete with a message telling folks to use the new one? Altough that's odd as well if the new surface area is marked experimental. Ugh.
We plan to remove the ToolCallBehavior
property and the corresponding code that uses it as part of the OpenAI SDK update work. The PR will be retargeted and merged into the feature-connectors-openai branch.
The experimental attributes will be removed, as the new function choice behavior functionality replaces the tool call behavior that was released for a while.
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.
Ok, thanks
…choice behavior related functionality that is going to replace existing tool calling functionality
[JsonDerivedType(typeof(AutoFunctionChoiceBehavior), typeDiscriminator: "auto")] | ||
[JsonDerivedType(typeof(RequiredFunctionChoiceBehavior), typeDiscriminator: "required")] | ||
[JsonDerivedType(typeof(NoneFunctionChoiceBehavior), typeDiscriminator: "none")] | ||
public abstract class FunctionChoiceBehavior |
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.
Can we evaluate how this adapts to requirements for assistant-agent tool-choice?
https://platform.openai.com/docs/api-reference/runs/createRun#runs-createrun-tool_choice
I wonder if there's a way to not bind this base abstraction so tightly to chat-completion only? Maybe there is an even more generic base abstraction? The current form might not adapt so well for assistants.
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.
Why would we not / are we not using the same content types for agents?
Motivation and Context
Today, every AI connector in SK that supports function calling has its own implementation of tool call behavior model classes. These classes are used to configure the way connectors advertise and invoke functions. For example, the behavior classes can describe which functions should be advertised to LLM by a connector, whether the functions should be called automatically by the connector, or if the connector caller will invoke them himself manually, etc.
All the tool call behavior classes are the same in terms of describing the desired function call behavior. However, the classes have a mapping functionality to map the function call behavior to the connector-specific model classes, and that's what makes the function calling classes non-reusable between connectors.
Additionally, today, it's not possible to specify function calling behavior declaratively in YAML, MD, and Kernel(config.json) prompts.
Description
This PR introduces a few function choice behavior classes that allow configure function calling behavior in connector agnostic way:
Callers can specify one of the function choice behaviors using the new property, FunctionChoiceBehavior, which has been added to the PromptExecutionSettings class. Here's an example:
The function choice behavior can be configured in JSON and YAML prompts as well:
Closes - #5253, #5954
ADR - #6099
Contribution Checklist