-
Notifications
You must be signed in to change notification settings - Fork 855
.NET: Add serialization support for ContextualFunctionProvider #2601
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: Add serialization support for ContextualFunctionProvider #2601
Conversation
- Added constructor overload that accepts JsonElement serializedState - Implemented Serialize method to persist recent messages - Added ContextualFunctionProviderState class - Registered state class with AgentJsonUtilities JsonContext - Added comprehensive unit tests for serialization/deserialization Co-authored-by: westey-m <[email protected]>
- Reordered constructor parameters to maintain consistency (options before jsonSerializerOptions) - Made default JsonElement explicit with default(JsonElement) in constructor chaining - All tests continue to pass Co-authored-by: westey-m <[email protected]>
- Updated jsonSerializerOptions parameter comments to clarify actual usage - Made it clear that AgentJsonUtilities.DefaultOptions is used - All tests continue to pass Co-authored-by: westey-m <[email protected]>
| var functions = new List<AIFunction> { CreateFunction("f1") }; | ||
| var options = new ContextualFunctionProviderOptions | ||
| { | ||
| NumberOfRecentMessagesInContext = 3 |
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 , change this to 2, so that we can see messages truncation in action.
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.
Changed to 2. The test now demonstrates truncation by adding 3 messages (M1, M2, M3) but only keeping the 2 most recent ones (M2, M3) in the serialized state.
Changes committed in 3ee80a1.
- Updated test to use limit of 2 messages instead of 3 - Now test shows truncation in action (3 messages added, only 2 kept) - Updated assertion to expect 2 messages in serialized state - All tests pass Co-authored-by: westey-m <[email protected]>
Motivation and Context
Addresses review feedback from #2505 to add state persistence for
ContextualFunctionProvider, enabling restoration of recent message context across sessions or in distributed scenarios.Description
Implements serialization/deserialization following the
TextSearchProviderpattern:Core Changes:
JsonElement serializedStatewith deserialization logicSerialize()method to persist recent messages queue asChatMessageobjectsContextualFunctionProviderStateclass and registered withAgentJsonUtilities.JsonContextNumberOfRecentMessagesInContextlimit during deserialization, truncating if changedUsage:
Testing:
Contribution Checklist
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.