diff --git a/dotnet/agent-framework-dotnet.slnx b/dotnet/agent-framework-dotnet.slnx index a4ffe13958..4a48c1b289 100644 --- a/dotnet/agent-framework-dotnet.slnx +++ b/dotnet/agent-framework-dotnet.slnx @@ -202,7 +202,6 @@ - diff --git a/dotnet/samples/03-workflows/Declarative/GenerateCode/GenerateCode.csproj b/dotnet/samples/03-workflows/Declarative/GenerateCode/GenerateCode.csproj deleted file mode 100644 index a85173d289..0000000000 --- a/dotnet/samples/03-workflows/Declarative/GenerateCode/GenerateCode.csproj +++ /dev/null @@ -1,30 +0,0 @@ - - - - Exe - net10.0 - enable - enable - 5ee045b0-aea3-4f08-8d31-32d1a6f8fed0 - $(NoWarn);CA1812 - - - - true - - - - - - - - - - - - - - - - - diff --git a/dotnet/samples/03-workflows/Declarative/GenerateCode/Program.cs b/dotnet/samples/03-workflows/Declarative/GenerateCode/Program.cs deleted file mode 100644 index 54c77d4077..0000000000 --- a/dotnet/samples/03-workflows/Declarative/GenerateCode/Program.cs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Diagnostics; -using Microsoft.Agents.AI.Workflows.Declarative; - -namespace Demo.DeclarativeEject; - -/// -/// HOW TO: Convert a workflow from a declartive (yaml based) definition to code. -/// -/// -/// Usage -/// Provide the path to the workflow definition file as the first argument. -/// All other arguments are intepreted as a queue of inputs. -/// When no input is queued, interactive input is requested from the console. -/// -internal sealed class Program -{ - public static void Main(string[] args) - { - Program program = new(args); - program.Execute(); - } - - private void Execute() - { - // Read and parse the declarative workflow. - Notify($"WORKFLOW: Parsing {Path.GetFullPath(this.WorkflowFile)}"); - - Stopwatch timer = Stopwatch.StartNew(); - - // Use DeclarativeWorkflowBuilder to generate code based on a YAML file. - string code = - DeclarativeWorkflowBuilder.Eject( - this.WorkflowFile, - DeclarativeWorkflowLanguage.CSharp, - workflowNamespace: "Demo.DeclarativeCode", - workflowPrefix: "Sample"); - - Notify($"\nWORKFLOW: Defined {timer.Elapsed}\n"); - - Console.WriteLine(code); - } - - private const string DefaultWorkflow = "Marketing.yaml"; - - private string WorkflowFile { get; } - - private Program(string[] args) - { - this.WorkflowFile = ParseWorkflowFile(args); - } - - private static string ParseWorkflowFile(string[] args) - { - string workflowFile = args.FirstOrDefault() ?? DefaultWorkflow; - - if (!File.Exists(workflowFile) && !Path.IsPathFullyQualified(workflowFile)) - { - string? repoFolder = GetRepoFolder(); - if (repoFolder is not null) - { - workflowFile = Path.Combine(repoFolder, "workflow-samples", workflowFile); - workflowFile = Path.ChangeExtension(workflowFile, ".yaml"); - } - } - - if (!File.Exists(workflowFile)) - { - throw new InvalidOperationException($"Unable to locate workflow: {Path.GetFullPath(workflowFile)}."); - } - - return workflowFile; - - static string? GetRepoFolder() - { - DirectoryInfo? current = new(Directory.GetCurrentDirectory()); - - while (current is not null) - { - if (Directory.Exists(Path.Combine(current.FullName, ".git"))) - { - return current.FullName; - } - - current = current.Parent; - } - - return null; - } - } - - private static void Notify(string message) - { - Console.ForegroundColor = ConsoleColor.Cyan; - try - { - Console.WriteLine(message); - } - finally - { - Console.ResetColor(); - } - } -} diff --git a/dotnet/samples/03-workflows/Declarative/GenerateCode/Properties/launchSettings.json b/dotnet/samples/03-workflows/Declarative/GenerateCode/Properties/launchSettings.json deleted file mode 100644 index 692664eb00..0000000000 --- a/dotnet/samples/03-workflows/Declarative/GenerateCode/Properties/launchSettings.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "profiles": { - "Marketing": { - "commandName": "Project", - "commandLineArgs": "\"Marketing.yaml\"" - }, - "MathChat": { - "commandName": "Project", - "commandLineArgs": "\"MathChat.yaml\"" - }, - "Question": { - "commandName": "Project", - "commandLineArgs": "\"Question.yaml\"" - }, - "Research": { - "commandName": "Project", - "commandLineArgs": "\"DeepResearch.yaml\"" - }, - "ResponseObject": { - "commandName": "Project", - "commandLineArgs": "\"ResponseObject.yaml\"" - }, - "UserInput": { - "commandName": "Project", - "commandLineArgs": "\"UserInput.yaml\"" - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ActionTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ActionTemplate.cs deleted file mode 100644 index aece124f66..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ActionTemplate.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.Extensions; -using Microsoft.Agents.AI.Workflows.Declarative.Interpreter; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal abstract class ActionTemplate : CodeTemplate, IModeledAction -{ - public string Id { get; private set; } = string.Empty; - - public string Name { get; private set; } = string.Empty; - - public string ParentId { get; private set; } = string.Empty; - - public bool UseAgentProvider { get; init; } - - protected TAction Initialize(TAction model) where TAction : DialogAction - { - this.Id = model.GetId(); - this.ParentId = model.GetParentId() ?? WorkflowActionVisitor.Steps.Root(); - this.Name = this.Id.FormatType(); - - return model; - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/AddConversationMessageTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/AddConversationMessageTemplate.cs deleted file mode 100644 index 0064483589..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/AddConversationMessageTemplate.cs +++ /dev/null @@ -1,395 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class AddConversationMessageTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Adds a new message to the specified agent conversation\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session, ResponseAgentProvider agentProvider) : ActionExe" + - "cutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " {"); - - EvaluateStringExpression(this.Model.ConversationId, "conversationId", isNullable: true); - this.Write("\n if (string.IsNullOrWhiteSpace(conversationId))\n {\n thr" + - "ow new DeclarativeActionException($\"Conversation identifier must be defined: {th" + - "is.Id}\");\n }\n ChatMessage newMessage = new(ChatRole."); - this.Write(this.ToStringHelper.ToStringWithCulture(FormatEnum(this.Model.Role, RoleMap))); - this.Write(", await this.GetContentAsync(context).ConfigureAwait(false)) { AdditionalProperti" + - "es = this.GetMetadata() };\n newMessage = await agentProvider.CreateMessag" + - "eAsync(conversationId, newMessage, cancellationToken).ConfigureAwait(false);"); - - AssignVariable(this.Message, "newMessage"); - - this.Write("\n return default;\n }\n\n private async ValueTask> Get" + - "ContentAsync(IWorkflowContext context)\n {\n List content = [" + - "];\n "); - - int index = 0; - foreach (AddConversationMessageContent content in this.Model.Content) - { - ++index; - EvaluateMessageTemplate(content.Value, $"contentValue{index}"); - AgentMessageContentType contentType = content.Type.Value; - if (contentType == AgentMessageContentType.ImageUrl) - { - this.Write("\n content.Add(UriContent(contentValue"); - this.Write(this.ToStringHelper.ToStringWithCulture(index)); - this.Write(", \"image/*\"));"); - - } - else if (contentType == AgentMessageContentType.ImageFile) - { - this.Write("\n content.Add(new HostedFileContent(contentValue"); - this.Write(this.ToStringHelper.ToStringWithCulture(index)); - this.Write("));"); - - } - else - { - this.Write("\n content.Add(new TextContent(contentValue"); - this.Write(this.ToStringHelper.ToStringWithCulture(index)); - this.Write("));"); - - } - } - this.Write("\n return content;\n }\n\n private AdditionalPropertiesDictionary? GetMe" + - "tadata()\n {"); - - EvaluateRecordExpression(this.Model.Metadata, "metadata"); - this.Write("\n\n if (metadata is null)\n {\n return null; \n }\n" + - "\n return new AdditionalPropertiesDictionary(metadata);\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateRecordExpression(ObjectExpression expression, string targetVariable) -{ - string resultTypeName = $"Dictionary()}?>?"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = null;"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" =\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue))); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(">(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateExpressionAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateExpressionAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - -void EvaluateStringExpression(StringExpression expression, string targetVariable, bool isNullable = false) -{ - string typeName = isNullable ? "string?" : "string"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(isNullable ? "null" : "string.Empty")); - -this.Write(";"); - - - } - else if (expression.IsLiteral) - { - if (expression.LiteralValue.Contains("\n")) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = \n \"\"\"\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.LiteralValue)); - -this.Write("\n \"\"\";"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.LiteralValue))); - -this.Write(";"); - - - } - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - -void EvaluateMessageTemplate(TemplateLine templateLine, string variableName) -{ - if (templateLine is not null) - { -this.Write("\n string "); - -this.Write(this.ToStringHelper.ToStringWithCulture(variableName)); - -this.Write(" =\n await context.FormatTemplateAsync(\n \"\"\""); - - - FormatMessageTemplate(templateLine); -this.Write("\n \"\"\");"); - - - } - else - { -this.Write("\n string? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(variableName)); - -this.Write(" = null;"); - - - } -} - -void FormatMessageTemplate(TemplateLine line) -{ - foreach (string text in line.ToTemplateString().ByLine()) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(text)); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/AddConversationMessageTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/AddConversationMessageTemplate.tt deleted file mode 100644 index d86b624ac9..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/AddConversationMessageTemplate.tt +++ /dev/null @@ -1,67 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Extensions" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateRecordExpressionTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateStringExpressionTemplate.tt" once="true" #> -<#@ include file="Snippets/FormatMessageTemplate.tt" once="true" #> -/// -/// Adds a new message to the specified agent conversation -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session, ResponseAgentProvider agentProvider) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - EvaluateStringExpression(this.Model.ConversationId, "conversationId", isNullable: true); #> - if (string.IsNullOrWhiteSpace(conversationId)) - { - throw new DeclarativeActionException($"Conversation identifier must be defined: {this.Id}"); - } - ChatMessage newMessage = new(ChatRole.<#= FormatEnum(this.Model.Role, RoleMap) #>, await this.GetContentAsync(context).ConfigureAwait(false)) { AdditionalProperties = this.GetMetadata() }; - newMessage = await agentProvider.CreateMessageAsync(conversationId, newMessage, cancellationToken).ConfigureAwait(false);<# - AssignVariable(this.Message, "newMessage"); - #> - return default; - } - - private async ValueTask> GetContentAsync(IWorkflowContext context) - { - List content = []; - <# - int index = 0; - foreach (AddConversationMessageContent content in this.Model.Content) - { - ++index; - EvaluateMessageTemplate(content.Value, $"contentValue{index}"); - AgentMessageContentType contentType = content.Type.Value; - if (contentType == AgentMessageContentType.ImageUrl) - {#> - content.Add(UriContent(contentValue<#= index #>, "image/*"));<# - } - else if (contentType == AgentMessageContentType.ImageFile) - {#> - content.Add(new HostedFileContent(contentValue<#= index #>));<# - } - else - {#> - content.Add(new TextContent(contentValue<#= index #>));<# - } - }#> - return content; - } - - private AdditionalPropertiesDictionary? GetMetadata() - {<# - EvaluateRecordExpression(this.Model.Metadata, "metadata"); #> - - if (metadata is null) - { - return null; - } - - return new AdditionalPropertiesDictionary(metadata); - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/AddConversationMessageTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/AddConversationMessageTemplateCode.cs deleted file mode 100644 index f1e8065de6..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/AddConversationMessageTemplateCode.cs +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Collections.Frozen; -using System.Collections.Generic; -using Microsoft.Agents.ObjectModel; -using Microsoft.Extensions.AI; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class AddConversationMessageTemplate -{ - public AddConversationMessageTemplate(AddConversationMessage model) - { - this.Model = this.Initialize(model); - this.Message = this.Model.Message?.Path; - this.UseAgentProvider = true; - } - - public AddConversationMessage Model { get; } - - public PropertyPath? Message { get; } - - public const string DefaultRole = nameof(ChatRole.User); - - public static readonly FrozenDictionary RoleMap = - new Dictionary() - { - [AgentMessageRoleWrapper.Get(AgentMessageRole.User)] = nameof(ChatRole.User), - [AgentMessageRoleWrapper.Get(AgentMessageRole.Agent)] = nameof(ChatRole.Assistant), - }.ToFrozenDictionary(); -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ClearAllVariablesTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ClearAllVariablesTemplate.cs deleted file mode 100644 index 0d87f1c739..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ClearAllVariablesTemplate.cs +++ /dev/null @@ -1,221 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using System.Collections.Generic; - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class ClearAllVariablesTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Reset all the state for the targeted variable scope.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " {"); - - EvaluateEnumExpression(this.Model.Variables, "targetScopeName", ScopeMap, isNullable: true); - this.Write("\n await context.QueueClearScopeAsync(targetScopeName).ConfigureAwait(false" + - ");\n\n return default;\n }\n}\n"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateEnumExpression( - EnumExpression expression, - string targetVariable, - IDictionary resultMap, - string defaultValue = null, - bool qualifyResult = false, - bool isNullable = false) - where TWrapper : EnumWrapper -{ - string resultType = $"{GetTypeAlias()}{(isNullable ? "?" : "")}"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatValue(defaultValue))); - -this.Write(";"); - - - } - else if (expression.IsLiteral) - { - resultMap.TryGetValue(expression.LiteralValue, out string resultValue); - if (qualifyResult) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("."); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultValue)); - -this.Write(";"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatValue(resultValue))); - -this.Write(";"); - - - } - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(">(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ClearAllVariablesTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ClearAllVariablesTemplate.tt deleted file mode 100644 index b86d189ddb..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ClearAllVariablesTemplate.tt +++ /dev/null @@ -1,21 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateEnumExpressionTemplate.tt" once="true" #> -/// -/// Reset all the state for the targeted variable scope. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - EvaluateEnumExpression(this.Model.Variables, "targetScopeName", ScopeMap, isNullable: true); #> - await context.QueueClearScopeAsync(targetScopeName).ConfigureAwait(false); - - return default; - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ClearAllVariablesTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ClearAllVariablesTemplateCode.cs deleted file mode 100644 index 9a23bfe1e0..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ClearAllVariablesTemplateCode.cs +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Collections.Frozen; -using System.Collections.Generic; -using Microsoft.Agents.AI.Workflows.Declarative.PowerFx; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class ClearAllVariablesTemplate -{ - public ClearAllVariablesTemplate(ClearAllVariables model) - { - this.Model = this.Initialize(model); - } - - public ClearAllVariables Model { get; } - - public static readonly FrozenDictionary ScopeMap = - new Dictionary() - { - [VariablesToClearWrapper.Get(VariablesToClear.AllGlobalVariables)] = VariableScopeNames.Global, - [VariablesToClearWrapper.Get(VariablesToClear.ConversationScopedVariables)] = WorkflowFormulaState.DefaultScopeName, - }.ToFrozenDictionary(); -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CodeTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CodeTemplate.cs deleted file mode 100644 index 814ea1b81d..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CodeTemplate.cs +++ /dev/null @@ -1,339 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.CodeDom.Compiler; -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using Microsoft.Agents.ObjectModel; -using Microsoft.Shared.Diagnostics; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal abstract class CodeTemplate -{ - private bool _endsWithNewline; - - private string CurrentIndentField { get; set; } = string.Empty; - - /// - /// Create the template output - /// - public abstract string TransformText(); - - #region Object Model helpers - - public static string VariableName(PropertyPath path) => Throw.IfNull(path.VariableName); - public static string VariableScope(PropertyPath path) => Throw.IfNull(path.NamespaceAlias); - - public static string FormatBoolValue(bool? value, bool defaultValue = false) => - value ?? defaultValue ? "true" : "false"; - - public static string FormatStringValue(string? value) - { - if (value is null) - { - return "null"; - } - - if (value.Contains('\n') || value.Contains('\r')) - { - return @$"""""""{Environment.NewLine}{value}{Environment.NewLine}"""""""; - } - - if (value.Contains('"') || value.Contains('\\')) - { - return @$"""""""{value}"""""""; - } - - return @$"""{value}"""; - } - - public static string FormatValue(string? value) - { - if (typeof(TValue) == typeof(string)) - { - return FormatStringValue(value); - } - - if (value is null) - { - return "null"; - } - - if (typeof(TValue).IsEnum) - { - return $"{typeof(TValue).Name}.{value}"; - } - - return $"{value}"; - } - - public static string FormatDataValue(DataValue value) => - value switch - { - BlankDataValue => "null", - BooleanDataValue booleanValue => FormatBoolValue(booleanValue.Value), - FloatDataValue decimalValue => $"{decimalValue.Value}", - NumberDataValue numberValue => $"{numberValue.Value}", - DateDataValue dateValue => $"new DateTime({dateValue.Value.Ticks}, DateTimeKind.{dateValue.Value.Kind})", - DateTimeDataValue datetimeValue => $"new DateTimeOffset({datetimeValue.Value.Ticks}, TimeSpan.FromTicks({datetimeValue.Value.Offset}))", - TimeDataValue timeValue => $"TimeSpan.FromTicks({timeValue.Value.Ticks})", - StringDataValue stringValue => FormatStringValue(stringValue.Value), - OptionDataValue optionValue => @$"""{optionValue.Value}""", - // Indenting is important here to make the generated code readable. Don't change it without testing the output. - RecordDataValue recordValue => - $""" - [ - {string.Join(",\n ", recordValue.Properties.Select(p => $"[\"{p.Key}\"] = {FormatDataValue(p.Value)}"))} - ] - """, - _ => throw new DeclarativeModelException($"Unable to format '{value.GetType().Name}'"), - }; - - public static TTarget FormatEnum(TSource value, IDictionary map, TTarget? defaultValue = default) - { - if (map.TryGetValue(value, out TTarget? target)) - { - return target; - } - - if (defaultValue is null) - { - throw new DeclarativeModelException($"No default value suppied for '{typeof(TTarget).Name}'"); - } - - return defaultValue; - } - - public static string GetTypeAlias() => GetTypeAlias(typeof(TValue)); - - public static string GetTypeAlias(Type type) - { - return type switch - { - Type t when t == typeof(bool) => "bool", - Type t when t == typeof(byte) => "byte", - Type t when t == typeof(sbyte) => "sbyte", - Type t when t == typeof(char) => "char", - Type t when t == typeof(decimal) => "decimal", - Type t when t == typeof(double) => "double", - Type t when t == typeof(float) => "float", - Type t when t == typeof(int) => "int", - Type t when t == typeof(uint) => "uint", - Type t when t == typeof(long) => "long", - Type t when t == typeof(ulong) => "ulong", - Type t when t == typeof(nint) => "nint", - Type t when t == typeof(nuint) => "nuint", - Type t when t == typeof(short) => "short", - Type t when t == typeof(ushort) => "ushort", - Type t when t == typeof(string) => "string", - Type t when t == typeof(object) => "object", - _ => type.Name - }; - } - #endregion - - #region Properties - /// - /// The string builder that generation-time code is using to assemble generated output - /// - public StringBuilder GenerationEnvironment - { - get - { - return field ??= new StringBuilder(); - } - set; - } - /// - /// The error collection for the generation process - /// - public CompilerErrorCollection Errors => field ??= []; - - /// - /// A list of the lengths of each indent that was added with PushIndent - /// - private List IndentLengths { get => field ??= []; } - - /// - /// Gets the current indent we use when adding lines to the output - /// - public string CurrentIndent - { - get - { - return this.CurrentIndentField; - } - } - /// - /// Current transformation session - /// - public virtual IDictionary? Session { get; set; } - - #endregion - - #region Transform-time helpers - - /// - /// Write text directly into the generated output - /// - public void Write(string textToAppend) - { - if (string.IsNullOrEmpty(textToAppend)) - { - return; - } - // If we're starting off, or if the previous text ended with a newline, - // we have to append the current indent first. - if ((this.GenerationEnvironment.Length == 0) - || this._endsWithNewline) - { - this.GenerationEnvironment.Append(this.CurrentIndentField); - this._endsWithNewline = false; - } - // Check if the current text ends with a newline - if (textToAppend.EndsWith(Environment.NewLine, StringComparison.CurrentCulture)) - { - this._endsWithNewline = true; - } - // This is an optimization. If the current indent is "", then we don't have to do any - // of the more complex stuff further down. - if (this.CurrentIndentField.Length == 0) - { - this.GenerationEnvironment.Append(textToAppend); - return; - } - // Everywhere there is a newline in the text, add an indent after it - textToAppend = textToAppend.Replace(Environment.NewLine, Environment.NewLine + this.CurrentIndentField); - // If the text ends with a newline, then we should strip off the indent added at the very end - // because the appropriate indent will be added when the next time Write() is called - if (this._endsWithNewline) - { - this.GenerationEnvironment.Append(textToAppend, 0, textToAppend.Length - this.CurrentIndentField.Length); - } - else - { - this.GenerationEnvironment.Append(textToAppend); - } - } - - /// - /// Write text directly into the generated output - /// - public void WriteLine(string textToAppend) - { - this.Write(textToAppend); - this.GenerationEnvironment.AppendLine(); - this._endsWithNewline = true; - } - - /// - /// Write formatted text directly into the generated output - /// - public void Write(string format, params object[] args) - { - this.Write(string.Format(CultureInfo.CurrentCulture, format, args)); - } - - /// - /// Write formatted text directly into the generated output - /// - public void WriteLine(string format, params object[] args) - { - this.WriteLine(string.Format(CultureInfo.CurrentCulture, format, args)); - } - - /// - /// Raise an error - /// - public void Error(string message) - { - CompilerError error = new() - { - ErrorText = message - }; - this.Errors.Add(error); - } - - /// - /// Raise a warning - /// - public void Warning(string message) - { - CompilerError error = new() - { - ErrorText = message, - IsWarning = true - }; - error.ErrorText = message; - error.IsWarning = true; - this.Errors.Add(error); - } - - /// - /// Increase the indent - /// - public void PushIndent(string indent) - { - if (indent is null) - { - throw new ArgumentNullException(nameof(indent)); - } - this.CurrentIndentField += indent; - this.IndentLengths.Add(indent.Length); - } - - /// - /// Remove the last indent that was added with PushIndent - /// - public string PopIndent() - { - string returnValue = string.Empty; - if (this.IndentLengths.Count > 0) - { - int indentLength = this.IndentLengths[this.IndentLengths.Count - 1]; - this.IndentLengths.RemoveAt(this.IndentLengths.Count - 1); - if (indentLength > 0) - { - returnValue = this.CurrentIndentField.Substring(this.CurrentIndentField.Length - indentLength); - this.CurrentIndentField = this.CurrentIndentField.Remove(this.CurrentIndentField.Length - indentLength); - } - } - return returnValue; - } - - /// - /// Remove any indentation - /// - public void ClearIndent() - { - this.IndentLengths.Clear(); - this.CurrentIndentField = string.Empty; - } - - #endregion - - #region ToString Helpers - - /// - /// Utility class to produce culture-oriented representation of an object as a string. - /// - public sealed class ToStringInstanceHelper - { - /// - /// This is called from the compile/run appdomain to convert objects within an expression block to a string - /// -#pragma warning disable CA1822 // Required to be non-static for use in generated code - public string ToStringWithCulture(object objectToConvert) => $"{objectToConvert}"; -#pragma warning restore CA1822 - } - - /// - /// Helper to produce culture-oriented representation of an object as a string - /// - public ToStringInstanceHelper ToStringHelper { get; } = new(); - - #endregion -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ConditionGroupTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ConditionGroupTemplate.cs deleted file mode 100644 index eabaff77d8..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ConditionGroupTemplate.cs +++ /dev/null @@ -1,172 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.AI.Workflows.Declarative.ObjectModel; - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class ConditionGroupTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Conditional branching similar to an if / elseif / elseif / els" + - "e chain.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " {"); - - for (int index = 0; index < this.Model.Conditions.Length; ++index) - { - ConditionItem conditionItem = this.Model.Conditions[index]; - if (conditionItem.Condition is null) - { - continue; // Skip if no condition is defined - } - - EvaluateBoolExpression(conditionItem.Condition, $"condition{index}"); - this.Write("\n if (condition"); - this.Write(this.ToStringHelper.ToStringWithCulture(index)); - this.Write(")\n {\n return \""); - this.Write(this.ToStringHelper.ToStringWithCulture(ConditionGroupExecutor.Steps.Item(this.Model, conditionItem))); - this.Write("\";\n }\n "); - - } - - this.Write("\n return \""); - this.Write(this.ToStringHelper.ToStringWithCulture(ConditionGroupExecutor.Steps.Else(this.Model))); - this.Write("\";\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateBoolExpression(BoolExpression expression, string targetVariable, bool defaultValue = false) -{ - if (expression is null) - { -this.Write("\n bool "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatBoolValue(defaultValue))); - -this.Write(";"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n bool "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatBoolValue(expression.LiteralValue))); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n bool "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n bool "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync>("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n bool "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ConditionGroupTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ConditionGroupTemplate.tt deleted file mode 100644 index 37ec8863f1..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ConditionGroupTemplate.tt +++ /dev/null @@ -1,34 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.ObjectModel" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateBoolExpressionTemplate.tt" once="true" #> -/// -/// Conditional branching similar to an if / elseif / elseif / else chain. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - for (int index = 0; index < this.Model.Conditions.Length; ++index) - { - ConditionItem conditionItem = this.Model.Conditions[index]; - if (conditionItem.Condition is null) - { - continue; // Skip if no condition is defined - } - - EvaluateBoolExpression(conditionItem.Condition, $"condition{index}");#> - if (condition<#= index #>) - { - return "<#= ConditionGroupExecutor.Steps.Item(this.Model, conditionItem)#>"; - } - <# - } - #> - return "<#= ConditionGroupExecutor.Steps.Else(this.Model)#>"; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ConditionGroupTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ConditionGroupTemplateCode.cs deleted file mode 100644 index 81d79ae0ea..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ConditionGroupTemplateCode.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class ConditionGroupTemplate -{ - public ConditionGroupTemplate(ConditionGroup model) - { - this.Model = this.Initialize(model); - } - - public ConditionGroup Model { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CopyConversationMessagesTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CopyConversationMessagesTemplate.cs deleted file mode 100644 index 78fadd1982..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CopyConversationMessagesTemplate.cs +++ /dev/null @@ -1,324 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.ObjectModel; - using Microsoft.Extensions.AI; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class CopyConversationMessagesTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Copies one or more messages into the specified agent conversat" + - "ion.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session, ResponseAgentProvider agentProvider) : ActionExe" + - "cutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " {"); - - EvaluateStringExpression(this.Model.ConversationId, "conversationId", isNullable: true); - this.Write("\n if (string.IsNullOrWhiteSpace(conversationId))\n {\n thr" + - "ow new DeclarativeActionException($\"Conversation identifier must be defined: {th" + - "is.Id}\");\n }"); - - EvaluateValueExpression(this.Model.Messages, "messages"); - - this.Write(@" - if (messages is not null) - { - foreach (ChatMessage message in messages) - { - await agentProvider.CreateMessageAsync(conversationId, message, cancellationToken).ConfigureAwait(false); - } - } - return default; - } -}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateStringExpression(StringExpression expression, string targetVariable, bool isNullable = false) -{ - string typeName = isNullable ? "string?" : "string"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(isNullable ? "null" : "string.Empty")); - -this.Write(";"); - - - } - else if (expression.IsLiteral) - { - if (expression.LiteralValue.Contains("\n")) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = \n \"\"\"\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.LiteralValue)); - -this.Write("\n \"\"\";"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.LiteralValue))); - -this.Write(";"); - - - } - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - -void EvaluateValueExpression(ValueExpression expression, string targetVariable) => - EvaluateValueExpression(expression, targetVariable); - -void EvaluateValueExpression(ValueExpression expression, string targetVariable) -{ - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = null;"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue))); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CopyConversationMessagesTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CopyConversationMessagesTemplate.tt deleted file mode 100644 index b1bbcabb8c..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CopyConversationMessagesTemplate.tt +++ /dev/null @@ -1,33 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ import namespace="Microsoft.Extensions.AI" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateStringExpressionTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateValueExpressionTemplate.tt" once="true" #> -/// -/// Copies one or more messages into the specified agent conversation. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session, ResponseAgentProvider agentProvider) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - EvaluateStringExpression(this.Model.ConversationId, "conversationId", isNullable: true); #> - if (string.IsNullOrWhiteSpace(conversationId)) - { - throw new DeclarativeActionException($"Conversation identifier must be defined: {this.Id}"); - }<# - EvaluateValueExpression(this.Model.Messages, "messages"); - #> - if (messages is not null) - { - foreach (ChatMessage message in messages) - { - await agentProvider.CreateMessageAsync(conversationId, message, cancellationToken).ConfigureAwait(false); - } - } - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CopyConversationMessagesTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CopyConversationMessagesTemplateCode.cs deleted file mode 100644 index 74d0a38130..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CopyConversationMessagesTemplateCode.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class CopyConversationMessagesTemplate -{ - public CopyConversationMessagesTemplate(CopyConversationMessages model) - { - this.Model = this.Initialize(model); - this.UseAgentProvider = true; - } - - public CopyConversationMessages Model { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CreateConversationTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CreateConversationTemplate.cs deleted file mode 100644 index 58d4217285..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CreateConversationTemplate.cs +++ /dev/null @@ -1,78 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class CreateConversationTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Creates a new conversation and stores the identifier value to " + - "the \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Model.ConversationId)); - this.Write("\" variable.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session, ResponseAgentProvider agentProvider) : ActionExe" + - "cutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write(@""", session) -{ - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { - string conversationId = await agentProvider.CreateConversationAsync(cancellationToken).ConfigureAwait(false);"); - - AssignVariable(this.ConversationId, "conversationId"); - this.Write("\n await context.AddEventAsync(new ConversationUpdateEvent(conversationId))" + - ".ConfigureAwait(false);\n\n return default;\n }\n}\n"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CreateConversationTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CreateConversationTemplate.tt deleted file mode 100644 index c2e2ebd786..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CreateConversationTemplate.tt +++ /dev/null @@ -1,19 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -/// -/// Creates a new conversation and stores the identifier value to the "<#= this.Model.ConversationId #>" variable. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session, ResponseAgentProvider agentProvider) : ActionExecutor(id: "<#= this.Id #>", session) -{ - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { - string conversationId = await agentProvider.CreateConversationAsync(cancellationToken).ConfigureAwait(false);<# - AssignVariable(this.ConversationId, "conversationId");#> - await context.AddEventAsync(new ConversationUpdateEvent(conversationId)).ConfigureAwait(false); - - return default; - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CreateConversationTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CreateConversationTemplateCode.cs deleted file mode 100644 index cddc9fab22..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/CreateConversationTemplateCode.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; -using Microsoft.Shared.Diagnostics; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class CreateConversationTemplate -{ - public CreateConversationTemplate(CreateConversation model) - { - this.Model = this.Initialize(model); - this.ConversationId = Throw.IfNull(this.Model.ConversationId); - this.UseAgentProvider = true; - } - - public CreateConversation Model { get; } - - public PropertyPath ConversationId { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/DefaultTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/DefaultTemplate.cs deleted file mode 100644 index afb0cc5f1d..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/DefaultTemplate.cs +++ /dev/null @@ -1,40 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.AI.Workflows.Declarative.Interpreter; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class DefaultTemplate : ActionTemplate, IModeledAction - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\nDelegateExecutor "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.InstanceVariable)); - this.Write(" = new(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.RootVariable)); - this.Write(".Session"); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Action is not null ? $", {this.Action}" : "")); - this.Write(");\n"); - return this.GenerationEnvironment.ToString(); - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/DefaultTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/DefaultTemplate.tt deleted file mode 100644 index 286f2e2241..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/DefaultTemplate.tt +++ /dev/null @@ -1,4 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate, IModeledAction" visibility="internal" linePragmas="false" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Interpreter" #> -<#@ assembly name="System.Core" #> -DelegateExecutor <#= this.InstanceVariable #> = new(id: "<#= this.Id #>", <#= this.RootVariable #>.Session<#= this.Action is not null ? $", {this.Action}" : "" #>); diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/DefaultTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/DefaultTemplateCode.cs deleted file mode 100644 index 44ae876902..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/DefaultTemplateCode.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.Extensions; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class DefaultTemplate -{ - public DefaultTemplate(DialogAction model, string rootId, string? action = null) - { - this.Initialize(model); - this.Action = action; - this.InstanceVariable = this.Id.FormatName(); - this.RootVariable = rootId.FormatName(); - } - - public string? Action { get; } - public string InstanceVariable { get; } - public string RootVariable { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EdgeTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EdgeTemplate.cs deleted file mode 100644 index e4243c3899..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EdgeTemplate.cs +++ /dev/null @@ -1,51 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class EdgeTemplate : CodeTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - if (this.Condition is not null) -{ - this.Write("\n builder.AddEdge("); - this.Write(this.ToStringHelper.ToStringWithCulture(this.SourceId)); - this.Write(", "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.TargetId)); - this.Write(", (object? result) => "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Condition)); - this.Write(");"); - -} -else -{ - this.Write("\n builder.AddEdge("); - this.Write(this.ToStringHelper.ToStringWithCulture(this.SourceId)); - this.Write(", "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.TargetId)); - this.Write(");"); - -} - this.Write("\n"); - return this.GenerationEnvironment.ToString(); - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EdgeTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EdgeTemplate.tt deleted file mode 100644 index 258cafdaf7..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EdgeTemplate.tt +++ /dev/null @@ -1,10 +0,0 @@ -<#@ template language="C#" inherits="CodeTemplate" visibility="internal" linePragmas="false" #> -<#@ assembly name="System.Core" #> -<# if (this.Condition is not null) -{#> - builder.AddEdge(<#= this.SourceId #>, <#= this.TargetId #>, (object? result) => <#= this.Condition #>);<# -} -else -{#> - builder.AddEdge(<#= this.SourceId #>, <#= this.TargetId #>);<# -} #> diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EdgeTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EdgeTemplateCode.cs deleted file mode 100644 index 7e6c93b1ff..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EdgeTemplateCode.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class EdgeTemplate -{ - public EdgeTemplate(string sourceId, string targetId, string? condition = null) - { - this.SourceId = sourceId.FormatName(); - this.TargetId = targetId.FormatName(); - this.Condition = condition; - } - - public string SourceId { get; } - public string TargetId { get; } - public string? Condition { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EditTableV2Template.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EditTableV2Template.cs deleted file mode 100644 index a05ddba863..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EditTableV2Template.cs +++ /dev/null @@ -1,37 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class EditTableV2Template : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Modify items in a list\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " {\n return default;\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EditTableV2Template.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EditTableV2Template.tt deleted file mode 100644 index e783089c51..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EditTableV2Template.tt +++ /dev/null @@ -1,14 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -/// -/// Modify items in a list -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EditTableV2TemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EditTableV2TemplateCode.cs deleted file mode 100644 index d8ec7abb21..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EditTableV2TemplateCode.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class EditTableV2Template -{ - public EditTableV2Template(EditTableV2 model) - { - this.Model = this.Initialize(model); - } - - public EditTableV2 Model { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EmptyTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EmptyTemplate.cs deleted file mode 100644 index d37bd2d56a..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EmptyTemplate.cs +++ /dev/null @@ -1,40 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.AI.Workflows.Declarative.Interpreter; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class EmptyTemplate : CodeTemplate, IModeledAction - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\nDelegateExecutor "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.InstanceVariable)); - this.Write(" = new(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.RootVariable)); - this.Write(".Session"); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Action is not null ? $", {this.Action}" : "")); - this.Write(");\n"); - return this.GenerationEnvironment.ToString(); - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EmptyTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EmptyTemplate.tt deleted file mode 100644 index bd643034e9..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EmptyTemplate.tt +++ /dev/null @@ -1,4 +0,0 @@ -<#@ template language="C#" inherits="CodeTemplate, IModeledAction" visibility="internal" linePragmas="false" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Interpreter" #> -<#@ assembly name="System.Core" #> -DelegateExecutor <#= this.InstanceVariable #> = new(id: "<#= this.Id #>", <#= this.RootVariable #>.Session<#= this.Action is not null ? $", {this.Action}" : "" #>); diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EmptyTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EmptyTemplateCode.cs deleted file mode 100644 index 24f2064fbb..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/EmptyTemplateCode.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class EmptyTemplate -{ - public EmptyTemplate(string actionId, string rootId, string? action = null) - { - this.Id = actionId; - this.Name = this.Id.FormatType(); - this.InstanceVariable = this.Id.FormatName(); - this.RootVariable = rootId.FormatName(); - this.Action = action; - } - - public string Id { get; } - public string Name { get; } - public string InstanceVariable { get; } - public string RootVariable { get; } - public string? Action { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ForeachTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ForeachTemplate.cs deleted file mode 100644 index de779128f5..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ForeachTemplate.cs +++ /dev/null @@ -1,250 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class ForeachTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Loops over a list assignign the loop variable to \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Model.Value)); - this.Write("\" variable.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write(@""", session) -{ - private int _index; - private object[] _values = []; - - public bool HasValue { get; private set; } - - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { - this._index = 0;"); - - - EvaluateValueExpression(this.Model.Items, "evaluatedValue"); - this.Write(@" - - if (evaluatedValue == null) - { - this._values = []; - this.HasValue = false; - } - else - if (evaluatedValue is IEnumerable evaluatedList) - { - this._values = [.. evaluatedList]; - } - else - { - this._values = [evaluatedValue]; - } - - await this.ResetAsync(context, cancellationToken).ConfigureAwait(false); - - return default; - } - - public async ValueTask TakeNextAsync(IWorkflowContext context, object? _, CancellationToken cancellationToken) - { - if (this.HasValue = this._index < this._values.Length) - { - object value = this._values[this._index]; - "); - - AssignVariable(this.Value, "value", tightFormat: true); - - if (this.Index is not null) - { - AssignVariable(this.Index, "this._index", tightFormat: true); - } - - this.Write(@" - - this._index++; - } - } - - public async ValueTask CompleteAsync(IWorkflowContext context, object? _, CancellationToken cancellationToken) - { - await this.ResetAsync(context, cancellationToken).ConfigureAwait(false); - } - - private async ValueTask ResetAsync(IWorkflowContext context, CancellationToken cancellationToken) - {"); - - AssignVariable(this.Value, "UnassignedValue.Instance", tightFormat: true); - - if (this.Index is not null) - { - AssignVariable(this.Index, "UnassignedValue.Instance", tightFormat: true); - } - - this.Write("\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateValueExpression(ValueExpression expression, string targetVariable) => - EvaluateValueExpression(expression, targetVariable); - -void EvaluateValueExpression(ValueExpression expression, string targetVariable) -{ - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = null;"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue))); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ForeachTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ForeachTemplate.tt deleted file mode 100644 index 8a9c8d5910..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ForeachTemplate.tt +++ /dev/null @@ -1,77 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateValueExpressionTemplate.tt" once="true" #> -/// -/// Loops over a list assignign the loop variable to "<#= this.Model.Value #>" variable. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - private int _index; - private object[] _values = []; - - public bool HasValue { get; private set; } - - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { - this._index = 0;<# - - EvaluateValueExpression(this.Model.Items, "evaluatedValue");#> - - if (evaluatedValue == null) - { - this._values = []; - this.HasValue = false; - } - else - if (evaluatedValue is IEnumerable evaluatedList) - { - this._values = [.. evaluatedList]; - } - else - { - this._values = [evaluatedValue]; - } - - await this.ResetAsync(context, cancellationToken).ConfigureAwait(false); - - return default; - } - - public async ValueTask TakeNextAsync(IWorkflowContext context, object? _, CancellationToken cancellationToken) - { - if (this.HasValue = this._index < this._values.Length) - { - object value = this._values[this._index]; - <# - AssignVariable(this.Value, "value", tightFormat: true); - - if (this.Index is not null) - { - AssignVariable(this.Index, "this._index", tightFormat: true); - } - #> - - this._index++; - } - } - - public async ValueTask CompleteAsync(IWorkflowContext context, object? _, CancellationToken cancellationToken) - { - await this.ResetAsync(context, cancellationToken).ConfigureAwait(false); - } - - private async ValueTask ResetAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - AssignVariable(this.Value, "UnassignedValue.Instance", tightFormat: true); - - if (this.Index is not null) - { - AssignVariable(this.Index, "UnassignedValue.Instance", tightFormat: true); - } - #> - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ForeachTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ForeachTemplateCode.cs deleted file mode 100644 index 9ab4418e28..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ForeachTemplateCode.cs +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; -using Microsoft.Shared.Diagnostics; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class ForeachTemplate -{ - public ForeachTemplate(Foreach model) - { - this.Model = this.Initialize(model); - this.Index = this.Model.Index?.Path; - this.Value = Throw.IfNull(this.Model.Value); - } - - public Foreach Model { get; } - public PropertyPath? Index { get; } - public PropertyPath Value { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InstanceTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InstanceTemplate.cs deleted file mode 100644 index 8a249c419d..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InstanceTemplate.cs +++ /dev/null @@ -1,38 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class InstanceTemplate : CodeTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write(this.ToStringHelper.ToStringWithCulture(this.ExecutorType)); - this.Write("Executor "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.InstanceVariable)); - this.Write(" = new("); - this.Write(this.ToStringHelper.ToStringWithCulture(this.RootVariable)); - this.Write(".Session"); - this.Write(this.ToStringHelper.ToStringWithCulture(this.HasProvider ? ", options.AgentProvider" : "")); - this.Write(");"); - return this.GenerationEnvironment.ToString(); - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InstanceTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InstanceTemplate.tt deleted file mode 100644 index baf1932baa..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InstanceTemplate.tt +++ /dev/null @@ -1,3 +0,0 @@ -<#@ template language="C#" inherits="CodeTemplate" visibility="internal" linePragmas="false" #> -<#@ assembly name="System.Core" #> -<#= this.ExecutorType #>Executor <#= this.InstanceVariable #> = new(<#= this.RootVariable #>.Session<#= this.HasProvider ? ", options.AgentProvider" : "" #>); \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InstanceTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InstanceTemplateCode.cs deleted file mode 100644 index 0be236e824..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InstanceTemplateCode.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class InstanceTemplate -{ - public InstanceTemplate(string executorId, string rootId, bool hasProvider = false) - { - this.InstanceVariable = executorId.FormatName(); - this.ExecutorType = executorId.FormatType(); - this.RootVariable = rootId.FormatName(); - this.HasProvider = hasProvider; - } - - public string InstanceVariable { get; } - public string ExecutorType { get; } - public string RootVariable { get; } - public bool HasProvider { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InvokeAzureAgentTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InvokeAzureAgentTemplate.cs deleted file mode 100644 index beb3634df3..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InvokeAzureAgentTemplate.cs +++ /dev/null @@ -1,415 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using System.Collections.Generic; - using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - using Microsoft.Agents.ObjectModel; - using Microsoft.Extensions.AI; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class InvokeAzureAgentTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Invokes an agent to process messages and return a response wit" + - "hin a conversation context.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session, ResponseAgentProvider agentProvider) : AgentExec" + - "utor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session, agentProvider)\n{\n // \n protected override async V" + - "alueTask ExecuteAsync(IWorkflowContext context, CancellationToken cance" + - "llationToken)\n {"); - - EvaluateStringExpression(this.Model.Agent.Name, "agentName", isNullable: true); - this.Write("\n\n if (string.IsNullOrWhiteSpace(agentName))\n {\n throw n" + - "ew DeclarativeActionException($\"Agent name must be defined: {this.Id}\");\n " + - " }\n "); - - EvaluateStringExpression(this.Model.ConversationId, "conversationId", isNullable: true); - EvaluateBoolExpression(this.Model.Output?.AutoSend, "autoSend", defaultValue: true); - EvaluateListExpression(this.Model.Input?.Messages, "inputMessages"); - this.Write(@" - - AgentResponse agentResponse = - await InvokeAgentAsync( - context, - agentName, - conversationId, - autoSend, - inputMessages, - cancellationToken).ConfigureAwait(false); - - if (autoSend) - { - await context.AddEventAsync(new AgentResponseEvent(this.Id, agentResponse)).ConfigureAwait(false); - } - "); - - AssignVariable(this.Messages, "agentResponse.Messages"); - this.Write("\n return default;\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateBoolExpression(BoolExpression expression, string targetVariable, bool defaultValue = false) -{ - if (expression is null) - { -this.Write("\n bool "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatBoolValue(defaultValue))); - -this.Write(";"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n bool "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatBoolValue(expression.LiteralValue))); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n bool "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n bool "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync>("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n bool "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - -void EvaluateListExpression(ValueExpression expression, string targetVariable) -{ - string typeName = GetTypeAlias(); - if (expression is null) - { -this.Write("\n IList<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(">? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = null;"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n IList<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(">? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue))); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n IList<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(">? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadListAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n IList<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(">? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write("> = await context.EvaluateListAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n IList<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(">? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateListAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - -void EvaluateStringExpression(StringExpression expression, string targetVariable, bool isNullable = false) -{ - string typeName = isNullable ? "string?" : "string"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(isNullable ? "null" : "string.Empty")); - -this.Write(";"); - - - } - else if (expression.IsLiteral) - { - if (expression.LiteralValue.Contains("\n")) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = \n \"\"\"\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.LiteralValue)); - -this.Write("\n \"\"\";"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.LiteralValue))); - -this.Write(";"); - - - } - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InvokeAzureAgentTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InvokeAzureAgentTemplate.tt deleted file mode 100644 index 7c86a2de2f..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InvokeAzureAgentTemplate.tt +++ /dev/null @@ -1,48 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Extensions" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ import namespace="Microsoft.Extensions.AI" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateBoolExpressionTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateListExpressionTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateStringExpressionTemplate.tt" once="true" #> -/// -/// Invokes an agent to process messages and return a response within a conversation context. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session, ResponseAgentProvider agentProvider) : AgentExecutor(id: "<#= this.Id #>", session, agentProvider) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - EvaluateStringExpression(this.Model.Agent.Name, "agentName", isNullable: true);#> - - if (string.IsNullOrWhiteSpace(agentName)) - { - throw new DeclarativeActionException($"Agent name must be defined: {this.Id}"); - } - <# - EvaluateStringExpression(this.Model.ConversationId, "conversationId", isNullable: true); - EvaluateBoolExpression(this.Model.Output?.AutoSend, "autoSend", defaultValue: true); - EvaluateListExpression(this.Model.Input?.Messages, "inputMessages");#> - - AgentResponse agentResponse = - await InvokeAgentAsync( - context, - agentName, - conversationId, - autoSend, - inputMessages, - cancellationToken).ConfigureAwait(false); - - if (autoSend) - { - await context.AddEventAsync(new AgentResponseEvent(this.Id, agentResponse)).ConfigureAwait(false); - } - <# - AssignVariable(this.Messages, "agentResponse.Messages"); #> - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InvokeAzureAgentTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InvokeAzureAgentTemplateCode.cs deleted file mode 100644 index 92379e57f6..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/InvokeAzureAgentTemplateCode.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class InvokeAzureAgentTemplate -{ - public InvokeAzureAgentTemplate(InvokeAzureAgent model) - { - this.Model = this.Initialize(model); - this.Messages = this.Model.Output?.Messages?.Path; - this.UseAgentProvider = true; - } - - public InvokeAzureAgent Model { get; } - - public PropertyPath? Messages { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ParseValueTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ParseValueTemplate.cs deleted file mode 100644 index 4572f39973..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ParseValueTemplate.cs +++ /dev/null @@ -1,99 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class ParseValueTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Parses a string or untyped value to the provided data type. Wh" + - "en the input is a string, it will be treated as JSON.\n/// \ninternal se" + - "aled class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " { \n VariableType targetType = "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.GetVariableType())); - this.Write(";"); - -if (this.Model.Value.IsVariableReference && this.Model.Value.VariableReference.SegmentCount == 2) -{ - this.Write("\n object? parsedValue = await context.ConvertValueAsync(targetType, key: \"" + - ""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Model.Value.VariableReference.VariableName)); - this.Write("\", scopeName: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Model.Value.VariableReference.NamespaceAlias)); - this.Write("\", cancellationToken).ConfigureAwait(false);"); - -} -else if (this.Model.Value.IsVariableReference) -{ - this.Write("\n object? parsedValue = await context.ConvertValueAsync(targetType, "); - this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(this.Model.Value.VariableReference.ToString()))); - this.Write(", cancellationToken).ConfigureAwait(false);"); - -} -else -{ - this.Write("\n object? parsedValue = await context.ConvertValueAsync(targetType, "); - this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(this.Model.Value.ExpressionText))); - this.Write(", cancellationToken).ConfigureAwait(false);"); - -} - AssignVariable(this.Variable, "parsedValue"); - this.Write("\n return default;\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ParseValueTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ParseValueTemplate.tt deleted file mode 100644 index 246e1d331b..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ParseValueTemplate.tt +++ /dev/null @@ -1,30 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -/// -/// Parses a string or untyped value to the provided data type. When the input is a string, it will be treated as JSON. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { - VariableType targetType = <#= this.GetVariableType() #>;<# -if (this.Model.Value.IsVariableReference && this.Model.Value.VariableReference.SegmentCount == 2) -{#> - object? parsedValue = await context.ConvertValueAsync(targetType, key: "<#= this.Model.Value.VariableReference.VariableName #>", scopeName: "<#= this.Model.Value.VariableReference.NamespaceAlias #>", cancellationToken).ConfigureAwait(false);<# -} -else if (this.Model.Value.IsVariableReference) -{#> - object? parsedValue = await context.ConvertValueAsync(targetType, <#= FormatStringValue(this.Model.Value.VariableReference.ToString()) #>, cancellationToken).ConfigureAwait(false);<# -} -else -{#> - object? parsedValue = await context.ConvertValueAsync(targetType, <#= FormatStringValue(this.Model.Value.ExpressionText) #>, cancellationToken).ConfigureAwait(false);<# -} - AssignVariable(this.Variable, "parsedValue"); #> - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ParseValueTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ParseValueTemplateCode.cs deleted file mode 100644 index 276140d258..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ParseValueTemplateCode.cs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Linq; -using Microsoft.Agents.ObjectModel; -using Microsoft.Shared.Diagnostics; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class ParseValueTemplate -{ - public ParseValueTemplate(ParseValue model) - { - this.Model = this.Initialize(model); - this.Variable = Throw.IfNull(this.Model.Variable); - } - - public ParseValue Model { get; } - public PropertyPath Variable { get; } - - private string GetVariableType() - { - return GetVariableType(this.Model.ValueType); - - static string GetVariableType(DataType? dataType) => - dataType switch - { - null => "null", - StringDataType => "typeof(string)", - BooleanDataType => "typeof(bool)", - FloatDataType => "typeof(double)", - NumberDataType => "typeof(decimal)", - DateTimeDataType => "typeof(DateTime)", - DateDataType => "typeof(DateTime)", - TimeDataType => "typeof(TimeSpan)", - RecordDataType recordType => $"\nVariableType.Record(\n{string.Join(",\n ", recordType.Properties.Select(property => @$"( ""{property.Key}"", {GetVariableType(property.Value.Type)} )"))})", - TableDataType tableType => $"\nVariableType.Record(\n{string.Join(",\n ", tableType.Properties.Select(property => @$"( ""{property.Key}"", {GetVariableType(property.Value.Type)} )"))})", - _ => throw new DeclarativeModelException($"Unsupported data type: {dataType}"), - }; - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ProviderTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ProviderTemplate.cs deleted file mode 100644 index d09e7ff182..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ProviderTemplate.cs +++ /dev/null @@ -1,118 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class ProviderTemplate : CodeTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write(@" -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// ------------------------------------------------------------------------------ - -#nullable enable -#pragma warning disable IDE0005 // Extra using directive is ok. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Agents.AI; -using Microsoft.Agents.AI.Workflows; -using Microsoft.Agents.AI.Workflows.Declarative; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Extensions.AI; -"); - -if (this.Namespace is not null) -{ - this.Write("\nnamespace "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Namespace)); - this.Write(";\n"); - -} - - this.Write(@" -/// -/// This class provides a factory method to create a instance. -/// -/// -/// The workflow defined here was generated from a declarative workflow definition. -/// Declarative workflows utilize Power FX for defining conditions and expressions. -/// To learn more about Power FX, see: -/// https://learn.microsoft.com/power-platform/power-fx/formula-reference-copilot-studio -/// -public static class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Prefix ?? string.Empty)); - this.Write("WorkflowProvider\n{"); - -foreach (string executor in ByLine(this.Executors, formatGroup: true)) -{ - this.Write("\n "); - this.Write(this.ToStringHelper.ToStringWithCulture(executor)); - -} - - this.Write(@" - public static Workflow CreateWorkflow( - DeclarativeWorkflowOptions options, - Func? inputTransform = null) - where TInput : notnull - { - // Create root executor to initialize the workflow. - inputTransform ??= (message) => DeclarativeWorkflowBuilder.DefaultTransform(message); - "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.RootExecutorType)); - this.Write("Executor "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.RootInstance)); - this.Write(" = new(options, inputTransform);"); - - - // Create executor instances -foreach (string instance in ByLine(this.Instances)) -{ - this.Write("\n "); - this.Write(this.ToStringHelper.ToStringWithCulture(instance)); - -} - this.Write("\n\n // Define the workflow builder\n WorkflowBuilder builder = new("); - this.Write(this.ToStringHelper.ToStringWithCulture(this.RootInstance)); - this.Write(");\n\n // Connect executors"); - -foreach (string edge in ByLine(this.Edges)) -{ - this.Write("\n "); - this.Write(this.ToStringHelper.ToStringWithCulture(edge)); - -} - - this.Write("\n\n // Build the workflow\n return builder.Build(validateOrphans: fal" + - "se);\n }\n}\n"); - return this.GenerationEnvironment.ToString(); - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ProviderTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ProviderTemplate.tt deleted file mode 100644 index 8de0ba466d..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ProviderTemplate.tt +++ /dev/null @@ -1,75 +0,0 @@ -<#@ template language="C#" inherits="CodeTemplate" visibility="internal" linePragmas="false" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Extensions" #> -<#@ assembly name="System.Core" #> -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// -// ------------------------------------------------------------------------------ - -#nullable enable -#pragma warning disable IDE0005 // Extra using directive is ok. - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.Agents.AI; -using Microsoft.Agents.AI.Workflows; -using Microsoft.Agents.AI.Workflows.Declarative; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Extensions.AI; -<# -if (this.Namespace is not null) -{#> -namespace <#= this.Namespace #>; -<# -} -#> -/// -/// This class provides a factory method to create a instance. -/// -/// -/// The workflow defined here was generated from a declarative workflow definition. -/// Declarative workflows utilize Power FX for defining conditions and expressions. -/// To learn more about Power FX, see: -/// https://learn.microsoft.com/power-platform/power-fx/formula-reference-copilot-studio -/// -public static class <#= this.Prefix ?? string.Empty #>WorkflowProvider -{<# -foreach (string executor in ByLine(this.Executors, formatGroup: true)) -{ #> - <#= executor #><# -} -#> - public static Workflow CreateWorkflow( - DeclarativeWorkflowOptions options, - Func? inputTransform = null) - where TInput : notnull - { - // Create root executor to initialize the workflow. - inputTransform ??= (message) => DeclarativeWorkflowBuilder.DefaultTransform(message); - <#= this.RootExecutorType #>Executor <#= this.RootInstance #> = new(options, inputTransform);<# - - // Create executor instances -foreach (string instance in ByLine(this.Instances)) -{ #> - <#= instance #><# -}#> - - // Define the workflow builder - WorkflowBuilder builder = new(<#= this.RootInstance #>); - - // Connect executors<# -foreach (string edge in ByLine(this.Edges)) -{ #> - <#= edge #><# -} - #> - - // Build the workflow - return builder.Build(validateOrphans: false); - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ProviderTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ProviderTemplateCode.cs deleted file mode 100644 index d07f0bf8d1..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ProviderTemplateCode.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Collections.Generic; -using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class ProviderTemplate -{ - public ProviderTemplate( - string workflowId, - IEnumerable executors, - IEnumerable instances, - IEnumerable edges) - { - this.Executors = executors; - this.Instances = instances; - this.Edges = edges; - this.RootInstance = workflowId.FormatName(); - this.RootExecutorType = workflowId.FormatType(); - } - - public string? Namespace { get; init; } - public string? Prefix { get; init; } - - public string RootInstance { get; } - public string RootExecutorType { get; } - - public IEnumerable Executors { get; } - public IEnumerable Instances { get; } - public IEnumerable Edges { get; } - - public static IEnumerable ByLine(IEnumerable templates, bool formatGroup = false) - { - foreach (string template in templates) - { - foreach (string line in template.ByLine()) - { - yield return line; - } - - if (formatGroup) - { - yield return string.Empty; - } - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/QuestionTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/QuestionTemplate.cs deleted file mode 100644 index 61afa0309a..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/QuestionTemplate.cs +++ /dev/null @@ -1,37 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class QuestionTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Request input.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " {\n return default;\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/QuestionTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/QuestionTemplate.tt deleted file mode 100644 index 7d3a15af6b..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/QuestionTemplate.tt +++ /dev/null @@ -1,14 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -/// -/// Request input. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/QuestionTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/QuestionTemplateCode.cs deleted file mode 100644 index 6308fa8d6a..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/QuestionTemplateCode.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class QuestionTemplate -{ - public QuestionTemplate(Question model) - { - this.Model = this.Initialize(model); - } - - public Question Model { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ResetVariableTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ResetVariableTemplate.cs deleted file mode 100644 index bd56580a7b..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ResetVariableTemplate.cs +++ /dev/null @@ -1,74 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class ResetVariableTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Resets the value of the \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Model.Variable)); - this.Write("\" variable, potentially causing re-evaluation \n/// of the default value, question" + - " or action that provides the value to this variable.\n/// \ninternal sea" + - "led class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n protected override async ValueTask ExecuteAsync(IWorkf" + - "lowContext context, CancellationToken cancellationToken)\n {"); - - AssignVariable(this.Variable, "UnassignedValue.Instance"); - this.Write("\n return default;\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ResetVariableTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ResetVariableTemplate.tt deleted file mode 100644 index 0565a2328b..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ResetVariableTemplate.tt +++ /dev/null @@ -1,17 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -/// -/// Resets the value of the "<#= this.Model.Variable #>" variable, potentially causing re-evaluation -/// of the default value, question or action that provides the value to this variable. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - AssignVariable(this.Variable, "UnassignedValue.Instance"); #> - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ResetVariableTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ResetVariableTemplateCode.cs deleted file mode 100644 index fb5ab679f4..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ResetVariableTemplateCode.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; -using Microsoft.Shared.Diagnostics; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class ResetVariableTemplate -{ - public ResetVariableTemplate(ResetVariable model) - { - this.Model = this.Initialize(model); - this.Variable = Throw.IfNull(this.Model.Variable); - } - - public ResetVariable Model { get; } - - public PropertyPath Variable { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessageTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessageTemplate.cs deleted file mode 100644 index 4015cffa71..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessageTemplate.cs +++ /dev/null @@ -1,310 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class RetrieveConversationMessageTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Retrieves a list of messages from an agent conversation.\n/// <" + - "/summary>\ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session, ResponseAgentProvider agentProvider) : ActionExe" + - "cutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " {"); - - EvaluateStringExpression(this.Model.ConversationId, "conversationId"); - EvaluateStringExpression(this.Model.MessageId, "messageId"); - this.Write("\n ChatMessage message = await agentProvider.GetMessageAsync(conversationId" + - ", messageId, cancellationToken).ConfigureAwait(false);"); - - AssignVariable(this.Model.Message, "message"); - - this.Write("\n return default;\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateRecordExpression(ObjectExpression expression, string targetVariable) -{ - string resultTypeName = $"Dictionary()}?>?"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = null;"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" =\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue))); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(">(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateExpressionAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateExpressionAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - -void EvaluateStringExpression(StringExpression expression, string targetVariable, bool isNullable = false) -{ - string typeName = isNullable ? "string?" : "string"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(isNullable ? "null" : "string.Empty")); - -this.Write(";"); - - - } - else if (expression.IsLiteral) - { - if (expression.LiteralValue.Contains("\n")) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = \n \"\"\"\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.LiteralValue)); - -this.Write("\n \"\"\";"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.LiteralValue))); - -this.Write(";"); - - - } - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessageTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessageTemplate.tt deleted file mode 100644 index 487a1c54c6..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessageTemplate.tt +++ /dev/null @@ -1,23 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateRecordExpressionTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateStringExpressionTemplate.tt" once="true" #> -/// -/// Retrieves a list of messages from an agent conversation. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session, ResponseAgentProvider agentProvider) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - EvaluateStringExpression(this.Model.ConversationId, "conversationId"); - EvaluateStringExpression(this.Model.MessageId, "messageId"); #> - ChatMessage message = await agentProvider.GetMessageAsync(conversationId, messageId, cancellationToken).ConfigureAwait(false);<# - AssignVariable(this.Model.Message, "message"); - #> - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessageTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessageTemplateCode.cs deleted file mode 100644 index 2bcfdda6ca..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessageTemplateCode.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class RetrieveConversationMessageTemplate -{ - public RetrieveConversationMessageTemplate(RetrieveConversationMessage model) - { - this.Model = this.Initialize(model); - this.UseAgentProvider = true; - } - - public RetrieveConversationMessage Model { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessagesTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessagesTemplate.cs deleted file mode 100644 index d9b1ff94dd..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessagesTemplate.cs +++ /dev/null @@ -1,584 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using System.Collections.Generic; - using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class RetrieveConversationMessagesTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Retrieves a specific message from an agent conversation.\n/// <" + - "/summary>\ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session, ResponseAgentProvider agentProvider) : ActionExe" + - "cutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " {"); - - EvaluateStringExpression(this.Model.ConversationId, "conversationId"); - EvaluateIntExpression(this.Model.Limit, "limit"); - EvaluateStringExpression(this.Model.MessageAfter, "after", isNullable: true); - EvaluateStringExpression(this.Model.MessageBefore, "before", isNullable: true); - EvaluateEnumExpression(this.Model.SortOrder, "newestFirst", SortMap, defaultValue: DefaultSort); - this.Write(@" - IAsyncEnumerable messagesResult = - agentProvider.GetMessagesAsync( - conversationId, - limit, - after, - before, - newestFirst, - cancellationToken); - List messages = []; - await foreach (ChatMessage message in messagesResult.ConfigureAwait(false)) - { - messages.Add(message); - }"); - - AssignVariable(this.Model.Messages, "messages"); - - this.Write("\n return default;\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateEnumExpression( - EnumExpression expression, - string targetVariable, - IDictionary resultMap, - string defaultValue = null, - bool qualifyResult = false, - bool isNullable = false) - where TWrapper : EnumWrapper -{ - string resultType = $"{GetTypeAlias()}{(isNullable ? "?" : "")}"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatValue(defaultValue))); - -this.Write(";"); - - - } - else if (expression.IsLiteral) - { - resultMap.TryGetValue(expression.LiteralValue, out string resultValue); - if (qualifyResult) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("."); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultValue)); - -this.Write(";"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatValue(resultValue))); - -this.Write(";"); - - - } - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(">(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultType)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - -void EvaluateIntExpression(IntExpression expression, string targetVariable, bool isNullable = false) -{ - string typeName = isNullable ? "int?" : "int"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(isNullable ? "null" : "0")); - -this.Write(";"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.LiteralValue)); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - -void EvaluateRecordExpression(ObjectExpression expression, string targetVariable) -{ - string resultTypeName = $"Dictionary()}?>?"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = null;"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" =\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue))); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(">(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateExpressionAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateExpressionAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(resultTypeName)); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - -void EvaluateStringExpression(StringExpression expression, string targetVariable, bool isNullable = false) -{ - string typeName = isNullable ? "string?" : "string"; - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(isNullable ? "null" : "string.Empty")); - -this.Write(";"); - - - } - else if (expression.IsLiteral) - { - if (expression.LiteralValue.Contains("\n")) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = \n \"\"\"\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.LiteralValue)); - -this.Write("\n \"\"\";"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.LiteralValue))); - -this.Write(";"); - - - } - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(typeName)); - -this.Write(" "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessagesTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessagesTemplate.tt deleted file mode 100644 index d36a29310d..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessagesTemplate.tt +++ /dev/null @@ -1,42 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="System.Collections.Generic" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Extensions" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateEnumExpressionTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateIntExpressionTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateRecordExpressionTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateStringExpressionTemplate.tt" once="true" #> -/// -/// Retrieves a specific message from an agent conversation. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session, ResponseAgentProvider agentProvider) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - EvaluateStringExpression(this.Model.ConversationId, "conversationId"); - EvaluateIntExpression(this.Model.Limit, "limit"); - EvaluateStringExpression(this.Model.MessageAfter, "after", isNullable: true); - EvaluateStringExpression(this.Model.MessageBefore, "before", isNullable: true); - EvaluateEnumExpression(this.Model.SortOrder, "newestFirst", SortMap, defaultValue: DefaultSort); #> - IAsyncEnumerable messagesResult = - agentProvider.GetMessagesAsync( - conversationId, - limit, - after, - before, - newestFirst, - cancellationToken); - List messages = []; - await foreach (ChatMessage message in messagesResult.ConfigureAwait(false)) - { - messages.Add(message); - }<# - AssignVariable(this.Model.Messages, "messages"); - #> - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessagesTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessagesTemplateCode.cs deleted file mode 100644 index c13bf8dfbf..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RetrieveConversationMessagesTemplateCode.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Collections.Frozen; -using System.Collections.Generic; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class RetrieveConversationMessagesTemplate -{ - public RetrieveConversationMessagesTemplate(RetrieveConversationMessages model) - { - this.Model = this.Initialize(model); - this.UseAgentProvider = true; - } - - public RetrieveConversationMessages Model { get; } - - public const string DefaultSort = "false"; - - public static readonly FrozenDictionary SortMap = - new Dictionary() - { - [AgentMessageSortOrderWrapper.Get(AgentMessageSortOrder.NewestFirst)] = "true", - [AgentMessageSortOrderWrapper.Get(AgentMessageSortOrder.OldestFirst)] = "false", - }.ToFrozenDictionary(); -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RootTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RootTemplate.cs deleted file mode 100644 index 8c027f4b39..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RootTemplate.cs +++ /dev/null @@ -1,79 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - using Microsoft.Agents.AI.Workflows.Declarative.Interpreter; - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class RootTemplate : CodeTemplate, IModeledAction - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// The root executor for a declarative workflow.\n/// \ni" + - "nternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.TypeName)); - this.Write("Executor(\n DeclarativeWorkflowOptions options,\n Func inputTransform) :\n RootExecutor(\""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", options, inputTransform)\n where TInput : notnull\n{\n protected override a" + - "sync ValueTask ExecuteAsync(TInput message, IWorkflowContext context, Cancellati" + - "onToken cancellationToken)\n {"); - -if (this.TypeInfo.EnvironmentVariables.Count > 0) -{ - this.Write("\n // Set environment variables\n await this.InitializeEnvironmentAsy" + - "nc(\n context,"); - - int index = this.TypeInfo.EnvironmentVariables.Count - 1; - foreach (string variableName in this.TypeInfo.EnvironmentVariables) - { - this.Write("\n \""); - this.Write(this.ToStringHelper.ToStringWithCulture(variableName)); - this.Write("\""); - this.Write(this.ToStringHelper.ToStringWithCulture(index > 0 ? "," : "")); - - --index; - } - this.Write(").ConfigureAwait(false);\n"); -} - -if (this.TypeInfo.UserVariables.Count > 0) -{ - - this.Write("\n // Initialize variables"); - - foreach (VariableInformationDiagnostic variableInfo in this.TypeInfo.UserVariables) - { - this.Write("\n await context.QueueStateUpdateAsync(\""); - this.Write(this.ToStringHelper.ToStringWithCulture(variableInfo.Path.VariableName)); - this.Write("\", UnassignedValue.Instance, \""); - this.Write(this.ToStringHelper.ToStringWithCulture(variableInfo.Path.NamespaceAlias)); - this.Write("\").ConfigureAwait(false);"); - - } -} - this.Write("\n }\n}\n"); - return this.GenerationEnvironment.ToString(); - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RootTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RootTemplate.tt deleted file mode 100644 index ced3b842a2..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RootTemplate.tt +++ /dev/null @@ -1,40 +0,0 @@ -<#@ template language="C#" inherits="CodeTemplate, IModeledAction" visibility="internal" linePragmas="false" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Extensions" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Interpreter" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ assembly name="System.Core" #> -/// -/// The root executor for a declarative workflow. -/// -internal sealed class <#= this.TypeName #>Executor( - DeclarativeWorkflowOptions options, - Func inputTransform) : - RootExecutor("<#= this.Id #>", options, inputTransform) - where TInput : notnull -{ - protected override async ValueTask ExecuteAsync(TInput message, IWorkflowContext context, CancellationToken cancellationToken) - {<# -if (this.TypeInfo.EnvironmentVariables.Count > 0) -{ #> - // Set environment variables - await this.InitializeEnvironmentAsync( - context,<# - int index = this.TypeInfo.EnvironmentVariables.Count - 1; - foreach (string variableName in this.TypeInfo.EnvironmentVariables) - {#> - "<#= variableName #>"<#= index > 0 ? "," : "" #><# - --index; - }#>).ConfigureAwait(false); -<#} - -if (this.TypeInfo.UserVariables.Count > 0) -{ -#> - // Initialize variables<# - foreach (VariableInformationDiagnostic variableInfo in this.TypeInfo.UserVariables) - {#> - await context.QueueStateUpdateAsync("<#= variableInfo.Path.VariableName #>", UnassignedValue.Instance, "<#= variableInfo.Path.NamespaceAlias #>").ConfigureAwait(false);<# - } -}#> - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RootTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RootTemplateCode.cs deleted file mode 100644 index 61b625188b..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/RootTemplateCode.cs +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.Extensions; -using Microsoft.Agents.AI.Workflows.Declarative.PowerFx; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class RootTemplate -{ - internal RootTemplate( - string workflowId, - WorkflowTypeInfo typeInfo) - { - this.Id = workflowId; - this.TypeInfo = typeInfo; - this.TypeName = workflowId.FormatType(); - } - - public string Id { get; } - public WorkflowTypeInfo TypeInfo { get; } - public string TypeName { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SendActivityTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SendActivityTemplate.cs deleted file mode 100644 index cce0854bff..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SendActivityTemplate.cs +++ /dev/null @@ -1,109 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class SendActivityTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Formats a message template and sends an activity event.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " { "); - -if (this.Model.Activity is MessageActivityTemplate messageActivity) -{ - this.Write("\n string activityText = \n await context.FormatTemplateAsync( "); - - foreach (TemplateLine line in messageActivity.Text) - { - this.Write("\n \"\"\""); - - foreach (string text in line.ToTemplateString().ByLine()) - { - this.Write("\n "); - this.Write(this.ToStringHelper.ToStringWithCulture(text)); - - } - this.Write("\n \"\"\""); - - } - - this.Write("\n );\n AgentResponse response = new([new ChatMessage(ChatRole.As" + - "sistant, activityText)]);\n await context.AddEventAsync(new AgentResponseE" + - "vent(this.Id, response)).ConfigureAwait(false);"); - -} - this.Write("\n\n return default;\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void EvaluateMessageTemplate(TemplateLine templateLine, string variableName) -{ - if (templateLine is not null) - { -this.Write("\n string "); - -this.Write(this.ToStringHelper.ToStringWithCulture(variableName)); - -this.Write(" =\n await context.FormatTemplateAsync(\n \"\"\""); - - - FormatMessageTemplate(templateLine); -this.Write("\n \"\"\");"); - - - } - else - { -this.Write("\n string? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(variableName)); - -this.Write(" = null;"); - - - } -} - -void FormatMessageTemplate(TemplateLine line) -{ - foreach (string text in line.ToTemplateString().ByLine()) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(text)); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SendActivityTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SendActivityTemplate.tt deleted file mode 100644 index 283ac57e1b..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SendActivityTemplate.tt +++ /dev/null @@ -1,36 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Extensions" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/FormatMessageTemplate.tt" once="true" #> -/// -/// Formats a message template and sends an activity event. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { <# -if (this.Model.Activity is MessageActivityTemplate messageActivity) -{ #> - string activityText = - await context.FormatTemplateAsync( <# - foreach (TemplateLine line in messageActivity.Text) - { #> - """<# - foreach (string text in line.ToTemplateString().ByLine()) - { #> - <#= text #><# - } #> - """<# - } - #> - ); - AgentResponse response = new([new ChatMessage(ChatRole.Assistant, activityText)]); - await context.AddEventAsync(new AgentResponseEvent(this.Id, response)).ConfigureAwait(false);<# -} #> - - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SendActivityTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SendActivityTemplateCode.cs deleted file mode 100644 index dd582a8f40..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SendActivityTemplateCode.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class SendActivityTemplate -{ - public SendActivityTemplate(SendActivity model) - { - this.Model = this.Initialize(model); - } - - public SendActivity Model { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetMultipleVariablesTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetMultipleVariablesTemplate.cs deleted file mode 100644 index 52e86a1f65..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetMultipleVariablesTemplate.cs +++ /dev/null @@ -1,195 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class SetMultipleVariablesTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Assigns an evaluated expression, other variable, or literal va" + - "lue to one or more variables.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " {"); - int index = 0; - foreach (var assignment in this.Model.Assignments) - { - // Separate assigments with a blank line for readability - if (index > 0) - { - this.Write("\n "); - - } - ++index; - EvaluateValueExpression(assignment.Value, $"evaluatedValue{index}"); - AssignVariable(assignment.Variable, $"evaluatedValue{index}"); - } - - this.Write("\n return default;\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateValueExpression(ValueExpression expression, string targetVariable) => - EvaluateValueExpression(expression, targetVariable); - -void EvaluateValueExpression(ValueExpression expression, string targetVariable) -{ - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = null;"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue))); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetMultipleVariablesTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetMultipleVariablesTemplate.tt deleted file mode 100644 index 44b697eb2f..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetMultipleVariablesTemplate.tt +++ /dev/null @@ -1,29 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateValueExpressionTemplate.tt" once="true" #> -/// -/// Assigns an evaluated expression, other variable, or literal value to one or more variables. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# int index = 0; - foreach (var assignment in this.Model.Assignments) - { - // Separate assigments with a blank line for readability - if (index > 0) - {#> - <# - } - ++index; - EvaluateValueExpression(assignment.Value, $"evaluatedValue{index}"); - AssignVariable(assignment.Variable, $"evaluatedValue{index}"); - } - #> - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetMultipleVariablesTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetMultipleVariablesTemplateCode.cs deleted file mode 100644 index 55f5fdd847..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetMultipleVariablesTemplateCode.cs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class SetMultipleVariablesTemplate -{ - public SetMultipleVariablesTemplate(SetMultipleVariables model) - { - this.Model = this.Initialize(model); - } - - public SetMultipleVariables Model { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetTextVariableTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetTextVariableTemplate.cs deleted file mode 100644 index 81a9ee28bf..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetTextVariableTemplate.cs +++ /dev/null @@ -1,117 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.AI.Workflows.Declarative.Extensions; - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class SetTextVariableTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Assigns an evaluated message template to the \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Model.Variable)); - this.Write("\" variable.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n protected override async ValueTask ExecuteAsync(IWorkf" + - "lowContext context, CancellationToken cancellationToken)\n {"); - - EvaluateMessageTemplate(this.Model.Value, "textValue"); - AssignVariable(this.Variable, "textValue"); - this.Write("\n return default;\n }\n}"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateMessageTemplate(TemplateLine templateLine, string variableName) -{ - if (templateLine is not null) - { -this.Write("\n string "); - -this.Write(this.ToStringHelper.ToStringWithCulture(variableName)); - -this.Write(" =\n await context.FormatTemplateAsync(\n \"\"\""); - - - FormatMessageTemplate(templateLine); -this.Write("\n \"\"\");"); - - - } - else - { -this.Write("\n string? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(variableName)); - -this.Write(" = null;"); - - - } -} - -void FormatMessageTemplate(TemplateLine line) -{ - foreach (string text in line.ToTemplateString().ByLine()) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(text)); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetTextVariableTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetTextVariableTemplate.tt deleted file mode 100644 index 1d16ee92ea..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetTextVariableTemplate.tt +++ /dev/null @@ -1,19 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Extensions" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/FormatMessageTemplate.tt" once="true" #> -/// -/// Assigns an evaluated message template to the "<#= this.Model.Variable #>" variable. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - EvaluateMessageTemplate(this.Model.Value, "textValue"); - AssignVariable(this.Variable, "textValue"); #> - return default; - } -} \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetTextVariableTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetTextVariableTemplateCode.cs deleted file mode 100644 index 1be27b5ac2..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetTextVariableTemplateCode.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; -using Microsoft.Shared.Diagnostics; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class SetTextVariableTemplate -{ - public SetTextVariableTemplate(SetTextVariable model) - { - this.Model = this.Initialize(model); - this.Variable = Throw.IfNull(this.Model.Variable); - } - - public SetTextVariable Model { get; } - - public PropertyPath Variable { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetVariableTemplate.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetVariableTemplate.cs deleted file mode 100644 index 972fc1e5c9..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetVariableTemplate.cs +++ /dev/null @@ -1,186 +0,0 @@ -// ------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version: 18.0.0.0 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -// ------------------------------------------------------------------------------ -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen -{ - using Microsoft.Agents.ObjectModel; - using System; - - /// - /// Class to produce the template output - /// - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "18.0.0.0")] - internal partial class SetVariableTemplate : ActionTemplate - { - /// - /// Create the template output - /// - public override string TransformText() - { - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n"); - this.Write("\n/// \n/// Assigns an evaluated expression, other variable, or literal va" + - "lue to the \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Model.Variable)); - this.Write("\" variable.\n/// \ninternal sealed class "); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Name)); - this.Write("Executor(FormulaSession session) : ActionExecutor(id: \""); - this.Write(this.ToStringHelper.ToStringWithCulture(this.Id)); - this.Write("\", session)\n{\n // \n protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)\n " + - " {"); - - EvaluateValueExpression(this.Model.Value, "evaluatedValue"); - AssignVariable(this.Variable, "evaluatedValue"); - this.Write("\n return default;\n }\n}\n"); - return this.GenerationEnvironment.ToString(); - } - -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - { -this.Write("\n await context.QueueStateUpdateAsync(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableName(targetVariable))); - -this.Write("\", value: "); - -this.Write(this.ToStringHelper.ToStringWithCulture(valueVariable)); - -this.Write(", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(VariableScope(targetVariable))); - -this.Write("\").ConfigureAwait(false);"); - - - if (!tightFormat) - { -this.Write("\n "); - -} - } -} - - -void EvaluateValueExpression(ValueExpression expression, string targetVariable) => - EvaluateValueExpression(expression, targetVariable); - -void EvaluateValueExpression(ValueExpression expression, string targetVariable) -{ - if (expression is null) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = null;"); - - - } - else if (expression.IsLiteral) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = "); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatDataValue(expression.LiteralValue))); - -this.Write(";"); - - - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.ReadStateAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">(key: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.VariableName)); - -this.Write("\", scopeName: \""); - -this.Write(this.ToStringHelper.ToStringWithCulture(expression.VariableReference.NamespaceAlias)); - -this.Write("\").ConfigureAwait(false);"); - - - } - else if (expression.IsVariableReference) - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.VariableReference.ToString()))); - -this.Write(").ConfigureAwait(false);"); - - - } - else - { -this.Write("\n "); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write("? "); - -this.Write(this.ToStringHelper.ToStringWithCulture(targetVariable)); - -this.Write(" = await context.EvaluateValueAsync<"); - -this.Write(this.ToStringHelper.ToStringWithCulture(GetTypeAlias())); - -this.Write(">("); - -this.Write(this.ToStringHelper.ToStringWithCulture(FormatStringValue(expression.ExpressionText))); - -this.Write(").ConfigureAwait(false);"); - - - } -} - - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetVariableTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetVariableTemplate.tt deleted file mode 100644 index 2adbb1922c..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetVariableTemplate.tt +++ /dev/null @@ -1,19 +0,0 @@ -<#@ template language="C#" inherits="ActionTemplate" visibility="internal" linePragmas="false" #> -<#@ output extension=".cs" #> -<#@ assembly name="System.Core" #> -<#@ import namespace="Microsoft.Agents.ObjectModel" #> -<#@ include file="Snippets/AssignVariableTemplate.tt" once="true" #> -<#@ include file="Snippets/EvaluateValueExpressionTemplate.tt" once="true" #> -/// -/// Assigns an evaluated expression, other variable, or literal value to the "<#= this.Model.Variable #>" variable. -/// -internal sealed class <#= this.Name #>Executor(FormulaSession session) : ActionExecutor(id: "<#= this.Id #>", session) -{ - // - protected override async ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - {<# - EvaluateValueExpression(this.Model.Value, "evaluatedValue"); - AssignVariable(this.Variable, "evaluatedValue"); #> - return default; - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetVariableTemplateCode.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetVariableTemplateCode.cs deleted file mode 100644 index a9cc4a7abf..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/SetVariableTemplateCode.cs +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.ObjectModel; -using Microsoft.Shared.Diagnostics; - -namespace Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -internal partial class SetVariableTemplate -{ - internal SetVariableTemplate(SetVariable model) - { - this.Model = this.Initialize(model); - this.Variable = Throw.IfNull(this.Model.Variable); - } - - public SetVariable Model { get; } - public PropertyPath Variable { get; } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/AssignVariableTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/AssignVariableTemplate.tt deleted file mode 100644 index a3f13aead0..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/AssignVariableTemplate.tt +++ /dev/null @@ -1,12 +0,0 @@ -<#+ -void AssignVariable(PropertyPath targetVariable, string valueVariable, bool tightFormat = false) -{ - if (targetVariable is not null) - {#> - await context.QueueStateUpdateAsync(key: "<#= VariableName(targetVariable) #>", value: <#= valueVariable #>, scopeName: "<#= VariableScope(targetVariable) #>").ConfigureAwait(false);<#+ - if (!tightFormat) - {#> - <#+} - } -} -#> \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateBoolExpressionTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateBoolExpressionTemplate.tt deleted file mode 100644 index c4f860cf7e..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateBoolExpressionTemplate.tt +++ /dev/null @@ -1,25 +0,0 @@ -<#+ -void EvaluateBoolExpression(BoolExpression expression, string targetVariable, bool defaultValue = false) -{ - if (expression is null) - {#> - bool <#= targetVariable #> = <#= FormatBoolValue(defaultValue) #>;<#+ - } - else if (expression.IsLiteral) - {#> - bool <#= targetVariable #> = <#= FormatBoolValue(expression.LiteralValue) #>;<#+ - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - {#> - bool <#= targetVariable #> = await context.ReadStateAsync(key: "<#= expression.VariableReference.VariableName #>", scopeName: "<#= expression.VariableReference.NamespaceAlias #>").ConfigureAwait(false);<#+ - } - else if (expression.IsVariableReference) - {#> - bool <#= targetVariable #> = await context.EvaluateValueAsync>(<#= FormatStringValue(expression.VariableReference.ToString()) #>).ConfigureAwait(false);<#+ - } - else - {#> - bool <#= targetVariable #> = await context.EvaluateValueAsync(<#= FormatStringValue(expression.ExpressionText) #>).ConfigureAwait(false);<#+ - } -} -#> \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateEnumExpressionTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateEnumExpressionTemplate.tt deleted file mode 100644 index b730e0c519..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateEnumExpressionTemplate.tt +++ /dev/null @@ -1,41 +0,0 @@ -<#+ -void EvaluateEnumExpression( - EnumExpression expression, - string targetVariable, - IDictionary resultMap, - string defaultValue = null, - bool qualifyResult = false, - bool isNullable = false) - where TWrapper : EnumWrapper -{ - string resultType = $"{GetTypeAlias()}{(isNullable ? "?" : "")}"; - if (expression is null) - {#> - <#= resultType #> <#= targetVariable #> = <#= FormatValue(defaultValue) #>;<#+ - } - else if (expression.IsLiteral) - { - resultMap.TryGetValue(expression.LiteralValue, out string resultValue); - if (qualifyResult) - {#> - <#= resultType #> <#= targetVariable #> = <#= GetTypeAlias() #>.<#= resultValue #>;<#+ - } - else - {#> - <#= resultType #> <#= targetVariable #> = <#= FormatValue(resultValue) #>;<#+ - } - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - {#> - <#= resultType #> <#= targetVariable #> = await context.ReadStateAsync<<#= resultType #>>(key: "<#= expression.VariableReference.VariableName #>", scopeName: "<#= expression.VariableReference.NamespaceAlias #>").ConfigureAwait(false);<#+ - } - else if (expression.IsVariableReference) - {#> - <#= resultType #>? <#= targetVariable #> = await context.EvaluateValueAsync<<#= resultType #>>(<#= FormatStringValue(expression.VariableReference.ToString()) #>).ConfigureAwait(false);<#+ - } - else - {#> - <#= resultType #> <#= targetVariable #> = await context.EvaluateValueAsync<<#= resultType #>>(<#= FormatStringValue(expression.ExpressionText) #>).ConfigureAwait(false);<#+ - } -} -#> \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateIntExpressionTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateIntExpressionTemplate.tt deleted file mode 100644 index 2d94162c43..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateIntExpressionTemplate.tt +++ /dev/null @@ -1,26 +0,0 @@ -<#+ -void EvaluateIntExpression(IntExpression expression, string targetVariable, bool isNullable = false) -{ - string typeName = isNullable ? "int?" : "int"; - if (expression is null) - {#> - <#= typeName #> <#= targetVariable #> = <#= isNullable ? "null" : "0" #>;<#+ - } - else if (expression.IsLiteral) - {#> - <#= typeName #> <#= targetVariable #> = <#= expression.LiteralValue #>;<#+ - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - {#> - <#= typeName #> <#= targetVariable #> = await context.ReadStateAsync(key: "<#= expression.VariableReference.VariableName #>", scopeName: "<#= expression.VariableReference.NamespaceAlias #>").ConfigureAwait(false);<#+ - } - else if (expression.IsVariableReference) - {#> - <#= typeName #>? <#= targetVariable #> = await context.EvaluateValueAsync<<#= typeName #>>(<#= FormatStringValue(expression.VariableReference.ToString()) #>).ConfigureAwait(false);<#+ - } - else - {#> - <#= typeName #> <#= targetVariable #> = await context.EvaluateValueAsync<<#= typeName #>>(<#= FormatStringValue(expression.ExpressionText) #>).ConfigureAwait(false);<#+ - } -} -#> \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateListExpressionTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateListExpressionTemplate.tt deleted file mode 100644 index a9a40293e5..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateListExpressionTemplate.tt +++ /dev/null @@ -1,26 +0,0 @@ -<#+ -void EvaluateListExpression(ValueExpression expression, string targetVariable) -{ - string typeName = GetTypeAlias(); - if (expression is null) - {#> - IList<<#= typeName #>>? <#= targetVariable #> = null;<#+ - } - else if (expression.IsLiteral) - {#> - IList<<#= typeName #>>? <#= targetVariable #> = <#= FormatDataValue(expression.LiteralValue) #>;<#+ - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - {#> - IList<<#= typeName #>>? <#= targetVariable #> = await context.ReadListAsync<<#= GetTypeAlias() #>>(key: "<#= expression.VariableReference.VariableName #>", scopeName: "<#= expression.VariableReference.NamespaceAlias #>").ConfigureAwait(false);<#+ - } - else if (expression.IsVariableReference) - {#> - IList<<#= typeName #>>? <#= targetVariable #>> = await context.EvaluateListAsync<<#= typeName #>>(<#= FormatStringValue(expression.VariableReference.ToString()) #>).ConfigureAwait(false);<#+ - } - else - {#> - IList<<#= typeName #>>? <#= targetVariable #> = await context.EvaluateListAsync<<#= typeName #>>(<#= FormatStringValue(expression.ExpressionText) #>).ConfigureAwait(false);<#+ - } -} -#> \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateRecordExpressionTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateRecordExpressionTemplate.tt deleted file mode 100644 index c1d1513dc2..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateRecordExpressionTemplate.tt +++ /dev/null @@ -1,27 +0,0 @@ -<#+ -void EvaluateRecordExpression(ObjectExpression expression, string targetVariable) -{ - string resultTypeName = $"Dictionary()}?>?"; - if (expression is null) - {#> - <#= resultTypeName #> <#= targetVariable #> = null;<#+ - } - else if (expression.IsLiteral) - {#> - <#= resultTypeName #> <#= targetVariable #> = - <#= FormatDataValue(expression.LiteralValue) #>;<#+ - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - {#> - <#= resultTypeName #> <#= targetVariable #> = await context.ReadStateAsync<<#= resultTypeName #>>(key: "<#= expression.VariableReference.VariableName #>", scopeName: "<#= expression.VariableReference.NamespaceAlias #>").ConfigureAwait(false);<#+ - } - else if (expression.IsVariableReference) - {#> - <#= resultTypeName #>? <#= targetVariable #> = await context.EvaluateExpressionAsync<<#= resultTypeName #>>(<#= FormatStringValue(expression.VariableReference.ToString()) #>).ConfigureAwait(false);<#+ - } - else - {#> - <#= resultTypeName #> <#= targetVariable #> = await context.EvaluateExpressionAsync<<#= resultTypeName #>>(<#= FormatStringValue(expression.ExpressionText) #>).ConfigureAwait(false);<#+ - } -} -#> \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateStringExpressionTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateStringExpressionTemplate.tt deleted file mode 100644 index 81a2197961..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateStringExpressionTemplate.tt +++ /dev/null @@ -1,36 +0,0 @@ -<#+ -void EvaluateStringExpression(StringExpression expression, string targetVariable, bool isNullable = false) -{ - string typeName = isNullable ? "string?" : "string"; - if (expression is null) - {#> - <#= typeName #> <#= targetVariable #> = <#= isNullable ? "null" : "string.Empty" #>;<#+ - } - else if (expression.IsLiteral) - { - if (expression.LiteralValue.Contains("\n")) - {#> - <#= typeName #> <#= targetVariable #> = - """ - <#= expression.LiteralValue #> - """;<#+ - } - else - {#> - <#= typeName #> <#= targetVariable #> = <#= FormatStringValue(expression.LiteralValue) #>;<#+ - } - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - {#> - <#= typeName #> <#= targetVariable #> = await context.ReadStateAsync(key: "<#= expression.VariableReference.VariableName #>", scopeName: "<#= expression.VariableReference.NamespaceAlias #>").ConfigureAwait(false);<#+ - } - else if (expression.IsVariableReference) - {#> - <#= typeName #> <#= targetVariable #> = await context.EvaluateValueAsync(<#= FormatStringValue(expression.VariableReference.ToString()) #>).ConfigureAwait(false);<#+ - } - else - {#> - <#= typeName #> <#= targetVariable #> = await context.EvaluateValueAsync(<#= FormatStringValue(expression.ExpressionText) #>).ConfigureAwait(false);<#+ - } -} -#> \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateValueExpressionTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateValueExpressionTemplate.tt deleted file mode 100644 index 3085b86ece..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/EvaluateValueExpressionTemplate.tt +++ /dev/null @@ -1,28 +0,0 @@ -<#+ -void EvaluateValueExpression(ValueExpression expression, string targetVariable) => - EvaluateValueExpression(expression, targetVariable); - -void EvaluateValueExpression(ValueExpression expression, string targetVariable) -{ - if (expression is null) - {#> - <#= GetTypeAlias() #>? <#= targetVariable #> = null;<#+ - } - else if (expression.IsLiteral) - {#> - <#= GetTypeAlias() #>? <#= targetVariable #> = <#= FormatDataValue(expression.LiteralValue) #>;<#+ - } - else if (expression.IsVariableReference && expression.VariableReference.SegmentCount == 2) - {#> - <#= GetTypeAlias() #>? <#= targetVariable #> = await context.ReadStateAsync<<#= GetTypeAlias() #>>(key: "<#= expression.VariableReference.VariableName #>", scopeName: "<#= expression.VariableReference.NamespaceAlias #>").ConfigureAwait(false);<#+ - } - else if (expression.IsVariableReference) - {#> - <#= GetTypeAlias() #>? <#= targetVariable #> = await context.EvaluateValueAsync<<#= GetTypeAlias() #>>(<#= FormatStringValue(expression.VariableReference.ToString()) #>).ConfigureAwait(false);<#+ - } - else - {#> - <#= GetTypeAlias() #>? <#= targetVariable #> = await context.EvaluateValueAsync<<#= GetTypeAlias() #>>(<#= FormatStringValue(expression.ExpressionText) #>).ConfigureAwait(false);<#+ - } -} -#> \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/FormatMessageTemplate.tt b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/FormatMessageTemplate.tt deleted file mode 100644 index 8c68811d76..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/Snippets/FormatMessageTemplate.tt +++ /dev/null @@ -1,25 +0,0 @@ -<#+ -void EvaluateMessageTemplate(TemplateLine templateLine, string variableName) -{ - if (templateLine is not null) - {#> - string <#= variableName #> = - await context.FormatTemplateAsync( - """<#+ - FormatMessageTemplate(templateLine); #> - """);<#+ - } - else - {#> - string? <#= variableName #> = null;<#+ - } -} - -void FormatMessageTemplate(TemplateLine line) -{ - foreach (string text in line.ToTemplateString().ByLine()) - { #> - <#= text #><#+ - } -} -#> \ No newline at end of file diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/DeclarativeWorkflowBuilder.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/DeclarativeWorkflowBuilder.cs index c0396f42b4..03f0bfbec5 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/DeclarativeWorkflowBuilder.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/DeclarativeWorkflowBuilder.cs @@ -80,55 +80,6 @@ public static Workflow Build( return visitor.Complete(); } - /// - /// Generates source code (provider/executor scaffolding) for the workflow defined in the YAML file. - /// - /// The path to the workflow YAML file. - /// The language to use for the generated code. - /// Optional target namespace for the generated code. - /// Optional prefix for generated workflow type. - /// The generated source code representing the workflow. - public static string Eject( - string workflowFile, - DeclarativeWorkflowLanguage workflowLanguage, - string? workflowNamespace = null, - string? workflowPrefix = null) - { - using StreamReader yamlReader = File.OpenText(workflowFile); - return Eject(yamlReader, workflowLanguage, workflowNamespace, workflowPrefix); - } - - /// - /// Generates source code (provider/executor scaffolding) for the workflow defined in the provided YAML reader. - /// - /// The reader supplying the workflow YAML. - /// The language to use for the generated code. - /// Optional target namespace for the generated code. - /// Optional prefix for generated workflow type. - /// The generated source code representing the workflow. - public static string Eject( - TextReader yamlReader, - DeclarativeWorkflowLanguage workflowLanguage, - string? workflowNamespace = null, - string? workflowPrefix = null) - { - if (workflowLanguage != DeclarativeWorkflowLanguage.CSharp) - { - throw new NotSupportedException($"Converting workflow to {workflowLanguage} is not currently supported."); - } - - AdaptiveDialog workflowElement = ReadWorkflow(yamlReader); - - string rootId = WorkflowActionVisitor.Steps.Root(workflowElement); - WorkflowTypeInfo typeInfo = workflowElement.WrapWithBot().Describe(); - - WorkflowTemplateVisitor visitor = new(rootId, typeInfo); - WorkflowElementWalker walker = new(visitor); - walker.Visit(workflowElement); - - return visitor.Complete(workflowNamespace, workflowPrefix); - } - private static AdaptiveDialog ReadWorkflow(TextReader yamlReader) { BotElement rootElement = YamlSerializer.Deserialize(yamlReader) ?? throw new DeclarativeModelException("Workflow undefined."); diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowCodeBuilder.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowCodeBuilder.cs deleted file mode 100644 index 33eb5b6a0e..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowCodeBuilder.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Collections.Generic; -using System.Diagnostics; -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -namespace Microsoft.Agents.AI.Workflows.Declarative.Interpreter; - -internal sealed class WorkflowCodeBuilder : IModelBuilder -{ - private readonly HashSet _actions; - private readonly List _definitions; - private readonly List _instances; - private readonly List _edges; - private readonly string _rootId; - - public WorkflowCodeBuilder(string rootId) - { - this._actions = []; - this._definitions = []; - this._instances = []; - this._edges = []; - this._rootId = rootId; - } - - public string GenerateCode(string? workflowNamespace, string? workflowPrefix) - { - ProviderTemplate template = - new(this._rootId, this._definitions, this._instances, this._edges) - { - Namespace = workflowNamespace, - Prefix = workflowPrefix, - }; - - return template.TransformText().Trim(); - } - - public void Connect(IModeledAction source, IModeledAction target, string? condition) - { - Debug.WriteLine($"> CONNECT: {source.Id} => {target.Id}{(condition is null ? string.Empty : " (?)")}"); - - this.HandelAction(source); - this.HandelAction(target); - - this._edges.Add(new EdgeTemplate(source.Id, target.Id, condition).TransformText()); - } - - private void HandelAction(IModeledAction action) - { - // All templates are based on "CodeTemplate" - if (action is not CodeTemplate template) - { - // Something has gone very wrong. - throw new DeclarativeModelException($"Unable to generate code for: {action.GetType().Name}."); - } - - if (this._actions.Add(action.Id)) - { - switch (action) - { - case EmptyTemplate: - case DefaultTemplate: - this._instances.Add(template.TransformText()); - break; - case ActionTemplate actionTemplate: - this._definitions.Add(template.TransformText()); - this._instances.Add(new InstanceTemplate(action.Id, this._rootId, actionTemplate.UseAgentProvider).TransformText()); - break; - case RootTemplate: - this._definitions.Add(template.TransformText()); - break; - } - } - } -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowTemplateVisitor.cs b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowTemplateVisitor.cs deleted file mode 100644 index f754c45c62..0000000000 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Interpreter/WorkflowTemplateVisitor.cs +++ /dev/null @@ -1,500 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.Diagnostics; -using System.Linq; -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Extensions; -using Microsoft.Agents.AI.Workflows.Declarative.ObjectModel; -using Microsoft.Agents.AI.Workflows.Declarative.PowerFx; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.Interpreter; - -internal sealed class WorkflowTemplateVisitor : DialogActionVisitor -{ - private readonly string _rootId; - private readonly WorkflowModel _workflowModel; - - public WorkflowTemplateVisitor( - string workflowId, - WorkflowTypeInfo typeInfo) - { - this._rootId = workflowId; - this._workflowModel = new WorkflowModel(new RootTemplate(workflowId, typeInfo)); - - WorkflowDiagnostics.SetFoundryProduct(); - } - - public bool HasUnsupportedActions { get; private set; } - - public string Complete(string? workflowNamespace = null, string? workflowPrefix = null) - { - WorkflowCodeBuilder builder = new(this._rootId); - - this._workflowModel.Build(builder); - - return builder.GenerateCode(workflowNamespace, workflowPrefix); - } - - protected override void Visit(ActionScope item) - { - this.Trace(item); - - string parentId = GetParentId(item); - - // Handle case where root element is its own parent - if (item.Id.Equals(parentId)) - { - parentId = WorkflowActionVisitor.Steps.Root(parentId); - } - - this.ContinueWith(new EmptyTemplate(item.Id.Value, this._rootId), parentId, condition: null, CompletionHandler); - - //// Complete the action scope. - void CompletionHandler() - { - // No completion for root scope - if (this._workflowModel.GetDepth(item.Id.Value) > 1) - { - // Define post action for this scope - string completionId = this.ContinuationFor(item.Id.Value); - this._workflowModel.AddLinkFromPeer(item.Id.Value, completionId); - // Transition to post action of parent scope - this._workflowModel.AddLink(completionId, WorkflowActionVisitor.Steps.Post(parentId)); - } - } - } - - public override void VisitConditionItem(ConditionItem item) - { - this.Trace(item); - - string parentId = GetParentId(item); - ConditionGroupTemplate? conditionGroup = this._workflowModel.LocateParent(parentId); - if (conditionGroup is not null) - { - string stepId = ConditionGroupExecutor.Steps.Item(conditionGroup.Model, item); - this._workflowModel.AddNode(new EmptyTemplate(stepId, this._rootId), parentId, CompletionHandler); - - base.VisitConditionItem(item); - - // Complete the condition item. - void CompletionHandler() - { - string completionId = this.ContinuationFor(stepId); - this._workflowModel.AddLink(completionId, WorkflowActionVisitor.Steps.Post(conditionGroup.Id)); - - // Merge link when no action group is defined - if (!item.Actions.Any()) - { - this._workflowModel.AddLink(stepId, completionId); - } - } - } - } - - protected override void Visit(ConditionGroup item) - { - this.Trace(item); - - ConditionGroupTemplate action = new(item); - this.ContinueWith(action); - this.ContinuationFor(action.Id, parentId: action.ParentId); - - string? lastConditionItemId = null; - foreach (ConditionItem conditionItem in item.Conditions) - { - // Create conditional link for conditional action - lastConditionItemId = ConditionGroupExecutor.Steps.Item(item, conditionItem); - this._workflowModel.AddLink(action.Id, lastConditionItemId, $@"ActionExecutor.IsMatch(""{lastConditionItemId}"", result)"); - - conditionItem.Accept(this); - } - - if (item.ElseActions?.Actions.Length > 0) - { - if (lastConditionItemId is not null) - { - // Create clean start for else action from prior conditions - this.RestartAfter(lastConditionItemId, action.Id); - } - - // Create conditional link for else action - string stepId = ConditionGroupExecutor.Steps.Else(item); - this._workflowModel.AddLink(action.Id, stepId, $@"ActionExecutor.IsMatch(""{stepId}"", result)"); - } - } - - protected override void Visit(GotoAction item) - { - this.Trace(item); - - // Represent action with default executor - DefaultTemplate action = new(item, this._rootId); - this.ContinueWith(action); - // Transition to target action - this._workflowModel.AddLink(action.Id, item.ActionId.Value); - // Define a clean-start to ensure "goto" is not a source for any edge - this.RestartAfter(action.Id, action.ParentId); - } - - protected override void Visit(Foreach item) - { - this.Trace(item); - - // Entry point for loop - ForeachTemplate action = new(item); - string loopId = ForeachExecutor.Steps.Next(action.Id); - this.ContinueWith(action, condition: null, CompletionHandler); // Foreach - // Transition to select the next item - this.ContinueWith(new EmptyTemplate(loopId, this._rootId, $"{action.Id.FormatName()}.{nameof(ForeachExecutor.TakeNextAsync)}"), action.Id); - - // Transition to post action if no more items - string continuationId = this.ContinuationFor(action.Id, parentId: action.ParentId); // Action continuation - this._workflowModel.AddLink(loopId, continuationId, $"!{action.Id.FormatName()}.{nameof(ForeachExecutor.HasValue)}"); - - // Transition to start of inner actions if there is a current item - string startId = ForeachExecutor.Steps.Start(action.Id); - this._workflowModel.AddNode(new EmptyTemplate(startId, this._rootId), action.Id); - this._workflowModel.AddLink(loopId, startId, $"{action.Id.FormatName()}.{nameof(ForeachExecutor.HasValue)}"); - - void CompletionHandler() - { - // Transition to end of inner actions - string endActionsId = ForeachExecutor.Steps.End(action.Id); // Loop continuation - this.ContinueWith(new EmptyTemplate(endActionsId, this._rootId, $"{action.Id.FormatName()}.{nameof(ForeachExecutor.CompleteAsync)}"), action.Id); - // Transition to select the next item - this._workflowModel.AddLink(endActionsId, loopId); - } - } - - protected override void Visit(BreakLoop item) - { - this.Trace(item); - - // Locate the nearest "Foreach" loop that contains this action - ForeachTemplate? loopAction = this._workflowModel.LocateParent(item.GetParentId()); - // Skip action if its not contained a loop - if (loopAction is not null) - { - // Represent action with default executor - DefaultTemplate action = new(item, this._rootId); - this.ContinueWith(action); - // Transition to post action - this._workflowModel.AddLink(action.Id, WorkflowActionVisitor.Steps.Post(loopAction.Id)); - // Define a clean-start to ensure "break" is not a source for any edge - this.RestartAfter(action.Id, action.ParentId); - } - } - - protected override void Visit(ContinueLoop item) - { - this.Trace(item); - - // Locate the nearest "Foreach" loop that contains this action - ForeachTemplate? loopAction = this._workflowModel.LocateParent(item.GetParentId()); - // Skip action if its not contained a loop - if (loopAction is not null) - { - // Represent action with default executor - DefaultTemplate action = new(item, this._rootId); - this.ContinueWith(action); - // Transition to select the next item - this._workflowModel.AddLink(action.Id, ForeachExecutor.Steps.Start(loopAction.Id)); - // Define a clean-start to ensure "continue" is not a source for any edge - this.RestartAfter(action.Id, action.ParentId); - } - } - - protected override void Visit(Question item) - { - this.NotSupported(item); - } - - protected override void Visit(RequestExternalInput item) - { - this.NotSupported(item); - } - - protected override void Visit(EndDialog item) - { - this.Trace(item); - - // Represent action with default executor - DefaultTemplate action = new(item, this._rootId); - this.ContinueWith(action); - // Define a clean-start to ensure "end" is not a source for any edge - this.RestartAfter(action.Id, action.ParentId); - } - - protected override void Visit(EndConversation item) - { - this.Trace(item); - - // Represent action with default executor - DefaultTemplate action = new(item, this._rootId); - this.ContinueWith(action); - // Define a clean-start to ensure "end" is not a source for any edge - this.RestartAfter(action.Id, action.ParentId); - } - - protected override void Visit(CancelAllDialogs item) - { - // Represent action with default executor - DefaultTemplate action = new(item, this._rootId); - this.ContinueWith(action); - // Define a clean-start to ensure "end" is not a source for any edge - this.RestartAfter(action.Id, action.ParentId); - } - - protected override void Visit(CancelDialog item) - { - // Represent action with default executor - DefaultTemplate action = new(item, this._rootId); - this.ContinueWith(action); - // Define a clean-start to ensure "end" is not a source for any edge - this.RestartAfter(action.Id, action.ParentId); - } - - protected override void Visit(CreateConversation item) - { - this.Trace(item); - - this.ContinueWith(new CreateConversationTemplate(item)); - } - - protected override void Visit(AddConversationMessage item) - { - this.Trace(item); - - this.ContinueWith(new AddConversationMessageTemplate(item)); - } - - protected override void Visit(CopyConversationMessages item) - { - this.Trace(item); - - this.ContinueWith(new CopyConversationMessagesTemplate(item)); - } - - protected override void Visit(InvokeAzureAgent item) - { - this.Trace(item); - - this.ContinueWith(new InvokeAzureAgentTemplate(item)); - } - - protected override void Visit(InvokeAzureResponse item) - { - this.NotSupported(item); - } - - protected override void Visit(RetrieveConversationMessage item) - { - this.Trace(item); - - this.ContinueWith(new RetrieveConversationMessageTemplate(item)); - } - - protected override void Visit(RetrieveConversationMessages item) - { - this.Trace(item); - - this.ContinueWith(new RetrieveConversationMessagesTemplate(item)); - } - - protected override void Visit(SetVariable item) - { - this.Trace(item); - - this.ContinueWith(new SetVariableTemplate(item)); - } - - protected override void Visit(SetMultipleVariables item) - { - this.Trace(item); - - this.ContinueWith(new SetMultipleVariablesTemplate(item)); - } - - protected override void Visit(SetTextVariable item) - { - this.Trace(item); - - this.ContinueWith(new SetTextVariableTemplate(item)); - } - - protected override void Visit(ClearAllVariables item) - { - this.Trace(item); - - this.ContinueWith(new ClearAllVariablesTemplate(item)); - } - - protected override void Visit(ResetVariable item) - { - this.Trace(item); - - this.ContinueWith(new ResetVariableTemplate(item)); - } - - protected override void Visit(EditTable item) - { - this.NotSupported(item); - } - - protected override void Visit(EditTableV2 item) - { - this.NotSupported(item); - } - - protected override void Visit(ParseValue item) - { - this.Trace(item); - - this.ContinueWith(new ParseValueTemplate(item)); - } - - protected override void Visit(SendActivity item) - { - this.Trace(item); - - this.ContinueWith(new SendActivityTemplate(item)); - } - - #region Not supported - - protected override void Visit(InvokeMcpTool item) => this.NotSupported(item); - - protected override void Visit(InvokeFunctionTool item) => this.NotSupported(item); - - protected override void Visit(AnswerQuestionWithAI item) => this.NotSupported(item); - - protected override void Visit(DeleteActivity item) => this.NotSupported(item); - - protected override void Visit(GetActivityMembers item) => this.NotSupported(item); - - protected override void Visit(UpdateActivity item) => this.NotSupported(item); - - protected override void Visit(ActivateExternalTrigger item) => this.NotSupported(item); - - protected override void Visit(DisableTrigger item) => this.NotSupported(item); - - protected override void Visit(WaitForConnectorTrigger item) => this.NotSupported(item); - - protected override void Visit(InvokeConnectorAction item) => this.NotSupported(item); - - protected override void Visit(InvokeCustomModelAction item) => this.NotSupported(item); - - protected override void Visit(InvokeFlowAction item) => this.NotSupported(item); - - protected override void Visit(InvokeAIBuilderModelAction item) => this.NotSupported(item); - - protected override void Visit(InvokeSkillAction item) => this.NotSupported(item); - - protected override void Visit(AdaptiveCardPrompt item) => this.NotSupported(item); - - protected override void Visit(CSATQuestion item) => this.NotSupported(item); - - protected override void Visit(OAuthInput item) => this.NotSupported(item); - - protected override void Visit(BeginDialog item) => this.NotSupported(item); - - protected override void Visit(UnknownDialogAction item) => this.NotSupported(item); - - protected override void Visit(RepeatDialog item) => this.NotSupported(item); - - protected override void Visit(ReplaceDialog item) => this.NotSupported(item); - - protected override void Visit(EmitEvent item) => this.NotSupported(item); - - protected override void Visit(GetConversationMembers item) => this.NotSupported(item); - - protected override void Visit(HttpRequestAction item) => this.NotSupported(item); - - protected override void Visit(RecognizeIntent item) => this.NotSupported(item); - - protected override void Visit(TransferConversation item) => this.NotSupported(item); - - protected override void Visit(TransferConversationV2 item) => this.NotSupported(item); - - protected override void Visit(SignOutUser item) => this.NotSupported(item); - - protected override void Visit(LogCustomTelemetryEvent item) => this.NotSupported(item); - - protected override void Visit(DisconnectedNodeContainer item) => this.NotSupported(item); - - protected override void Visit(CreateSearchQuery item) => this.NotSupported(item); - - protected override void Visit(SearchKnowledgeSources item) => this.NotSupported(item); - - protected override void Visit(SearchAndSummarizeWithCustomModel item) => this.NotSupported(item); - - protected override void Visit(SearchAndSummarizeContent item) => this.NotSupported(item); - - #endregion - - private void ContinueWith( - ActionTemplate action, - string? condition = null, - Action? completionHandler = null) - { - this.ContinueWith(action, action.ParentId, condition, completionHandler); - } - - private void ContinueWith( - IModeledAction action, - string parentId, - string? condition = null, - Action? completionHandler = null) - { - this._workflowModel.AddNode(action, parentId, completionHandler); - this._workflowModel.AddLinkFromPeer(parentId, action.Id, condition); - } - - private string ContinuationFor(string parentId, string? stepAction = null) => this.ContinuationFor(parentId, parentId, stepAction); - - private string ContinuationFor(string actionId, string parentId, string? stepAction = null) - { - actionId = WorkflowActionVisitor.Steps.Post(actionId); - - this._workflowModel.AddNode(new EmptyTemplate(actionId, this._rootId, stepAction), parentId); - - return actionId; - } - - private void RestartAfter(string actionId, string parentId) => - this._workflowModel.AddNode(new EmptyTemplate(WorkflowActionVisitor.Steps.Restart(actionId), this._rootId), parentId); - - private static string GetParentId(BotElement item) => - item.GetParentId() ?? - throw new DeclarativeModelException($"Missing parent ID for action element: {item.GetId()} [{item.GetType().Name}]."); - - private void NotSupported(DialogAction item) - { - Debug.WriteLine($"> UNKNOWN: {FormatItem(item)} => {FormatParent(item)}"); - this.HasUnsupportedActions = true; - } - - private void Trace(BotElement item) => - Debug.WriteLine($"> VISIT: {new string('\t', this._workflowModel.GetDepth(item.GetParentId()))}{FormatItem(item)} => {FormatParent(item)}"); - - private void Trace(DialogAction item) - { - string? parentId = item.GetParentId(); - if (item.Id.Equals(parentId ?? string.Empty)) - { - parentId = WorkflowActionVisitor.Steps.Root(parentId); - } - - Debug.WriteLine($"> VISIT: {new string('\t', this._workflowModel.GetDepth(parentId))}{FormatItem(item)} => {FormatParent(item)}"); - } - - private static string FormatItem(BotElement element) => $"{element.GetType().Name} ({element.GetId()})"; - - private static string FormatParent(BotElement element) => - element.Parent is null ? - throw new DeclarativeModelException($"Undefined parent for {element.GetType().Name} that is member of {element.GetId()}.") : - $"{element.Parent.GetType().Name} ({element.GetParentId()})"; -} diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Microsoft.Agents.AI.Workflows.Declarative.csproj b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Microsoft.Agents.AI.Workflows.Declarative.csproj index d0ba8406b5..5f8cd37505 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Microsoft.Agents.AI.Workflows.Declarative.csproj +++ b/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/Microsoft.Agents.AI.Workflows.Declarative.csproj @@ -38,18 +38,6 @@ - - - TextTemplatingFilePreprocessor - %(Filename).cs - - - %(Filename).tt - True - True - - - diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/DeclarativeWorkflowTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/DeclarativeWorkflowTest.cs index eb1d0f55a2..d9be652a5b 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/DeclarativeWorkflowTest.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/DeclarativeWorkflowTest.cs @@ -33,7 +33,8 @@ public Task ValidateCaseAsync(string workflowFileName, string testcaseFileName, public Task ValidateScenarioAsync(string workflowFileName, string testcaseFileName, bool externalConveration = false) => this.RunWorkflowAsync(GetWorkflowPath(workflowFileName, isSample: true), testcaseFileName, externalConveration); - [Theory(Skip = "Multi-turn tests hang in CI - needs investigation")] + [Theory] + [Trait("Category", "IntegrationDisabled")] // Multi-turn tests hang in CI - needs investigation [InlineData("ConfirmInput.yaml", "ConfirmInput.json", false)] [InlineData("RequestExternalInput.yaml", "RequestExternalInput.json", false)] public Task ValidateMultiTurnAsync(string workflowFileName, string testcaseFileName, bool isSample) => diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj index 37c0fa98cf..621e685287 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests/Microsoft.Agents.AI.Workflows.Declarative.IntegrationTests.csproj @@ -30,6 +30,7 @@ Never + Always diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/AddConversationMessageTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/AddConversationMessageTemplateTest.cs deleted file mode 100644 index 786563d688..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/AddConversationMessageTemplateTest.cs +++ /dev/null @@ -1,151 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Collections.Generic; -using System.Collections.Immutable; -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class AddConversationMessageTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void NoRole() - { - // Act, Assert - this.ExecuteTest( - nameof(AddConversationMessage), - "TestVariable", - conversation: StringExpression.Literal("#rev_9"), - content: - [ - new AddConversationMessageContent.Builder() - { - Type = AgentMessageContentType.Text, - Value = TemplateLine.Parse("Hello! How can I help you today?"), - }, - ]); - } - - [Fact] - public void WithRole() - { - // Act, Assert - this.ExecuteTest( - nameof(AddConversationMessage), - "TestVariable", - conversation: StringExpression.Variable(PropertyPath.Create("System.ConversationId")), - role: AgentMessageRoleWrapper.Get(AgentMessageRole.Agent), - content: - [ - new AddConversationMessageContent.Builder() - { - Type = AgentMessageContentType.Text, - Value = TemplateLine.Parse("Hello! How can I help you today?"), - }, - ]); - } - - [Fact] - public void WithMetadataLiteral() - { - // Act, Assert - this.ExecuteTest( - nameof(AddConversationMessage), - "TestVariable", - conversation: StringExpression.Variable(PropertyPath.Create("System.Conversation.Id")), - role: AgentMessageRoleWrapper.Get(AgentMessageRole.Agent), - metadata: ObjectExpression.Literal( - new RecordDataValue( - new Dictionary - { - { "key1", StringDataValue.Create("value1") }, - { "key2", NumberDataValue.Create(42) }, - }.ToImmutableDictionary())), - content: - [ - new AddConversationMessageContent.Builder() - { - Type = AgentMessageContentType.Text, - Value = TemplateLine.Parse("Hello! How can I help you today?"), - }, - ]); - } - - [Fact] - public void WithMetadataVariable() - { - // Act, Assert - this.ExecuteTest( - nameof(AddConversationMessage), - "TestVariable", - conversation: StringExpression.Literal("#rev_9"), - role: AgentMessageRoleWrapper.Get(AgentMessageRole.Agent), - metadata: ObjectExpression.Variable(PropertyPath.TopicVariable("MyMetadata")), - content: - [ - new AddConversationMessageContent.Builder() - { - Type = AgentMessageContentType.Text, - Value = TemplateLine.Parse("Hello! How can I help you today?"), - }, - ]); - } - - private void ExecuteTest( - string displayName, - string variableName, - StringExpression conversation, - IEnumerable content, - AgentMessageRoleWrapper? role = null, - ObjectExpression.Builder? metadata = null) - { - // Arrange - AddConversationMessage model = - this.CreateModel( - displayName, - FormatVariablePath(variableName), - conversation, - content, - role, - metadata); - - // Act - AddConversationMessageTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - AssertGeneratedAssignment(model.Message?.Path, workflowCode); - } - - private AddConversationMessage CreateModel( - string displayName, - string variablePath, - StringExpression conversation, - IEnumerable contents, - AgentMessageRoleWrapper? role, - ObjectExpression.Builder? metadata) - { - AddConversationMessage.Builder actionBuilder = - new() - { - Id = this.CreateActionId("add_message"), - DisplayName = this.FormatDisplayName(displayName), - ConversationId = conversation, - Message = PropertyPath.Create(variablePath), - Role = role, - Metadata = metadata, - }; - - foreach (AddConversationMessageContent.Builder content in contents) - { - actionBuilder.Content.Add(content); - } - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/BreakLoopTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/BreakLoopTemplateTest.cs deleted file mode 100644 index 2960718256..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/BreakLoopTemplateTest.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class BreakLoopTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void BreakLoop() - { - // Act, Assert - this.ExecuteTest(nameof(BreakLoop)); - } - - private void ExecuteTest(string displayName) - { - // Arrange - BreakLoop model = this.CreateModel(displayName); - - // Act - DefaultTemplate template = new(model, "workflow_id"); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertDelegate(template.Id, "workflow_id", workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - } - - private BreakLoop CreateModel(string displayName) - { - BreakLoop.Builder actionBuilder = - new() - { - Id = this.CreateActionId("break_loop"), - DisplayName = this.FormatDisplayName(displayName), - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ClearAllVariablesTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ClearAllVariablesTemplateTest.cs deleted file mode 100644 index be7ea25eab..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ClearAllVariablesTemplateTest.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class ClearAllVariablesTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void LiteralEnum() - { - // Arrange - EnumExpression.Builder expressionBuilder = new(EnumExpression.Literal(VariablesToClear.AllGlobalVariables)); - - // Act, Assert - this.ExecuteTest(nameof(LiteralEnum), expressionBuilder); - } - - [Fact] - public void VariableEnum() - { - // Arrange - EnumExpression.Builder expressionBuilder = new(EnumExpression.Variable(PropertyPath.TopicVariable("MyClearEnum"))); - - // Act, Assert - this.ExecuteTest(nameof(VariableEnum), expressionBuilder); - } - - [Fact] - public void UnsupportedEnum() - { - // Arrange - EnumExpression.Builder expressionBuilder = new(EnumExpression.Literal(VariablesToClear.UserScopedVariables)); - - // Act, Assert - this.ExecuteTest(nameof(UnsupportedEnum), expressionBuilder); - } - - private void ExecuteTest( - string displayName, - EnumExpression.Builder variablesExpression) - { - // Arrange - ClearAllVariables model = - this.CreateModel( - displayName, - variablesExpression); - - // Act - ClearAllVariablesTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - } - - private ClearAllVariables CreateModel( - string displayName, - EnumExpression.Builder variablesExpression) - { - ClearAllVariables.Builder actionBuilder = - new() - { - Id = this.CreateActionId("set_variable"), - DisplayName = this.FormatDisplayName(displayName), - Variables = variablesExpression, - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ConditionGroupTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ConditionGroupTemplateTest.cs deleted file mode 100644 index af0166c44e..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ConditionGroupTemplateTest.cs +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class ConditionGroupTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void NoElse() - { - // Act, Assert - this.ExecuteTest( - nameof(WithElse), - hasElse: false); - } - - [Fact] - public void WithElse() - { - // Act, Assert - this.ExecuteTest( - nameof(WithElse), - hasElse: true); - } - - private void ExecuteTest(string displayName, bool hasElse = false) - { - // Arrange - ConditionGroup model = this.CreateModel(displayName, hasElse); - - // Act - ConditionGroupTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - foreach (ConditionItem condition in model.Conditions) - { - Assert.Contains(@$"""{condition.Id}""", workflowCode); - } - if (model.ElseActions?.Actions.Length > 0) - { - Assert.Contains(@$"""{model.ElseActions.Id}""", workflowCode); - } - } - - private ConditionGroup CreateModel(string displayName, bool hasElse = false) - { - ConditionGroup.Builder actionBuilder = - new() - { - Id = this.CreateActionId("condition_group"), - DisplayName = this.FormatDisplayName(displayName), - }; - - actionBuilder.Conditions.Add( - new ConditionItem.Builder - { - Id = "condition_item_a", - Condition = BoolExpression.Expression("2 > 3"), - Actions = this.CreateActions("condition_a"), - }); - - actionBuilder.Conditions.Add( - new ConditionItem.Builder - { - Id = "condition_item_b", - Condition = BoolExpression.Expression("2 < 3"), - Actions = this.CreateActions("condition_b"), - }); - - if (hasElse) - { - actionBuilder.ElseActions = this.CreateActions("condition_else"); - } - - return actionBuilder.Build(); - } - - private ActionScope.Builder CreateActions(string prefix, int count = 2) - { - ActionScope.Builder actions = - new() - { - Id = this.CreateActionId("${prefix}_actions"), - }; - for (int index = 1; index <= count; ++index) - { - actions.Actions.Add( - new SendActivity.Builder - { - Id = this.CreateActionId($"{prefix}_action_{index}"), - Activity = new MessageActivityTemplate - { - //Value = TemplateLine.Parse($"This is message #{index}"), - }, - }); - } - - return actions; - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ContinueLoopTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ContinueLoopTemplateTest.cs deleted file mode 100644 index 9210460701..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ContinueLoopTemplateTest.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class ContinueLoopTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void ContinueLoop() - { - // Act, Assert - this.ExecuteTest(nameof(ContinueLoop)); - } - - private void ExecuteTest(string displayName) - { - // Arrange - ContinueLoop model = this.CreateModel(displayName); - - // Act - DefaultTemplate template = new(model, "workflow_id"); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertDelegate(template.Id, "workflow_id", workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - } - - private ContinueLoop CreateModel(string displayName) - { - ContinueLoop.Builder actionBuilder = - new() - { - Id = this.CreateActionId("continue_loop"), - DisplayName = this.FormatDisplayName(displayName), - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/CopyConversationMessagesTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/CopyConversationMessagesTemplateTest.cs deleted file mode 100644 index 5f005b6b3b..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/CopyConversationMessagesTemplateTest.cs +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class CopyConversationMessagesTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void CopyConversationMessagesLiteral() - { - // Act, Assert - this.ExecuteTest( - nameof(CopyConversationMessagesLiteral), - StringExpression.Literal("#conv_dm99"), - ValueExpression.Variable(PropertyPath.TopicVariable("MyMessages"))); - } - - [Fact] - public void CopyConversationMessagesVariable() - { - // Act, Assert - this.ExecuteTest( - nameof(CopyConversationMessagesVariable), - StringExpression.Variable(PropertyPath.TopicVariable("TestConversation")), - ValueExpression.Variable(PropertyPath.TopicVariable("MyMessages"))); - } - - private void ExecuteTest( - string displayName, - StringExpression conversation, - ValueExpression messages, - ValueExpression? metadata = null) - { - // Arrange - CopyConversationMessages model = - this.CreateModel( - displayName, - conversation, - messages); - - // Act - CopyConversationMessagesTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - } - - private CopyConversationMessages CreateModel( - string displayName, - StringExpression conversation, - ValueExpression messages, - ValueExpression? metadata = null) - { - CopyConversationMessages.Builder actionBuilder = - new() - { - Id = this.CreateActionId("copy_messages"), - DisplayName = this.FormatDisplayName(displayName), - ConversationId = conversation, - Messages = messages, - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/CreateConversationTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/CreateConversationTemplateTest.cs deleted file mode 100644 index c4c0fd4458..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/CreateConversationTemplateTest.cs +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Collections.Generic; -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Extensions; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class CreateConversationTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void Basic() - { - // Act, Assert - this.ExecuteTest( - nameof(Basic), - "TestVariable"); - } - - [Fact] - public void WithMetadata() - { - Dictionary metadata = - new() - { - ["key1"] = "value1", - ["key2"] = "value2", - }; - - // Act, Assert - this.ExecuteTest( - nameof(WithMetadata), - "TestVariable", - ObjectExpression.Literal(metadata.ToRecordValue())); - } - - private void ExecuteTest( - string displayName, - string variableName, - ObjectExpression? metadata = null) - { - // Arrange - CreateConversation model = - this.CreateModel( - displayName, - FormatVariablePath(variableName), - metadata); - - // Act - CreateConversationTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - AssertGeneratedAssignment(model.ConversationId?.Path, workflowCode); - } - - private CreateConversation CreateModel( - string displayName, - string variablePath, - ObjectExpression? metadata = null) - { - CreateConversation.Builder actionBuilder = - new() - { - Id = this.CreateActionId("create_conversation"), - DisplayName = this.FormatDisplayName(displayName), - ConversationId = PropertyPath.Create(variablePath), - }; - - if (metadata is not null) - { - actionBuilder.Metadata = metadata; - } - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/DeclarativeEjectionTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/DeclarativeEjectionTest.cs deleted file mode 100644 index 0c6ac9efe7..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/DeclarativeEjectionTest.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System; -using System.IO; -using System.Threading.Tasks; -using Shared.Code; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -/// -/// Tests execution of workflow created by . -/// -public sealed class DeclarativeEjectionTest(ITestOutputHelper output) : WorkflowTest(output) -{ - [Theory] - [InlineData("AddConversationMessage.yaml")] - [InlineData("CancelWorkflow.yaml")] - [InlineData("ClearAllVariables.yaml")] - [InlineData("CopyConversationMessages.yaml")] - [InlineData("Condition.yaml")] - [InlineData("ConditionElse.yaml")] - [InlineData("CreateConversation.yaml")] - [InlineData("EditTable.yaml")] - [InlineData("EditTableV2.yaml")] - [InlineData("EndConversation.yaml")] - [InlineData("EndWorkflow.yaml")] - [InlineData("Goto.yaml")] - [InlineData("InvokeAgent.yaml")] - [InlineData("LoopBreak.yaml")] - [InlineData("LoopContinue.yaml")] - [InlineData("LoopEach.yaml")] - [InlineData("ParseValue.yaml")] - [InlineData("ResetVariable.yaml")] - [InlineData("RetrieveConversationMessage.yaml")] - [InlineData("RetrieveConversationMessages.yaml")] - [InlineData("SendActivity.yaml")] - [InlineData("SetVariable.yaml")] - [InlineData("SetTextVariable.yaml")] - public Task ExecuteActionAsync(string workflowFile) => - this.EjectWorkflowAsync(workflowFile); - - private async Task EjectWorkflowAsync(string workflowFile) - { - using StreamReader yamlReader = File.OpenText(Path.Combine("Workflows", workflowFile)); - string workflowCode = DeclarativeWorkflowBuilder.Eject(yamlReader, DeclarativeWorkflowLanguage.CSharp, "Test.WorkflowProviders"); - - string baselinePath = Path.Combine("Workflows", Path.ChangeExtension(workflowFile, ".cs")); - string generatedPath = Path.Combine("Workflows", Path.ChangeExtension(workflowFile, ".g.cs")); - - this.Output.WriteLine($"WRITING BASELINE TO: {Path.GetFullPath(generatedPath)}\n"); - - try - { - File.WriteAllText(Path.GetFullPath(generatedPath), workflowCode); - Compiler.Build(workflowCode, Compiler.RepoDependencies(typeof(DeclarativeWorkflowBuilder))); // Throws if build fails - } - finally - { - Console.WriteLine(workflowCode); - } - - string expectedCode = File.ReadAllText(baselinePath); - string[] expectedLines = expectedCode.Trim().Split('\n'); - string[] workflowLines = workflowCode.Trim().Split('\n'); - - Assert.Equal(expectedLines.Length, workflowLines.Length); - - for (int index = 0; index < workflowLines.Length; ++index) - { - this.Output.WriteLine($"Comparing line #{index + 1}/{workflowLines.Length}."); - Assert.Equal(expectedLines[index].Trim(), workflowLines[index].Trim()); - } - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/EdgeTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/EdgeTemplateTest.cs deleted file mode 100644 index 10633f4581..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/EdgeTemplateTest.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class EdgeTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void InitializeNext() - { - this.ExecuteTest("set_variable_1", "invoke_agent_2"); - } - - private void ExecuteTest(string sourceId, string targetId) - { - // Arrange - EdgeTemplate template = new(sourceId, targetId); - - // Act - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - Assert.Equal("builder.AddEdge(setVariable1, invokeAgent2);", workflowCode.Trim()); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/EndConversationTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/EndConversationTest.cs deleted file mode 100644 index 75d2cc7b80..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/EndConversationTest.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class EndConversationTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void EndConversation() - { - // Act, Assert - this.ExecuteTest(nameof(EndConversation)); - } - - private void ExecuteTest(string displayName) - { - // Arrange - EndConversation model = this.CreateModel(displayName); - - // Act - DefaultTemplate template = new(model, "workflow_id"); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertDelegate(template.Id, "workflow_id", workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - } - - private EndConversation CreateModel(string displayName) - { - EndConversation.Builder actionBuilder = - new() - { - Id = this.CreateActionId("end_conversation"), - DisplayName = this.FormatDisplayName(displayName), - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/EndDialogTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/EndDialogTest.cs deleted file mode 100644 index aea9b76833..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/EndDialogTest.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class EndDialogTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void EndDialog() - { - // Act, Assert - this.ExecuteTest(nameof(EndDialog)); - } - - private void ExecuteTest(string displayName) - { - // Arrange - EndDialog model = this.CreateModel(displayName); - - // Act - DefaultTemplate template = new(model, "workflow_id"); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertDelegate(template.Id, "workflow_id", workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - } - - private EndDialog CreateModel(string displayName) - { - EndDialog.Builder actionBuilder = - new() - { - Id = this.CreateActionId("end_Dialog"), - DisplayName = this.FormatDisplayName(displayName), - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ForeachTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ForeachTemplateTest.cs deleted file mode 100644 index d6e924c262..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ForeachTemplateTest.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.AI.Workflows.Declarative.ObjectModel; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class ForeachTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void LoopNoIndex() - { - // Act, Assert - this.ExecuteTest( - nameof(LoopNoIndex), - ValueExpression.Variable(PropertyPath.TopicVariable("MyItems")), - "LoopValue"); - } - - [Fact] - public void LoopWithIndex() - { - // Act, Assert - this.ExecuteTest( - nameof(LoopNoIndex), - ValueExpression.Variable(PropertyPath.TopicVariable("MyItems")), - "LoopValue", - "IndexValue"); - } - - private void ExecuteTest( - string displayName, - ValueExpression items, - string valueName, - string? indexName = null) - { - // Arrange - Foreach model = - this.CreateModel( - displayName, - items, - FormatVariablePath(valueName), - FormatOptionalPath(indexName)); - - // Act - ForeachTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - AssertGeneratedMethod(nameof(ForeachExecutor.TakeNextAsync), workflowCode); - AssertGeneratedMethod(nameof(ForeachExecutor.CompleteAsync), workflowCode); - } - - private Foreach CreateModel( - string displayName, - ValueExpression items, - string valueName, - string? indexName = null) - { - Foreach.Builder actionBuilder = - new() - { - Id = this.CreateActionId("loop_action"), - DisplayName = this.FormatDisplayName(displayName), - Items = items, - Value = PropertyPath.Create(valueName), - }; - - if (indexName is not null) - { - actionBuilder.Index = PropertyPath.Create(indexName); - } - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/GotoTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/GotoTemplateTest.cs deleted file mode 100644 index 1c9c2c26ad..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/GotoTemplateTest.cs +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class GotoTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void GotoAction() - { - // Act, Assert - this.ExecuteTest(nameof(GotoAction), "target_action_id"); - } - - private void ExecuteTest(string displayName, string targetId) - { - // Arrange - GotoAction model = this.CreateModel(displayName, targetId); - - // Act - DefaultTemplate template = new(model, "workflow_id"); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertDelegate(template.Id, "workflow_id", workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - } - - private GotoAction CreateModel(string displayName, string targetId) - { - GotoAction.Builder actionBuilder = - new() - { - Id = this.CreateActionId("goto_action"), - DisplayName = this.FormatDisplayName(displayName), - ActionId = new ActionId(targetId), - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/InvokeAzureAgentTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/InvokeAzureAgentTemplateTest.cs deleted file mode 100644 index 8642270726..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/InvokeAzureAgentTemplateTest.cs +++ /dev/null @@ -1,139 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class InvokeAzureAgentTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void LiteralConversation() - { - // Act, Assert - this.ExecuteTest( - nameof(LiteralConversation), - StringExpression.Literal("asst_123abc"), - StringExpression.Literal("conv_123abc"), - messagesVariable: null); - } - - [Fact] - public void VariableConversation() - { - // Act, Assert - this.ExecuteTest( - nameof(VariableConversation), - StringExpression.Variable(PropertyPath.GlobalVariable("TestAgent")), - StringExpression.Variable(PropertyPath.TopicVariable("TestConversation")), - "MyMessages", - BoolExpression.Literal(true)); - } - - [Fact] - public void ExpressionAutosend() - { - // Act, Assert - this.ExecuteTest( - nameof(VariableConversation), - StringExpression.Literal("asst_123abc"), - StringExpression.Variable(PropertyPath.TopicVariable("TestConversation")), - "MyMessages", - BoolExpression.Expression("1 < 2")); - } - - [Fact] - public void InputMessagesVariable() - { - // Act, Assert - this.ExecuteTest( - nameof(VariableConversation), - StringExpression.Literal("asst_123abc"), - StringExpression.Variable(PropertyPath.TopicVariable("TestConversation")), - "MyMessages", - messages: ValueExpression.Variable(PropertyPath.TopicVariable("TestConversation"))); - } - - [Fact] - public void InputMessagesExpression() - { - // Act, Assert - this.ExecuteTest( - nameof(VariableConversation), - StringExpression.Literal("asst_123abc"), - StringExpression.Literal("conv_123abc"), - "MyMessages", - messages: ValueExpression.Expression("[UserMessage(System.LastMessageText)]")); - } - - private void ExecuteTest( - string displayName, - StringExpression.Builder agentName, - StringExpression.Builder conversation, - string? messagesVariable = null, - BoolExpression.Builder? autoSend = null, - ValueExpression.Builder? messages = null) - { - // Arrange - InvokeAzureAgent model = - this.CreateModel( - displayName, - agentName, - conversation, - messagesVariable, - autoSend, - messages); - - // Act - InvokeAzureAgentTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - AssertOptionalAssignment(model.Output?.Messages?.Path, workflowCode); - } - - private InvokeAzureAgent CreateModel( - string displayName, - StringExpression.Builder agentName, - StringExpression.Builder conversation, - string? messagesVariable = null, - BoolExpression.Builder? autoSend = null, - ValueExpression.Builder? messages = null) - { - InitializablePropertyPath? outputMessages = null; - if (messagesVariable is not null) - { - outputMessages = PropertyPath.Create(FormatVariablePath(messagesVariable)); - } - - InvokeAzureAgent.Builder actionBuilder = - new() - { - Id = this.CreateActionId("invoke_agent"), - DisplayName = this.FormatDisplayName(displayName), - ConversationId = conversation, - Agent = - new AzureAgentUsage.Builder - { - Name = agentName, - }, - Input = - new AzureAgentInput.Builder - { - Messages = messages, - }, - Output = - new AzureAgentOutput.Builder - { - AutoSend = autoSend, - Messages = outputMessages, - }, - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ProviderTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ProviderTemplateTest.cs deleted file mode 100644 index 28ae9a0314..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ProviderTemplateTest.cs +++ /dev/null @@ -1,113 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using System.Threading.Tasks; -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class ProviderTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public async Task WithNamespaceAsync() - { - await this.ExecuteTestAsync( - [ - """ - internal sealed class TestExecutor1() : ActionExecutor(id: "test_1") - { - protected override ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { - // Nothing to do - return default; - } - } - """ - ], - [ - """ - TestExecutor1 test1 = new(); - """ - ], - [ - """ - builder.AddEdge(builder.Root, test1); - """ - ], - "Test.Workflows.Generated"); - } - - [Fact] - public async Task WithoutNamespaceAsync() - { - await this.ExecuteTestAsync( - [ - """ - internal sealed class TestExecutor1() : ActionExecutor(id: "test_1") - { - protected override ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { - // Nothing to do - return default; - } - } - - internal sealed class TestExecutor2() : ActionExecutor(id: "test_2") - { - protected override ValueTask ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken) - { - // Nothing to do - return default; - } - } - """ - ], - [ - """ - TestExecutor1 test1 = new(); - TestExecutor2 test2 = new(); - """ - ], - [ - """ - builder.AddEdge(builder.Root, test1); - builder.AddEdge(test1, test2); - """ - ]); - } - - private async Task ExecuteTestAsync( - string[] executors, - string[] instances, - string[] edges, - string? workflowNamespace = null) - { - // Arrange - ProviderTemplate template = new("worflow-id", executors, instances, edges) { Namespace = workflowNamespace }; - - // Act - string workflowCode = template.TransformText(); - - // Assert - this.Output.WriteLine(workflowCode); - - Assert.True(Contains(executors)); - Assert.True(Contains(instances)); - Assert.True(Contains(edges)); - - bool Contains(string[] code) - { - foreach (string block in code) - { - foreach (string line in block.Split('\n')) - { - if (!workflowCode.Contains(line.Trim())) - { - return false; - } - } - } - - return true; - } - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ResetVariableTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ResetVariableTemplateTest.cs deleted file mode 100644 index b34126c5be..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/ResetVariableTemplateTest.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class ResetVariableTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void ResetVariable() - { - // Act, Assert - this.ExecuteTest(nameof(ResetVariable), "TestVariable"); - } - - private void ExecuteTest(string displayName, string variableName) - { - // Arrange - ResetVariable model = - this.CreateModel( - displayName, - FormatVariablePath(variableName)); - - // Act - ResetVariableTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - } - - private ResetVariable CreateModel(string displayName, string variablePath) - { - ResetVariable.Builder actionBuilder = - new() - { - Id = this.CreateActionId("set_variable"), - DisplayName = this.FormatDisplayName(displayName), - Variable = PropertyPath.Create(variablePath) - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/RetrieveConversationMessageTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/RetrieveConversationMessageTemplateTest.cs deleted file mode 100644 index 153cb95ea4..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/RetrieveConversationMessageTemplateTest.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class RetrieveConversationMessageTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void RetrieveConversationVariable() - { - // Act, Assert - this.ExecuteTest( - nameof(RetrieveConversationVariable), - "TestVariable", - StringExpression.Variable(PropertyPath.TopicVariable("TestConversation")), - StringExpression.Literal("#mid_43")); - } - [Fact] - public void RetrieveMessageVariable() - { - // Act, Assert - this.ExecuteTest( - nameof(RetrieveMessageVariable), - "TestVariable", - StringExpression.Literal("#cid_3"), - StringExpression.Variable(PropertyPath.TopicVariable("TestMessage"))); - } - - private void ExecuteTest( - string displayName, - string variableName, - StringExpression conversationExpression, - StringExpression messageExpression) - { - // Arrange - RetrieveConversationMessage model = - this.CreateModel( - displayName, - FormatVariablePath(variableName), - conversationExpression, - messageExpression); - - // Act - RetrieveConversationMessageTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - AssertGeneratedAssignment(model.Message?.Path, workflowCode); - } - - private RetrieveConversationMessage CreateModel( - string displayName, - string variableName, - StringExpression conversationExpression, - StringExpression messageExpression) - { - RetrieveConversationMessage.Builder actionBuilder = - new() - { - Id = this.CreateActionId("retrieve_message"), - DisplayName = this.FormatDisplayName(displayName), - Message = PropertyPath.Create(variableName), - ConversationId = conversationExpression, - MessageId = messageExpression, - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/RetrieveConversationMessagesTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/RetrieveConversationMessagesTemplateTest.cs deleted file mode 100644 index 30988ef019..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/RetrieveConversationMessagesTemplateTest.cs +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class RetrieveConversationMessagesTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void DefaultQuery() - { - // Act, Assert - this.ExecuteTest( - nameof(DefaultQuery), - "TestVariable", - StringExpression.Variable(PropertyPath.TopicVariable("TestConversation"))); - } - - [Fact] - public void LimitCountQuery() - { - // Act, Assert - this.ExecuteTest( - nameof(DefaultQuery), - "TestVariable", - StringExpression.Literal("#cid_3"), - limit: IntExpression.Literal(94)); - } - - [Fact] - public void AfterMessageQuery() - { - // Act, Assert - this.ExecuteTest( - nameof(DefaultQuery), - "TestVariable", - StringExpression.Literal("#cid_3"), - after: StringExpression.Literal("#mid_43")); - } - - [Fact] - public void BeforeMessageQuery() - { - // Act, Assert - this.ExecuteTest( - nameof(DefaultQuery), - "TestVariable", - StringExpression.Literal("#cid_3"), - before: StringExpression.Literal("#mid_43")); - } - - [Fact] - public void NewestFirstQuery() - { - // Act, Assert - this.ExecuteTest( - nameof(DefaultQuery), - "TestVariable", - StringExpression.Literal("#cid_3"), - sortOrder: EnumExpression.Literal(AgentMessageSortOrderWrapper.Get(AgentMessageSortOrder.NewestFirst))); - } - - private void ExecuteTest( - string displayName, - string variableName, - StringExpression conversation, - IntExpression? limit = null, - StringExpression? after = null, - StringExpression? before = null, - EnumExpression? sortOrder = null) - { - // Arrange - RetrieveConversationMessages model = - this.CreateModel( - displayName, - FormatVariablePath(variableName), - conversation, - limit, - after, - before, - sortOrder); - - // Act - RetrieveConversationMessagesTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - AssertGeneratedAssignment(model.Messages?.Path, workflowCode); - } - - private RetrieveConversationMessages CreateModel( - string displayName, - string variableName, - StringExpression conversationExpression, - IntExpression? limitExpression, - StringExpression? afterExpression, - StringExpression? beforeExpression, - EnumExpression? sortExpression) - { - RetrieveConversationMessages.Builder actionBuilder = - new() - { - Id = this.CreateActionId("retrieve_messages"), - DisplayName = this.FormatDisplayName(displayName), - Messages = PropertyPath.Create(variableName), - ConversationId = conversationExpression, - }; - - if (limitExpression is not null) - { - actionBuilder.Limit = limitExpression; - } - - if (afterExpression is not null) - { - actionBuilder.MessageAfter = afterExpression; - } - - if (beforeExpression is not null) - { - actionBuilder.MessageBefore = beforeExpression; - } - - if (sortExpression is not null) - { - actionBuilder.SortOrder = sortExpression; - } - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/SetMultipleVariablesTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/SetMultipleVariablesTemplateTest.cs deleted file mode 100644 index 91387705e0..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/SetMultipleVariablesTemplateTest.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; -using Microsoft.PowerFx.Types; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class SetMultipleVariablesTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void InitializeMultipleValues() - { - // Act, Assert - this.ExecuteTest( - nameof(InitializeMultipleValues), - new AssignmentCase("TestVariable1", new ValueExpression.Builder(ValueExpression.Literal(new NumberDataValue(420))), FormulaValue.New(420)), - new AssignmentCase("TestVariable2", new ValueExpression.Builder(ValueExpression.Variable(PropertyPath.TopicVariable("MyValue"))), FormulaValue.New(6)), - new AssignmentCase("TestVariable3", new ValueExpression.Builder(ValueExpression.Expression("9 - 3")), FormulaValue.New(6))); - } - - private void ExecuteTest(string displayName, params AssignmentCase[] assignments) - { - // Arrange - SetMultipleVariables model = - this.CreateModel( - displayName, - assignments); - - // Act - SetMultipleVariablesTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - foreach (AssignmentCase assignment in assignments) - { - AssertGeneratedAssignment(PropertyPath.TopicVariable(assignment.Path), workflowCode); - } - } - - private SetMultipleVariables CreateModel(string displayName, params AssignmentCase[] assignments) - { - SetMultipleVariables.Builder actionBuilder = - new() - { - Id = this.CreateActionId("set_multiple"), - DisplayName = this.FormatDisplayName(displayName), - }; - - foreach (AssignmentCase assignment in assignments) - { - actionBuilder.Assignments.Add( - new VariableAssignment.Builder() - { - Variable = PropertyPath.Create(FormatVariablePath(assignment.Path)), - Value = assignment.Expression, - }); - } - - return actionBuilder.Build(); - } - - private sealed record AssignmentCase(string Path, ValueExpression.Builder Expression, FormulaValue Expected); -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/SetTextVariableTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/SetTextVariableTemplateTest.cs deleted file mode 100644 index 9a503394de..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/SetTextVariableTemplateTest.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class SetTextVariableTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void InitializeTemplate() - { - // Act, Assert - this.ExecuteTest(nameof(InitializeTemplate), "TestVariable", "Value: {OtherVar}"); - } - - private void ExecuteTest( - string displayName, - string variableName, - string textValue) - { - // Arrange - SetTextVariable model = - this.CreateModel( - displayName, - FormatVariablePath(variableName), - textValue); - - // Act - SetTextVariableTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - AssertGeneratedAssignment(model.Variable?.Path, workflowCode); - Assert.Contains(textValue, workflowCode); - } - - private SetTextVariable CreateModel(string displayName, string variablePath, string textValue) - { - SetTextVariable.Builder actionBuilder = - new() - { - Id = this.CreateActionId("set_variable"), - DisplayName = this.FormatDisplayName(displayName), - Variable = PropertyPath.Create(variablePath), - Value = TemplateLine.Parse(textValue), - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/SetVariableTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/SetVariableTemplateTest.cs deleted file mode 100644 index 64f8a1b6a8..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/SetVariableTemplateTest.cs +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.CodeGen; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; -using Microsoft.PowerFx.Types; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -public class SetVariableTemplateTest(ITestOutputHelper output) : WorkflowActionTemplateTest(output) -{ - [Fact] - public void InitializeLiteralValue() - { - // Arrange - ValueExpression.Builder expressionBuilder = new(ValueExpression.Literal(new NumberDataValue(420))); - - // Act, Assert - this.ExecuteTest(nameof(InitializeLiteralValue), "TestVariable", expressionBuilder, FormulaValue.New(420)); - } - - [Fact] - public void InitializeVariable() - { - // Arrange - ValueExpression.Builder expressionBuilder = new(ValueExpression.Variable(PropertyPath.TopicVariable("MyValue"))); - - // Act, Assert - this.ExecuteTest(nameof(InitializeVariable), "TestVariable", expressionBuilder, FormulaValue.New(6)); - } - - [Fact] - public void InitializeExpression() - { - ValueExpression.Builder expressionBuilder = new(ValueExpression.Expression("9 - 3")); - - // Act, Assert - this.ExecuteTest(nameof(InitializeExpression), "TestVariable", expressionBuilder, FormulaValue.New(6)); - } - - private void ExecuteTest( - string displayName, - string variableName, - ValueExpression.Builder valueExpression, - FormulaValue expectedValue) - { - // Arrange - SetVariable model = - this.CreateModel( - displayName, - FormatVariablePath(variableName), - valueExpression); - - // Act - SetVariableTemplate template = new(model); - string workflowCode = template.TransformText(); - this.Output.WriteLine(workflowCode.Trim()); - - // Assert - AssertGeneratedCode(template.Id, workflowCode); - AssertAgentProvider(template.UseAgentProvider, workflowCode); - AssertGeneratedAssignment(model.Variable?.Path, workflowCode); - } - - private SetVariable CreateModel(string displayName, string variablePath, ValueExpression.Builder valueExpression) - { - SetVariable.Builder actionBuilder = - new() - { - Id = this.CreateActionId("set_variable"), - DisplayName = this.FormatDisplayName(displayName), - Variable = PropertyPath.Create(variablePath), - Value = valueExpression, - }; - - return actionBuilder.Build(); - } -} diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/WorkflowActionTemplateTest.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/WorkflowActionTemplateTest.cs deleted file mode 100644 index 6ae2a4b45e..0000000000 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.UnitTests/CodeGen/WorkflowActionTemplateTest.cs +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (c) Microsoft. All rights reserved. - -using Microsoft.Agents.AI.Workflows.Declarative.Extensions; -using Microsoft.Agents.AI.Workflows.Declarative.Kit; -using Microsoft.Agents.ObjectModel; - -namespace Microsoft.Agents.AI.Workflows.Declarative.UnitTests.CodeGen; - -/// -/// Base test class for text template. -/// -public abstract class WorkflowActionTemplateTest(ITestOutputHelper output) : WorkflowTest(output) -{ - private int ActionIndex { get; set; } = 1; - -#pragma warning disable CA1308 // Normalize strings to uppercase - protected ActionId CreateActionId(string seed) => new($"{seed.ToLowerInvariant()}_{this.ActionIndex++}"); -#pragma warning restore CA1308 // Normalize strings to uppercase - - protected string FormatDisplayName(string name) => $"{this.GetType().Name}_{name}"; - - protected static void AssertGeneratedCode(string actionId, string workflowCode) where TBase : class - { - Assert.Contains($"internal sealed class {actionId.FormatType()}", workflowCode); - Assert.Contains($") : {typeof(TBase).Name}(", workflowCode); - Assert.Contains(@$"""{actionId}""", workflowCode); - } - - protected static void AssertGeneratedMethod(string methodName, string workflowCode) => - Assert.Contains($"ValueTask {methodName}(", workflowCode); - - protected static void AssertAgentProvider(bool expected, string workflowCode) - { - if (expected) - { - Assert.Contains($", {nameof(ResponseAgentProvider)} agentProvider", workflowCode); - } - else - { - Assert.DoesNotContain($", {nameof(ResponseAgentProvider)} agentProvider", workflowCode); - } - } - - protected static void AssertOptionalAssignment(PropertyPath? variablePath, string workflowCode) - { - if (variablePath is not null) - { - Assert.Contains(@$"key: ""{variablePath.VariableName}""", workflowCode); - Assert.Contains(@$"scopeName: ""{variablePath.NamespaceAlias}""", workflowCode); - } - } - - protected static void AssertGeneratedAssignment(PropertyPath? variablePath, string workflowCode) - { - Assert.NotNull(variablePath); - Assert.Contains(@$"key: ""{variablePath.VariableName}""", workflowCode); - Assert.Contains(@$"scopeName: ""{variablePath.NamespaceAlias}""", workflowCode); - } - - protected static void AssertDelegate(string actionId, string rootId, string workflowCode) - { - Assert.Contains($"{nameof(DelegateExecutor)} {actionId.FormatName()} = new(", workflowCode); - Assert.Contains(@$"""{actionId}""", workflowCode); - Assert.Contains($"{rootId.FormatName()}.Session", workflowCode); - } -}