Skip to content

.Net: Contextual function provider #12254

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

Merged

Conversation

SergeyMenshykh
Copy link
Member

@SergeyMenshykh SergeyMenshykh commented May 23, 2025

Motivation, Context, and Description

This PR adds functionality that allows AI agents to advertise functions relevant to the current context, rather than advertising all available functions.

The functionality is implemented by two components:

  • The FunctionStore class is responsible for the vectorization of functions, upserting them into the provided vector store, and performing vector searches. This class is internal at the moment as it's used only by the ContextualFunctionProvider class. Later, it might be promoted to public if required.
  • The ContextualFunctionProvider class delegates function vectorization and persistence to the FunctionStore. It vectorizes the current context and delegates the vector search to the FunctionStore class again.

Logging will be added in follow-up PRs.

Contributes to: #10074

@SergeyMenshykh SergeyMenshykh self-assigned this May 23, 2025
@SergeyMenshykh SergeyMenshykh requested a review from a team as a code owner May 23, 2025 10:25
@markwallace-microsoft markwallace-microsoft added the .NET Issue or Pull requests regarding .NET code label May 23, 2025
@SergeyMenshykh SergeyMenshykh moved this to Sprint: In Review in Semantic Kernel May 23, 2025
@SergeyMenshykh SergeyMenshykh changed the title .Net: Add contextual function provider .Net: Contextual function provider May 23, 2025
@SergeyMenshykh SergeyMenshykh requested review from Copilot and removed request for a team May 23, 2025 10:28
Copy link
Contributor

@Copilot 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

Adds a contextual function selection capability by vectorizing available functions and retrieving only those relevant to the current chat context.

  • Introduces FunctionStore and its options to index and search functions via a vector store
  • Adds ContextualFunctionProvider and corresponding options to plug into chat-based agents
  • Updates sample project to demonstrate usage and adds a new ModelContextProtocol dependency

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
dotnet/src/SemanticKernel.Core/Functions/ContextualSelection/FunctionStoreOptions.cs Defines options for function vectorization and retrieval
dotnet/src/SemanticKernel.Core/Functions/ContextualSelection/FunctionStore.cs Implements vector store indexing and search logic
dotnet/src/SemanticKernel.Core/Functions/ContextualSelection/ContextualFunctionProviderOptions.cs Defines public options for the contextual provider
dotnet/src/SemanticKernel.Core/Functions/ContextualSelection/ContextualFunctionProvider.cs Wraps FunctionStore to provide an AI context with relevant functions
dotnet/samples/Concepts/Concepts.csproj Adds ModelContextProtocol package reference
dotnet/samples/Concepts/Agents/ChatCompletion_ContextualFunctionSelection.cs Sample showing how to wire up the contextual provider
Comments suppressed due to low confidence (1)

dotnet/samples/Concepts/Agents/ChatCompletion_ContextualFunctionSelection.cs:38

  • [nitpick] The agent name uses GithubAssistant; update it to GitHubAssistant to match correct casing of the GitHub brand.
Name = "GithubAssistant",

SergeyMenshykh and others added 2 commits May 23, 2025 12:52
…ontextualFunctionProvider.cs

Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
@markwallace-microsoft markwallace-microsoft added the kernel Issues or pull requests impacting the core kernel label May 26, 2025
@SergeyMenshykh SergeyMenshykh merged commit 9c91a7e into contextual-function-selection May 27, 2025
2 checks passed
@github-project-automation github-project-automation bot moved this from Sprint: In Review to Sprint: Done in Semantic Kernel May 27, 2025
@SergeyMenshykh SergeyMenshykh deleted the add-contextual-function-provider branch May 27, 2025 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
agents documentation kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants