Skip to content

Conversation

@westey-m
Copy link
Contributor

Motivation and Context

#2448

Description

  • Porting ContextualFunctionProvider from SK to AF.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings November 27, 2025 17:15
Copilot finished reviewing on behalf of westey-m November 27, 2025 17:18
using Microsoft.Extensions.VectorData;
using Microsoft.Shared.Diagnostics;

namespace Microsoft.Agents.AI.Functions;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether we should go with the more abstract name Tools instead of the more specific Functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not convinced .Functions is right either. Want to bring it up as a discussion point with the team.

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 ports the ContextualFunctionProvider from Semantic Kernel (SK) to the Agent Framework (AF), enabling RAG (Retrieval-Augmented Generation) on functions to identify the most relevant functions for a given context.

Key Changes:

  • Introduced FunctionStore class for vectorizing and storing functions in a vector store
  • Added ContextualFunctionProvider that performs vector searches to find relevant functions based on context
  • Implemented comprehensive configuration options through ContextualFunctionProviderOptions and FunctionStoreOptions

Reviewed changes

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

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI/Functions/FunctionStore.cs Core internal class for storing and searching functions using vector similarity
dotnet/src/Microsoft.Agents.AI/Functions/FunctionStoreOptions.cs Internal configuration options for function store customization
dotnet/src/Microsoft.Agents.AI/Functions/FunctionStoreLoggingExtensions.cs Logging extension methods for function vectorization and search results
dotnet/src/Microsoft.Agents.AI/Functions/ContextualFunctionProvider.cs Public AI context provider that uses vector search for function selection
dotnet/src/Microsoft.Agents.AI/Functions/ContextualFunctionProviderOptions.cs Public configuration options for contextual function provider
dotnet/tests/Microsoft.Agents.AI.UnitTests/Functions/FunctionStoreTests.cs Unit tests for FunctionStore covering constructor validation, save, and search operations
dotnet/tests/Microsoft.Agents.AI.UnitTests/Functions/ContextualFunctionProviderTests.cs Comprehensive unit tests for ContextualFunctionProvider including context building and function retrieval

public sealed class ContextualFunctionProvider : AIContextProvider
{
private readonly FunctionStore _functionStore;
private readonly ConcurrentQueue<ChatMessage> _recentMessages = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These need to be serialized into the AIContextProvider state

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot, please add serialization and deserialization code, that stores the recent messages in serialized state.
See the TextSearchProvider as an example.
Also add unit tests for this behavior.

}

/// <inheritdoc/>
public override ValueTask InvokedAsync(InvokedContext context, CancellationToken cancellationToken = default)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should check for an exception in the context before adding messages to the queue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot, update the code here so that that if the context has a non-null exception, it doesn't add messages to the recent messages list.

Copy link
Contributor

Copilot AI commented Dec 3, 2025

@westey-m I've opened a new pull request, #2600, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Dec 3, 2025

@westey-m I've opened a new pull request, #2601, to work on those changes. Once the pull request is ready, I'll request review from you.

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.

3 participants