From 66022eaa694a132608bef371873d7745fbe7d286 Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Wed, 22 Jan 2025 14:14:25 -0700 Subject: [PATCH 1/5] OpenAI skill trigger/Return value from pipeline --- src/PowerShell/PowerShellManager.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PowerShell/PowerShellManager.cs b/src/PowerShell/PowerShellManager.cs index 5bd506b5..12228170 100644 --- a/src/PowerShell/PowerShellManager.cs +++ b/src/PowerShell/PowerShellManager.cs @@ -16,6 +16,7 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.PowerShell { using Microsoft.Azure.Functions.PowerShellWorker.OpenTelemetry; + using System.Linq; using System.Management.Automation; using System.Text; @@ -247,7 +248,8 @@ public Hashtable InvokeFunction( { _pwsh.AddCommand(Utils.TracePipelineObjectCmdlet); } - return ExecuteUserCode(isActivityFunction, outputBindings); + var isOpenAiSkillTrigger = functionInfo.InputBindings.Where(x => x.Value.Type == "assistantSkillTrigger").Any(); + return ExecuteUserCode(isActivityFunction || isOpenAiSkillTrigger, outputBindings); } } catch (RuntimeException e) From 7d3077b2e627c0c701bd0506acde9c6c708df28f Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Wed, 22 Jan 2025 15:13:32 -0700 Subject: [PATCH 2/5] Bugfix, logic refactor --- src/FunctionInfoUtilities.cs | 19 +++++++++++++++++++ src/PowerShell/PowerShellManager.cs | 3 +-- src/RequestProcessor.cs | 3 ++- 3 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/FunctionInfoUtilities.cs diff --git a/src/FunctionInfoUtilities.cs b/src/FunctionInfoUtilities.cs new file mode 100644 index 00000000..30ba6f9d --- /dev/null +++ b/src/FunctionInfoUtilities.cs @@ -0,0 +1,19 @@ +// +// Copyright (c) Microsoft. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +using System.Linq; + +namespace Microsoft.Azure.Functions.PowerShellWorker +{ + internal class FunctionInfoUtilities + { + private const string assistantSkillTriggerName = "assistantSkillTrigger"; + + public static bool hasAssistantSkillTrigger(AzFunctionInfo info) + { + return info.InputBindings.Where(x => x.Value.Type == assistantSkillTriggerName).Any(); + } + } +} diff --git a/src/PowerShell/PowerShellManager.cs b/src/PowerShell/PowerShellManager.cs index 12228170..25955b9b 100644 --- a/src/PowerShell/PowerShellManager.cs +++ b/src/PowerShell/PowerShellManager.cs @@ -248,8 +248,7 @@ public Hashtable InvokeFunction( { _pwsh.AddCommand(Utils.TracePipelineObjectCmdlet); } - var isOpenAiSkillTrigger = functionInfo.InputBindings.Where(x => x.Value.Type == "assistantSkillTrigger").Any(); - return ExecuteUserCode(isActivityFunction || isOpenAiSkillTrigger, outputBindings); + return ExecuteUserCode(isActivityFunction || FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo), outputBindings); } } catch (RuntimeException e) diff --git a/src/RequestProcessor.cs b/src/RequestProcessor.cs index ee3378ad..4a34c18b 100644 --- a/src/RequestProcessor.cs +++ b/src/RequestProcessor.cs @@ -22,6 +22,7 @@ namespace Microsoft.Azure.Functions.PowerShellWorker using LogLevel = Microsoft.Azure.WebJobs.Script.Grpc.Messages.RpcLog.Types.Level; using System.Runtime.InteropServices; using Microsoft.Azure.Functions.PowerShellWorker.OpenTelemetry; + using System.Linq; internal class RequestProcessor { @@ -537,7 +538,7 @@ private static void BindOutputFromResult(InvocationResponse response, AzFunction } } - if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue) + if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue || functionInfo.InputBindings.Where(x => x.Value.Type == "assistantSkillTrigger").Any()) { response.ReturnValue = results[AzFunctionInfo.DollarReturn].ToTypedData(isDurableData: true); } From a45209c0d8fc2ca75a27e6d9a5c28140142503cf Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Wed, 22 Jan 2025 15:25:57 -0700 Subject: [PATCH 3/5] Remove unnecessary usings --- src/PowerShell/PowerShellManager.cs | 1 - src/RequestProcessor.cs | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/PowerShell/PowerShellManager.cs b/src/PowerShell/PowerShellManager.cs index 25955b9b..d423eedc 100644 --- a/src/PowerShell/PowerShellManager.cs +++ b/src/PowerShell/PowerShellManager.cs @@ -16,7 +16,6 @@ namespace Microsoft.Azure.Functions.PowerShellWorker.PowerShell { using Microsoft.Azure.Functions.PowerShellWorker.OpenTelemetry; - using System.Linq; using System.Management.Automation; using System.Text; diff --git a/src/RequestProcessor.cs b/src/RequestProcessor.cs index 4a34c18b..18fed1e1 100644 --- a/src/RequestProcessor.cs +++ b/src/RequestProcessor.cs @@ -22,7 +22,6 @@ namespace Microsoft.Azure.Functions.PowerShellWorker using LogLevel = Microsoft.Azure.WebJobs.Script.Grpc.Messages.RpcLog.Types.Level; using System.Runtime.InteropServices; using Microsoft.Azure.Functions.PowerShellWorker.OpenTelemetry; - using System.Linq; internal class RequestProcessor { @@ -538,7 +537,7 @@ private static void BindOutputFromResult(InvocationResponse response, AzFunction } } - if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue || functionInfo.InputBindings.Where(x => x.Value.Type == "assistantSkillTrigger").Any()) + if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue || FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo)) { response.ReturnValue = results[AzFunctionInfo.DollarReturn].ToTypedData(isDurableData: true); } From e0e3fd6af9ceb00898bc0fa773ddf831a7e49152 Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Wed, 5 Feb 2025 17:27:45 -0700 Subject: [PATCH 4/5] Add assistantSkillTrigger test - Ensure pipeline output is not logged for assistantSkillTrigger --- src/DurableWorker/DurableController.cs | 1 - src/PowerShell/PowerShellManager.cs | 2 +- .../Unit/PowerShell/PowerShellManagerTests.cs | 37 ++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/DurableWorker/DurableController.cs b/src/DurableWorker/DurableController.cs index 389643bc..efaaaf9c 100644 --- a/src/DurableWorker/DurableController.cs +++ b/src/DurableWorker/DurableController.cs @@ -144,7 +144,6 @@ public bool TryGetInputBindingParameterValue(string bindingName, out object valu public void AddPipelineOutputIfNecessary(Collection pipelineItems, Hashtable result) { - if (ShouldSuppressPipelineTraces()) { var returnValue = FunctionReturnValueBuilder.CreateReturnValueFromFunctionOutput(pipelineItems); diff --git a/src/PowerShell/PowerShellManager.cs b/src/PowerShell/PowerShellManager.cs index d423eedc..a8c506ac 100644 --- a/src/PowerShell/PowerShellManager.cs +++ b/src/PowerShell/PowerShellManager.cs @@ -243,7 +243,7 @@ public Hashtable InvokeFunction( else { var isActivityFunction = functionInfo.DurableFunctionInfo.IsActivityFunction; - if (!isActivityFunction) + if (!isActivityFunction && !FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo)) { _pwsh.AddCommand(Utils.TracePipelineObjectCmdlet); } diff --git a/test/Unit/PowerShell/PowerShellManagerTests.cs b/test/Unit/PowerShell/PowerShellManagerTests.cs index 5bceda4a..c84abd6f 100644 --- a/test/Unit/PowerShell/PowerShellManagerTests.cs +++ b/test/Unit/PowerShell/PowerShellManagerTests.cs @@ -392,7 +392,7 @@ public void LoggerContextIsSet() [InlineData(DurableFunctionType.None, false)] [InlineData(DurableFunctionType.OrchestrationFunction, false)] [InlineData(DurableFunctionType.ActivityFunction, true)] - internal void SuppressPipelineTracesForDurableActivityFunctionOnly(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces) + internal void SuppressPipelineTracesForDurableActivityFunction(DurableFunctionType durableFunctionType, bool shouldSuppressPipelineTraces) { s_testLogger.FullLog.Clear(); @@ -416,6 +416,41 @@ internal void SuppressPipelineTracesForDurableActivityFunctionOnly(DurableFuncti } } + [Theory] + [InlineData("httpTrigger", false)] + [InlineData("assistantSkillTrigger", true)] + internal void SuppressPipelineTracesForOpenAIAssistantSkillTrigger(string inputBindingType, bool shouldSuppressPipelineTraces) + { + s_testLogger.FullLog.Clear(); + + var path = Path.Join(s_funcDirectory, "testFunctionWithOutput.ps1"); + + foreach(var binding in s_functionLoadRequest.Metadata.Bindings) + { + if (binding.Value.Direction == BindingInfo.Types.Direction.In) + { + binding.Value.Type = inputBindingType; + } + } + + var (functionInfo, testManager) = PrepareFunction(path, string.Empty); + + try + { + FunctionMetadata.RegisterFunctionMetadata(testManager.InstanceId, functionInfo.OutputBindings); + + var result = testManager.InvokeFunction(functionInfo, null, null, null, CreateOrchestratorInputData(), new FunctionInvocationPerformanceStopwatch(), null); + + var relevantLogs = s_testLogger.FullLog.Where(message => message.StartsWith("Information: OUTPUT:")).ToList(); + var expected = shouldSuppressPipelineTraces ? new string[0] : new[] { "Information: OUTPUT: Hello" }; + Assert.Equal(expected, relevantLogs); + } + finally + { + FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId); + } + } + private static List CreateOrchestratorInputData() { var orchestrationContext = new OrchestrationContext From 079e583d8752097b85ce0c703503372658ee14e3 Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Fri, 7 Feb 2025 10:57:23 -0700 Subject: [PATCH 5/5] Fix test issue --- test/Unit/PowerShell/PowerShellManagerTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/Unit/PowerShell/PowerShellManagerTests.cs b/test/Unit/PowerShell/PowerShellManagerTests.cs index c84abd6f..6912de3c 100644 --- a/test/Unit/PowerShell/PowerShellManagerTests.cs +++ b/test/Unit/PowerShell/PowerShellManagerTests.cs @@ -425,11 +425,16 @@ internal void SuppressPipelineTracesForOpenAIAssistantSkillTrigger(string inputB var path = Path.Join(s_funcDirectory, "testFunctionWithOutput.ps1"); + BindingInfo bindingInfo = null; + string oldBindingType = ""; foreach(var binding in s_functionLoadRequest.Metadata.Bindings) { if (binding.Value.Direction == BindingInfo.Types.Direction.In) { + bindingInfo = binding.Value; + oldBindingType = binding.Value.Type; binding.Value.Type = inputBindingType; + break; } } @@ -448,6 +453,10 @@ internal void SuppressPipelineTracesForOpenAIAssistantSkillTrigger(string inputB finally { FunctionMetadata.UnregisterFunctionMetadata(testManager.InstanceId); + if (bindingInfo != null) + { + bindingInfo.Type = oldBindingType; + } } }