From 1936346f6b88fa3933d818a2be5552dc0a4c3c16 Mon Sep 17 00:00:00 2001 From: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com> Date: Fri, 14 Aug 2026 14:04:12 +0100 Subject: [PATCH] .NET: Fix IDE0039 by using local functions in samples Replace Func lambda assignments with local functions so dotnet format --verify-no-changes passes on the agent and RAG samples. --- .../AgentWithRAG_Step01_BasicTextRAG/Program.cs | 6 +++--- .../AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs | 6 +++--- .../Agents/Agent_Step17_AdditionalAIContext/Program.cs | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs b/dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs index 58e8f050b2..921e56183e 100644 --- a/dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs +++ b/dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step01_BasicTextRAG/Program.cs @@ -37,7 +37,7 @@ await textSearchStore.UpsertDocumentsAsync(GetSampleDocuments()); // Create an adapter function that the TextSearchProvider can use to run searches against the TextSearchStore. -Func>> SearchAdapter = async (text, ct) => +async Task> SearchAdapterAsync(string text, CancellationToken ct) { // Here we are limiting the search results to the single top result to demonstrate that we are accurately matching // specific search results for each question, but in a real world case, more results should be used. @@ -49,7 +49,7 @@ Text = r.Text ?? string.Empty, RawRepresentation = r }); -}; +} // Configure the options for the TextSearchProvider. TextSearchProviderOptions textSearchOptions = new() @@ -63,7 +63,7 @@ .AsAIAgent(new ChatClientAgentOptions { ChatOptions = new() { ModelId = deploymentName, Instructions = "You are a helpful support specialist for Contoso Outdoors. Answer questions using the provided context and cite the source document when available." }, - AIContextProviders = [new TextSearchProvider(SearchAdapter, textSearchOptions)], + AIContextProviders = [new TextSearchProvider(SearchAdapterAsync, textSearchOptions)], // Since we are using ChatCompletion which stores chat history locally, we can also add a message filter // that removes messages produced by the TextSearchProvider before they are added to the chat history, so that // we don't bloat chat history with all the search result messages. diff --git a/dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs b/dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs index 35a37c6afb..ef068fab0b 100644 --- a/dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs +++ b/dotnet/samples/02-agents/AgentWithRAG/AgentWithRAG_Step02_CustomVectorStoreRAG/Program.cs @@ -40,7 +40,7 @@ await UploadDataFromMarkdown(afMigrationUrl, "Semantic Kernel to Microsoft Agent Framework Migration Guide", documentationCollection, 2000, 200); // Create an adapter function that the TextSearchProvider can use to run searches against the collection. -Func>> SearchAdapter = async (text, ct) => +async Task> SearchAdapterAsync(string text, CancellationToken ct) { List results = []; await foreach (var result in documentationCollection.SearchAsync(text, 5, cancellationToken: ct)) @@ -54,7 +54,7 @@ }); } return results; -}; +} // Configure the options for the TextSearchProvider. TextSearchProviderOptions textSearchOptions = new() @@ -72,7 +72,7 @@ .AsAIAgent(new ChatClientAgentOptions { ChatOptions = new() { ModelId = deploymentName, Instructions = "You are a helpful support specialist for the Microsoft Agent Framework. Answer questions using the provided context and cite the source document when available. Keep responses brief." }, - AIContextProviders = [new TextSearchProvider(SearchAdapter, textSearchOptions)], + AIContextProviders = [new TextSearchProvider(SearchAdapterAsync, textSearchOptions)], // Configure a filter on the InMemoryChatHistoryProvider so that we don't persist the messages produced by the TextSearchProvider in chat history. // The default is to persist all messages except those that came from chat history in the first place. // You may choose to persist the TextSearchProvider messages, if you want the search output to be provided to the model in future interactions as well. diff --git a/dotnet/samples/02-agents/Agents/Agent_Step17_AdditionalAIContext/Program.cs b/dotnet/samples/02-agents/Agents/Agent_Step17_AdditionalAIContext/Program.cs index fcff5e6e47..5cc02610fd 100644 --- a/dotnet/samples/02-agents/Agents/Agent_Step17_AdditionalAIContext/Program.cs +++ b/dotnet/samples/02-agents/Agents/Agent_Step17_AdditionalAIContext/Program.cs @@ -23,7 +23,7 @@ var deploymentName = Environment.GetEnvironmentVariable("FOUNDRY_MODEL") ?? "gpt-5.4-mini"; // A sample function to load the next three calendar events for the user. -Func> loadNextThreeCalendarEvents = async () => +async Task LoadNextThreeCalendarEventsAsync() { // In a real implementation, this method would connect to a calendar service return @@ -32,7 +32,7 @@ "Team meeting today at 17:00", "Birthday party today at 20:00" ]; -}; +} // Create an agent with an AI context provider attached that aggregates two other providers. // You must dissable client side conversation storage for clients that support it: @@ -64,7 +64,7 @@ You remind users of upcoming calendar events when the user interacts with you. // The agent will call each provider in sequence, accumulating context from each. AIContextProviders = [ new TodoListAIContextProvider(), - new CalendarSearchAIContextProvider(loadNextThreeCalendarEvents) + new CalendarSearchAIContextProvider(LoadNextThreeCalendarEventsAsync) ], });