-
Notifications
You must be signed in to change notification settings - Fork 849
Port ContextualFunctionProvider from SK #2505
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
base: main
Are you sure you want to change the base?
Conversation
| using Microsoft.Extensions.VectorData; | ||
| using Microsoft.Shared.Diagnostics; | ||
|
|
||
| namespace Microsoft.Agents.AI.Functions; |
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.
I wonder whether we should go with the more abstract name Tools instead of the more specific Functions.
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.
Yeah, I'm not convinced .Functions is right either. Want to bring it up as a discussion point with the team.
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 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
FunctionStoreclass for vectorizing and storing functions in a vector store - Added
ContextualFunctionProviderthat performs vector searches to find relevant functions based on context - Implemented comprehensive configuration options through
ContextualFunctionProviderOptionsandFunctionStoreOptions
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 |
dotnet/src/Microsoft.Agents.AI/Functions/ContextualFunctionProviderOptions.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/Functions/FunctionStoreTests.cs
Outdated
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/Functions/FunctionStoreTests.cs
Show resolved
Hide resolved
dotnet/tests/Microsoft.Agents.AI.UnitTests/Functions/FunctionStoreTests.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI/Functions/ContextualFunctionProvider.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
| public sealed class ContextualFunctionProvider : AIContextProvider | ||
| { | ||
| private readonly FunctionStore _functionStore; | ||
| private readonly ConcurrentQueue<ChatMessage> _recentMessages = []; |
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.
These need to be serialized into the AIContextProvider state
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.
@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) |
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.
This should check for an exception in the context before adding messages to the queue.
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.
@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.
Motivation and Context
#2448
Description
Contribution Checklist