Skip to content
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 name policy to control function fqn creation and parsing #10206

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

SergeyMenshykh
Copy link
Member

@SergeyMenshykh SergeyMenshykh commented Jan 16, 2025

Motivation, Context

Today, each AI connector uses a hyphen ("-") as a plugin-function name separator when creating a fully qualified name (FQN) for all functions to advertise them to an AI model. On the way back, they also use the hyphen when splitting FQNs into plugin and function names while handling function calls from the AI model.

From time to time, AI models hallucinate/replace the FQN separator with a different one. For example, if a function is advertised with the TimePlugin-GetCurrentUtcDateTime FQN, the AI model may call it with the TimePlugin.GetCurrentUtcDateTime or TimePlugin_GetCurrentUtcDateTime FQNs. As a result, when the AI model calls the functions with one of the unexpected separators, SK cannot find the function during the lookup process to invoke it and sends this information back to the AI model, which fails the request with the error: "Invalid 'messages[6].tool_calls[0].function.name': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9-]+$'"_.

Description

This PR enables a few ways for the consuming code to tackle the issue described above via the new FunctionNamePolicy class:

  1. Use a custom separator instead of the default hyphen. The idea here is that the custom separator might be more natural as part of a function name for the AI model, so it stops changing it.

  2. Provide an FQN parsing delegate to customize the process of splitting the function FQN from the function call by trying different separators. The idea here is to handle the hallucinated name on the client side without unnecessary roundtrips (which may fail anyway if the hallucinated function name contains a dot) to the AI model, only to tell it that it called the function with the wrong separator.

  3. Advertise functions using their names only as FQNs. The idea here is that if the plugin name is not included in the FQN, then the separator is not needed, and as a result, there's nothing to hallucinate. Of course, it's possible to hallucinate the function names in a few other ways, but that has not been the case so far, or at least we have not heard about it.

@SergeyMenshykh SergeyMenshykh requested a review from a team as a code owner January 16, 2025 11:49
@SergeyMenshykh SergeyMenshykh self-assigned this Jan 16, 2025
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels Jan 16, 2025
@SergeyMenshykh SergeyMenshykh added ai connector Anything related to AI connectors function_calling and removed kernel Issues or pull requests impacting the core kernel kernel.core labels Jan 16, 2025
@markwallace-microsoft markwallace-microsoft added kernel Issues or pull requests impacting the core kernel kernel.core labels Jan 16, 2025
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 function_calling kernel.core kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code
Projects
Status: Sprint: In Review
Development

Successfully merging this pull request may close these issues.

2 participants