Skip to content

Commit 1774dd3

Browse files
.Net: Filter out reasoning response items during function calling (#13020)
### Motivation and Context Closes #12904 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
1 parent 701da3a commit 1774dd3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

dotnet/samples/GettingStartedWithAgents/OpenAIResponse/Step03_OpenAIResponseAgent_ReasoningModel.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.SemanticKernel;
33
using Microsoft.SemanticKernel.Agents.OpenAI;
44
using OpenAI.Responses;
5+
using Plugins;
56

67
namespace GettingStarted.OpenAIResponseAgents;
78

@@ -80,4 +81,26 @@ exceed 80 columns
8081
WriteAgentChatMessage(responseItem);
8182
}
8283
}
84+
85+
[Fact]
86+
public async Task UseOpenAIResponseAgentWithAReasoningModelAndToolsAsync()
87+
{
88+
// Define the agent
89+
OpenAIResponseAgent agent = new(this.Client)
90+
{
91+
Name = "ResponseAgent",
92+
Instructions = "Answer all queries with a detailed response.",
93+
};
94+
95+
// Create a plugin that defines the tools to be used by the agent.
96+
KernelPlugin plugin = KernelPluginFactory.CreateFromType<MenuPlugin>();
97+
agent.Kernel.Plugins.Add(plugin);
98+
99+
// Invoke the agent and output the response
100+
var responseItems = agent.InvokeAsync("What is the best value healthy meal?");
101+
await foreach (ChatMessageContent responseItem in responseItems)
102+
{
103+
WriteAgentChatMessage(responseItem);
104+
}
105+
}
83106
}

dotnet/src/Agents/OpenAI/Internal/ResponseThreadActions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ internal static async IAsyncEnumerable<ChatMessageContent> InvokeAsync(
5757
}
5858
else
5959
{
60-
inputItems.AddRange(response.OutputItems);
60+
var filteredItems = response.OutputItems
61+
.Where(item => item is not ReasoningResponseItem); // Keep items that are not ReasoningResponseItem
62+
inputItems.AddRange(filteredItems);
6163
}
6264

6365
var message = response.ToChatMessageContent();

0 commit comments

Comments
 (0)