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/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 5bd506b5..a8c506ac 100644 --- a/src/PowerShell/PowerShellManager.cs +++ b/src/PowerShell/PowerShellManager.cs @@ -243,11 +243,11 @@ public Hashtable InvokeFunction( else { var isActivityFunction = functionInfo.DurableFunctionInfo.IsActivityFunction; - if (!isActivityFunction) + if (!isActivityFunction && !FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo)) { _pwsh.AddCommand(Utils.TracePipelineObjectCmdlet); } - return ExecuteUserCode(isActivityFunction, outputBindings); + return ExecuteUserCode(isActivityFunction || FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo), outputBindings); } } catch (RuntimeException e) diff --git a/src/RequestProcessor.cs b/src/RequestProcessor.cs index ee3378ad..18fed1e1 100644 --- a/src/RequestProcessor.cs +++ b/src/RequestProcessor.cs @@ -537,7 +537,7 @@ private static void BindOutputFromResult(InvocationResponse response, AzFunction } } - if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue) + if (functionInfo.DurableFunctionInfo.ProvidesForcedDollarReturnValue || FunctionInfoUtilities.hasAssistantSkillTrigger(functionInfo)) { response.ReturnValue = results[AzFunctionInfo.DollarReturn].ToTypedData(isDurableData: true); } diff --git a/test/Unit/PowerShell/PowerShellManagerTests.cs b/test/Unit/PowerShell/PowerShellManagerTests.cs index 5bceda4a..6912de3c 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,50 @@ 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"); + + 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; + } + } + + 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); + if (bindingInfo != null) + { + bindingInfo.Type = oldBindingType; + } + } + } + private static List CreateOrchestratorInputData() { var orchestrationContext = new OrchestrationContext