diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs index baa8188039..16969a23e4 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step01_Basics/Program.cs @@ -28,20 +28,21 @@ async Task SKAgentAsync() { Name = "Joker", Instructions = "You are good at telling jokes.", + StoreEnabled = true }; var agentOptions = new OpenAIResponseAgentInvokeOptions() { ResponseCreationOptions = new() { MaxOutputTokenCount = 1000 } }; - Microsoft.SemanticKernel.Agents.AgentThread? thread = new OpenAIResponseAgentThread(responseClient); + Microsoft.SemanticKernel.Agents.AgentThread? thread = null; await foreach (var item in agent.InvokeAsync(userInput, thread, agentOptions)) { + thread = item.Thread; Console.WriteLine(item.Message); } Console.WriteLine("---"); await foreach (var item in agent.InvokeStreamingAsync(userInput, thread, agentOptions)) { - // Thread need to be updated for subsequent calls thread = item.Thread; Console.Write(item.Message); } diff --git a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs index 01259834cf..0aafea7a73 100644 --- a/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/AzureOpenAIResponses/Step02_ReasoningModel/Program.cs @@ -53,8 +53,9 @@ async Task SKAgentAsync() .GetOpenAIResponseClient(deploymentName); OpenAIResponseAgent agent = new(responseClient) { - Name = "Joker", - Instructions = "You are good at telling jokes.", + Name = "Thinker", + Instructions = "You are good at thinking hard before answering.", + StoreEnabled = true }; var agentOptions = new OpenAIResponseAgentInvokeOptions() @@ -70,13 +71,12 @@ async Task SKAgentAsync() } }; - Microsoft.SemanticKernel.Agents.AgentThread? thread = new OpenAIResponseAgentThread(responseClient); + Microsoft.SemanticKernel.Agents.AgentThread? thread = null; await foreach (var item in agent.InvokeAsync(userInput, thread, agentOptions)) { + thread = item.Thread; foreach (var content in item.Message.Items) { - // Currently SK Responses Agent doesn't distinguish thinking from non-thinking content in non-streaming mode. - // SK Bugfix WIP: https://github.com/microsoft/semantic-kernel/issues/13046 if (content is ReasoningContent thinking) { Console.Write($"Thinking: \n{thinking}\n---\n"); @@ -97,7 +97,8 @@ async Task SKAgentAsync() foreach (var content in item.Message.Items) { // Currently SK Agent doesn't output thinking in streaming mode. - // SK Bugfix WIP: https://github.com/microsoft/semantic-kernel/issues/13046 + // SK Issue: https://github.com/microsoft/semantic-kernel/issues/13046 + // OpenAI SDK Issue: https://github.com/openai/openai-dotnet/issues/643 if (content is StreamingReasoningContent thinking) { Console.WriteLine($"Thinking: [{thinking}]"); @@ -118,7 +119,7 @@ async Task AFAgentAsync() var agent = new AzureOpenAIClient(new Uri(endpoint), new AzureCliCredential()) .GetOpenAIResponseClient(deploymentName) - .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes."); + .CreateAIAgent(name: "Thinker", instructions: "You are good at thinking hard before answering."); var thread = agent.GetNewThread(); var agentOptions = new ChatClientAgentRunOptions(new() diff --git a/dotnet/samples/SemanticKernelMigration/OpenAIResponses/Step01_Basics/Program.cs b/dotnet/samples/SemanticKernelMigration/OpenAIResponses/Step01_Basics/Program.cs index d88684e240..b8edd253b0 100644 --- a/dotnet/samples/SemanticKernelMigration/OpenAIResponses/Step01_Basics/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/OpenAIResponses/Step01_Basics/Program.cs @@ -25,14 +25,16 @@ async Task SKAgentAsync() { Name = "Joker", Instructions = "You are good at telling jokes.", + StoreEnabled = true }; var agentOptions = new OpenAIResponseAgentInvokeOptions() { ResponseCreationOptions = new() { MaxOutputTokenCount = 1000 } }; - Microsoft.SemanticKernel.Agents.AgentThread? thread = new OpenAIResponseAgentThread(responseClient); + Microsoft.SemanticKernel.Agents.AgentThread? thread = null; await foreach (var item in agent.InvokeAsync(userInput, thread, agentOptions)) { Console.WriteLine(item.Message); + thread = item.Thread; } Console.WriteLine("---"); diff --git a/dotnet/samples/SemanticKernelMigration/OpenAIResponses/Step02_ReasoningModel/Program.cs b/dotnet/samples/SemanticKernelMigration/OpenAIResponses/Step02_ReasoningModel/Program.cs index 818604fd64..b0ac702ad2 100644 --- a/dotnet/samples/SemanticKernelMigration/OpenAIResponses/Step02_ReasoningModel/Program.cs +++ b/dotnet/samples/SemanticKernelMigration/OpenAIResponses/Step02_ReasoningModel/Program.cs @@ -50,8 +50,9 @@ async Task SKAgentAsync() var responseClient = new OpenAIClient(apiKey).GetOpenAIResponseClient(modelId); OpenAIResponseAgent agent = new(responseClient) { - Name = "Joker", - Instructions = "You are good at telling jokes.", + Name = "Thinker", + Instructions = "You are good at thinking hard before answering.", + StoreEnabled = true }; var agentOptions = new OpenAIResponseAgentInvokeOptions() @@ -67,13 +68,12 @@ async Task SKAgentAsync() } }; - Microsoft.SemanticKernel.Agents.AgentThread? thread = new OpenAIResponseAgentThread(responseClient); + Microsoft.SemanticKernel.Agents.AgentThread? thread = null; await foreach (var item in agent.InvokeAsync(userInput, thread, agentOptions)) { + thread = item.Thread; foreach (var content in item.Message.Items) { - // Currently SK Responses Agent doesn't distinguish thinking from non-thinking content in non-streaming mode. - // SK Bugfix WIP: https://github.com/microsoft/semantic-kernel/issues/13046 if (content is ReasoningContent thinking) { Console.Write($"Thinking: \n{thinking}\n---\n"); @@ -88,13 +88,15 @@ async Task SKAgentAsync() Console.WriteLine("---"); var userMessage = new ChatMessageContent(AuthorRole.User, userInput); + thread = null; await foreach (var item in agent.InvokeStreamingAsync(userMessage, thread, agentOptions)) { thread = item.Thread; foreach (var content in item.Message.Items) { // Currently SK Agent doesn't output thinking in streaming mode. - // SK Bugfix WIP: https://github.com/microsoft/semantic-kernel/issues/13046 + // SK Issue: https://github.com/microsoft/semantic-kernel/issues/13046 + // OpenAI SDK Issue: https://github.com/openai/openai-dotnet/issues/643 if (content is StreamingReasoningContent thinking) { Console.WriteLine($"Thinking: [{thinking}]"); @@ -114,7 +116,7 @@ async Task AFAgentAsync() Console.WriteLine("\n=== AF Agent ===\n"); var agent = new OpenAIClient(apiKey).GetOpenAIResponseClient(modelId) - .CreateAIAgent(name: "Joker", instructions: "You are good at telling jokes."); + .CreateAIAgent(name: "Thinker", instructions: "You are at thinking hard before answering."); var thread = agent.GetNewThread(); var agentOptions = new ChatClientAgentRunOptions(new()