Files
agent-framework/dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/CodeGen/ProviderTemplate.tt
T
Jacob Alber 0bf6d437d8 .NET: [BREAKING] .NET: Add Workflow on-Build() Orphan Validation (#1943)
* fix: Workflow Validation

* adds orphan validation to workflow builder
* adds tests for workflow validation
* expands on the underlying reasoning why type validation is not supported

* fixup: CodeGen template
2025-11-05 22:12:27 +00:00

76 lines
2.4 KiB
Plaintext

<#@ template language="C#" inherits="CodeTemplate" visibility="internal" linePragmas="false" #>
<#@ import namespace="Microsoft.Agents.AI.Workflows.Declarative.Extensions" #>
<#@ assembly name="System.Core" #>
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// </auto-generated>
// ------------------------------------------------------------------------------
#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 #>;
<#
}
#>
/// <summary>
/// This class provides a factory method to create a <see cref="Workflow" /> instance.
/// </summary>
/// <remarks>
/// 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
/// </remarks>
public static class <#= this.Prefix ?? string.Empty #>WorkflowProvider
{<#
foreach (string executor in ByLine(this.Executors, formatGroup: true))
{ #>
<#= executor #><#
}
#>
public static Workflow CreateWorkflow<TInput>(
DeclarativeWorkflowOptions options,
Func<TInput, ChatMessage>? inputTransform = null)
where TInput : notnull
{
// Create root executor to initialize the workflow.
inputTransform ??= (message) => DeclarativeWorkflowBuilder.DefaultTransform(message);
<#= this.RootExecutorType #>Executor<TInput> <#= 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);
}
}