From b40e0cc0845f4501628e61707d46e57b753fa7ac Mon Sep 17 00:00:00 2001 From: Michael Landis Date: Thu, 12 Dec 2024 00:09:48 -0800 Subject: [PATCH] .Net: fix: add "status" field to Python dynamic session response (#9903) ### Motivation and Context Addresses issue #9902 for .NET. Include the "status" field in the response string returned by Python dynamic sessions. Fixes a usability issue where the LLM assumes success despite execution failures. ### Description As per #9902, including the `status` property from the response in the plugin result, we ensure that the LLM has explicit information about whether the execution succeeded or failed, preventing misinterpretation of stderr or other response elements. This helps avoid hallucinated follow-ups or unnecessary retries by providing clear success/failure indicators. ### Contribution Checklist - [x] The code builds clean without any errors or warnings - [x] 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 - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone :smile: --------- Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com> --- .../Plugins.Core/CodeInterpreter/SessionsPythonPlugin.cs | 2 ++ .../Plugins/Plugins.UnitTests/Core/SessionsPythonPluginTests.cs | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dotnet/src/Plugins/Plugins.Core/CodeInterpreter/SessionsPythonPlugin.cs b/dotnet/src/Plugins/Plugins.Core/CodeInterpreter/SessionsPythonPlugin.cs index c8094de65201..bebd972fe350 100644 --- a/dotnet/src/Plugins/Plugins.Core/CodeInterpreter/SessionsPythonPlugin.cs +++ b/dotnet/src/Plugins/Plugins.Core/CodeInterpreter/SessionsPythonPlugin.cs @@ -113,6 +113,8 @@ public async Task ExecuteCodeAsync([Description("The valid Python code t var jsonElementResult = JsonSerializer.Deserialize(await response.Content.ReadAsStringAsync().ConfigureAwait(false)); return $""" + Status: + {jsonElementResult.GetProperty("status").GetRawText()} Result: {jsonElementResult.GetProperty("result").GetRawText()} Stdout: diff --git a/dotnet/src/Plugins/Plugins.UnitTests/Core/SessionsPythonPluginTests.cs b/dotnet/src/Plugins/Plugins.UnitTests/Core/SessionsPythonPluginTests.cs index 789cd85fc353..f9a5e9fc1bcb 100644 --- a/dotnet/src/Plugins/Plugins.UnitTests/Core/SessionsPythonPluginTests.cs +++ b/dotnet/src/Plugins/Plugins.UnitTests/Core/SessionsPythonPluginTests.cs @@ -70,6 +70,8 @@ public async Task ItShouldExecuteCodeAsync() Content = new StringContent(responseContent), }; var expectedResult = """ + Status: + "Success" Result: "" Stdout: