From d82d2527af176cbd65eb8a80b9de43f34b374e85 Mon Sep 17 00:00:00 2001 From: markwallace-microsoft <127216156+markwallace-microsoft@users.noreply.github.com> Date: Wed, 27 Aug 2025 14:40:31 +0100 Subject: [PATCH] Filter out reasoning response items during function calling --- ...ep03_OpenAIResponseAgent_ReasoningModel.cs | 23 +++++++++++++++++++ .../OpenAI/Internal/ResponseThreadActions.cs | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dotnet/samples/GettingStartedWithAgents/OpenAIResponse/Step03_OpenAIResponseAgent_ReasoningModel.cs b/dotnet/samples/GettingStartedWithAgents/OpenAIResponse/Step03_OpenAIResponseAgent_ReasoningModel.cs index a88059222efb..7db3ecc847bf 100644 --- a/dotnet/samples/GettingStartedWithAgents/OpenAIResponse/Step03_OpenAIResponseAgent_ReasoningModel.cs +++ b/dotnet/samples/GettingStartedWithAgents/OpenAIResponse/Step03_OpenAIResponseAgent_ReasoningModel.cs @@ -2,6 +2,7 @@ using Microsoft.SemanticKernel; using Microsoft.SemanticKernel.Agents.OpenAI; using OpenAI.Responses; +using Plugins; namespace GettingStarted.OpenAIResponseAgents; @@ -80,4 +81,26 @@ exceed 80 columns WriteAgentChatMessage(responseItem); } } + + [Fact] + public async Task UseOpenAIResponseAgentWithAReasoningModelAndToolsAsync() + { + // Define the agent + OpenAIResponseAgent agent = new(this.Client) + { + Name = "ResponseAgent", + Instructions = "Answer all queries with a detailed response.", + }; + + // Create a plugin that defines the tools to be used by the agent. + KernelPlugin plugin = KernelPluginFactory.CreateFromType(); + agent.Kernel.Plugins.Add(plugin); + + // Invoke the agent and output the response + var responseItems = agent.InvokeAsync("What is the best value healthy meal?"); + await foreach (ChatMessageContent responseItem in responseItems) + { + WriteAgentChatMessage(responseItem); + } + } } diff --git a/dotnet/src/Agents/OpenAI/Internal/ResponseThreadActions.cs b/dotnet/src/Agents/OpenAI/Internal/ResponseThreadActions.cs index a7c7cc0b8cc4..b5112c2ba808 100644 --- a/dotnet/src/Agents/OpenAI/Internal/ResponseThreadActions.cs +++ b/dotnet/src/Agents/OpenAI/Internal/ResponseThreadActions.cs @@ -57,7 +57,9 @@ internal static async IAsyncEnumerable InvokeAsync( } else { - inputItems.AddRange(response.OutputItems); + var filteredItems = response.OutputItems + .Where(item => item is not ReasoningResponseItem); // Keep items that are not ReasoningResponseItem + inputItems.AddRange(filteredItems); } var message = response.ToChatMessageContent();