.NET Workflows - Add "CustomerSupport" sample (#2102)

This commit is contained in:
Chris
2025-11-13 11:27:02 -08:00
committed by GitHub
Unverified
parent 5303c700ef
commit 1d6f53b3df
24 changed files with 935 additions and 39 deletions
+1
View File
@@ -141,6 +141,7 @@
<Folder Name="/Samples/GettingStarted/Workflows/Declarative/">
<File Path="samples/GettingStarted/Workflows/Declarative/README.md" />
<Project Path="samples/GettingStarted/Workflows/Declarative/ConfirmInput/ConfirmInput.csproj" />
<Project Path="samples/GettingStarted/Workflows/Declarative/CustomerSupport/CustomerSupport.csproj" />
<Project Path="samples/GettingStarted/Workflows/Declarative/DeepResearch/DeepResearch.csproj" />
<Project Path="samples/GettingStarted/Workflows/Declarative/ExecuteCode/ExecuteCode.csproj" />
<Project Path="samples/GettingStarted/Workflows/Declarative/ExecuteWorkflow/ExecuteWorkflow.csproj" />
@@ -32,7 +32,7 @@
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\workflow-samples\ConfirmInput.yaml">
<None Include="ConfirmInput.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
@@ -59,6 +59,3 @@ trigger:
Confirmed input:
{Local.ConfirmedInput}
@@ -11,7 +11,7 @@ namespace Demo.Workflows.Declarative.ConfirmInput;
/// </summary>
/// <remarks>
/// See the README.md file in the parent folder (../README.md) for detailed
/// information the configuration required to run this sample.
/// information about the configuration required to run this sample.
/// </remarks>
internal sealed class Program
{
@@ -0,0 +1,40 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ProjectsDebugTargetFrameworks>net9.0</ProjectsDebugTargetFrameworks>
<TargetFrameworks Condition="'$(Configuration)' == 'Debug'">$(ProjectsDebugTargetFrameworks)</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup>
<InjectIsExternalInitOnLegacy>true</InjectIsExternalInitOnLegacy>
<InjectSharedFoundryAgents>true</InjectSharedFoundryAgents>
<InjectSharedWorkflowsExecution>true</InjectSharedWorkflowsExecution>
<InjectSharedWorkflowsSettings>true</InjectSharedWorkflowsSettings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="Microsoft.Extensions.Logging" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\src\Microsoft.Agents.AI.Workflows.Declarative\Microsoft.Agents.AI.Workflows.Declarative.csproj" />
<ProjectReference Include="..\..\..\..\..\src\Microsoft.Agents.AI.Workflows.Declarative.AzureAI\Microsoft.Agents.AI.Workflows.Declarative.AzureAI.csproj" />
</ItemGroup>
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)..\..\..\..\..\..\workflow-samples\CustomerSupport.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
@@ -0,0 +1,440 @@
// Copyright (c) Microsoft. All rights reserved.
using Azure.AI.Agents;
using Azure.Identity;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.Configuration;
using OpenAI.Responses;
using Shared.Foundry;
using Shared.Workflows;
namespace Demo.Workflows.Declarative.CustomerSupport;
/// <summary>
/// This workflow demonstrates using multiple agents to provide automated
/// troubleshooting steps to resolve common issues with escalation options.
/// </summary>
/// <remarks>
/// See the README.md file in the parent folder (../README.md) for detailed
/// information about the configuration required to run this sample.
/// </remarks>
internal sealed class Program
{
public static async Task Main(string[] args)
{
// Initialize configuration
IConfiguration configuration = Application.InitializeConfig();
Uri foundryEndpoint = new(configuration.GetValue(Application.Settings.FoundryEndpoint));
// Create the ticketing plugin (mock functionality)
TicketingPlugin plugin = new();
// Ensure sample agents exist in Foundry.
await CreateAgentsAsync(foundryEndpoint, configuration, plugin);
// Get input from command line or console
string workflowInput = Application.GetInput(args);
// Create the workflow factory. This class demonstrates how to initialize a
// declarative workflow from a YAML file. Once the workflow is created, it
// can be executed just like any regular workflow.
WorkflowFactory workflowFactory =
new("CustomerSupport.yaml", foundryEndpoint)
{
Functions =
[
AIFunctionFactory.Create(plugin.CreateTicket),
AIFunctionFactory.Create(plugin.GetTicket),
AIFunctionFactory.Create(plugin.ResolveTicket),
AIFunctionFactory.Create(plugin.SendNotification),
]
};
// Execute the workflow: The WorkflowRunner demonstrates how to execute
// a workflow, handle the workflow events, and providing external input.
// This also includes the ability to checkpoint workflow state and how to
// resume execution.
WorkflowRunner runner = new();
await runner.ExecuteAsync(workflowFactory.CreateWorkflow, workflowInput);
}
private static async Task CreateAgentsAsync(Uri foundryEndpoint, IConfiguration configuration, TicketingPlugin plugin)
{
AgentClient agentClient = new(foundryEndpoint, new AzureCliCredential());
await agentClient.CreateAgentAsync(
agentName: "SelfServiceAgent",
agentDefinition: DefineSelfServiceAgent(configuration),
agentDescription: "Service agent for CustomerSupport workflow");
await agentClient.CreateAgentAsync(
agentName: "TicketingAgent",
agentDefinition: DefineTicketingAgent(configuration, plugin),
agentDescription: "Ticketing agent for CustomerSupport workflow");
await agentClient.CreateAgentAsync(
agentName: "TicketRoutingAgent",
agentDefinition: DefineTicketRoutingAgent(configuration, plugin),
agentDescription: "Routing agent for CustomerSupport workflow");
await agentClient.CreateAgentAsync(
agentName: "WindowsSupportAgent",
agentDefinition: DefineWindowsSupportAgent(configuration, plugin),
agentDescription: "Windows support agent for CustomerSupport workflow");
await agentClient.CreateAgentAsync(
agentName: "TicketResolutionAgent",
agentDefinition: DefineResolutionAgent(configuration, plugin),
agentDescription: "Resolution agent for CustomerSupport workflow");
await agentClient.CreateAgentAsync(
agentName: "TicketEscalationAgent",
agentDefinition: TicketEscalationAgent(configuration, plugin),
agentDescription: "Escalate agent for human support");
}
private static PromptAgentDefinition DefineSelfServiceAgent(IConfiguration configuration) =>
new(configuration.GetValue(Application.Settings.FoundryModelMini))
{
Instructions =
"""
Use your knowledge to work with the user to provide the best possible troubleshooting steps.
- If the user confirms that the issue is resolved, then the issue is resolved.
- If the user reports that the issue persists, then escalate.
""",
TextOptions =
new ResponseTextOptions
{
TextFormat =
ResponseTextFormat.CreateJsonSchemaFormat(
"TaskEvaluation",
BinaryData.FromString(
"""
{
"type": "object",
"properties": {
"IsResolved": {
"type": "boolean",
"description": "True if the user issue/ask has been resolved."
},
"NeedsTicket": {
"type": "boolean",
"description": "True if the user issue/ask requires that a ticket be filed."
},
"IssueDescription": {
"type": "string",
"description": "A concise description of the issue."
},
"AttemptedResolutionSteps": {
"type": "string",
"description": "An outline of the steps taken to attempt resolution."
}
},
"required": ["IsResolved", "NeedsTicket", "IssueDescription", "AttemptedResolutionSteps"],
"additionalProperties": false
}
"""),
jsonSchemaFormatDescription: null,
jsonSchemaIsStrict: true),
}
};
private static PromptAgentDefinition DefineTicketingAgent(IConfiguration configuration, TicketingPlugin plugin) =>
new(configuration.GetValue(Application.Settings.FoundryModelMini))
{
Instructions =
"""
Always create a ticket in Azure DevOps using the available tools.
Include the following information in the TicketSummary.
- Issue description: {{IssueDescription}}
- Attempted resolution steps: {{AttemptedResolutionSteps}}
After creating the ticket, provide the user with the ticket ID.
""",
Tools =
{
AIFunctionFactory.Create(plugin.CreateTicket).AsOpenAIResponseTool()
},
StructuredInputs =
{
["IssueDescription"] =
new StructuredInputDefinition
{
IsRequired = false,
DefaultValue = BinaryData.FromString(@"""unknown"""),
Description = "A concise description of the issue.",
},
["AttemptedResolutionSteps"] =
new StructuredInputDefinition
{
IsRequired = false,
DefaultValue = BinaryData.FromString(@"""unknown"""),
Description = "An outline of the steps taken to attempt resolution.",
}
},
TextOptions =
new ResponseTextOptions
{
TextFormat =
ResponseTextFormat.CreateJsonSchemaFormat(
"TaskEvaluation",
BinaryData.FromString(
"""
{
"type": "object",
"properties": {
"TicketId": {
"type": "string",
"description": "The identifier of the ticket created in response to the user issue."
},
"TicketSummary": {
"type": "string",
"description": "The summary of the ticket created in response to the user issue."
}
},
"required": ["TicketId", "TicketSummary"],
"additionalProperties": false
}
"""),
jsonSchemaFormatDescription: null,
jsonSchemaIsStrict: true),
}
};
private static PromptAgentDefinition DefineTicketRoutingAgent(IConfiguration configuration, TicketingPlugin plugin) =>
new(configuration.GetValue(Application.Settings.FoundryModelMini))
{
Instructions =
"""
Determine how to route the given issue to the appropriate support team.
Choose from the available teams and their functions:
- Windows Activation Support: Windows license activation issues
- Windows Support: Windows related issues
- Azure Support: Azure related issues
- Network Support: Network related issues
- Hardware Support: Hardware related issues
- Microsoft Office Support: Microsoft Office related issues
- General Support: General issues not related to the above categories
""",
Tools =
{
AIFunctionFactory.Create(plugin.GetTicket).AsOpenAIResponseTool(),
},
TextOptions =
new ResponseTextOptions
{
TextFormat =
ResponseTextFormat.CreateJsonSchemaFormat(
"TaskEvaluation",
BinaryData.FromString(
"""
{
"type": "object",
"properties": {
"TeamName": {
"type": "string",
"description": "The name of the team to route the issue"
}
},
"required": ["TeamName"],
"additionalProperties": false
}
"""),
jsonSchemaFormatDescription: null,
jsonSchemaIsStrict: true),
}
};
private static PromptAgentDefinition DefineWindowsSupportAgent(IConfiguration configuration, TicketingPlugin plugin) =>
new(configuration.GetValue(Application.Settings.FoundryModelMini))
{
Instructions =
"""
Use your knowledge to work with the user to provide the best possible troubleshooting steps
for issues related to Windows operating system.
- Utilize the "Attempted Resolutions Steps" as a starting point for your troubleshooting.
- Never escalate without troubleshooting with the user.
- If the user confirms that the issue is resolved, then the issue is resolved.
- If the user reports that the issue persists, then escalate.
Issue: {{IssueDescription}}
Attempted Resolution Steps: {{AttemptedResolutionSteps}}
""",
StructuredInputs =
{
["IssueDescription"] =
new StructuredInputDefinition
{
IsRequired = false,
DefaultValue = BinaryData.FromString(@"""unknown"""),
Description = "A concise description of the issue.",
},
["AttemptedResolutionSteps"] =
new StructuredInputDefinition
{
IsRequired = false,
DefaultValue = BinaryData.FromString(@"""unknown"""),
Description = "An outline of the steps taken to attempt resolution.",
}
},
Tools =
{
AIFunctionFactory.Create(plugin.GetTicket).AsOpenAIResponseTool(),
},
TextOptions =
new ResponseTextOptions
{
TextFormat =
ResponseTextFormat.CreateJsonSchemaFormat(
"TaskEvaluation",
BinaryData.FromString(
"""
{
"type": "object",
"properties": {
"IsResolved": {
"type": "boolean",
"description": "True if the user issue/ask has been resolved."
},
"NeedsEscalation": {
"type": "boolean",
"description": "True resolution could not be achieved and the issue/ask requires escalation."
},
"ResolutionSummary": {
"type": "string",
"description": "The summary of the steps that led to resolution."
}
},
"required": ["IsResolved", "NeedsEscalation", "ResolutionSummary"],
"additionalProperties": false
}
"""),
jsonSchemaFormatDescription: null,
jsonSchemaIsStrict: true),
}
};
private static PromptAgentDefinition DefineResolutionAgent(IConfiguration configuration, TicketingPlugin plugin) =>
new(configuration.GetValue(Application.Settings.FoundryModelMini))
{
Instructions =
"""
Resolve the following ticket in Azure DevOps.
Always include the resolution details.
- Ticket ID: #{{TicketId}}
- Resolution Summary: {{ResolutionSummary}}
""",
Tools =
{
AIFunctionFactory.Create(plugin.ResolveTicket).AsOpenAIResponseTool(),
},
StructuredInputs =
{
["TicketId"] =
new StructuredInputDefinition
{
IsRequired = false,
DefaultValue = BinaryData.FromString(@"""unknown"""),
Description = "The identifier of the ticket being resolved.",
},
["ResolutionSummary"] =
new StructuredInputDefinition
{
IsRequired = false,
DefaultValue = BinaryData.FromString(@"""unknown"""),
Description = "The steps taken to resolve the issue.",
}
}
};
private static PromptAgentDefinition TicketEscalationAgent(IConfiguration configuration, TicketingPlugin plugin) =>
new(configuration.GetValue(Application.Settings.FoundryModelMini))
{
Instructions =
"""
You escalate the provided issue to human support team by sending an email if the issue is not resolved.
Here are some additional details that might help:
- TicketId : {{TicketId}}
- IssueDescription : {{IssueDescription}}
- AttemptedResolutionSteps : {{AttemptedResolutionSteps}}
Before escalating, gather the user's email address for follow-up.
If not known, ask the user for their email address so that the support team can reach them when needed.
When sending the email, include the following details:
- To: support@contoso.com
- Cc: user's email address
- Subject of the email: "Support Ticket - {TicketId} - [Compact Issue Description]"
- Body:
- Issue description
- Attempted resolution steps
- User's email address
- Any other relevant information from the conversation history
Assure the user that their issue will be resolved and provide them with a ticket ID for reference.
""",
Tools =
{
AIFunctionFactory.Create(plugin.GetTicket).AsOpenAIResponseTool(),
AIFunctionFactory.Create(plugin.SendNotification).AsOpenAIResponseTool(),
},
StructuredInputs =
{
["TicketId"] =
new StructuredInputDefinition
{
IsRequired = false,
DefaultValue = BinaryData.FromString(@"""unknown"""),
Description = "The identifier of the ticket being escalated.",
},
["IssueDescription"] =
new StructuredInputDefinition
{
IsRequired = false,
DefaultValue = BinaryData.FromString(@"""unknown"""),
Description = "A concise description of the issue.",
},
["ResolutionSummary"] =
new StructuredInputDefinition
{
IsRequired = false,
DefaultValue = BinaryData.FromString(@"""unknown"""),
Description = "An outline of the steps taken to attempt resolution.",
}
},
TextOptions =
new ResponseTextOptions
{
TextFormat =
ResponseTextFormat.CreateJsonSchemaFormat(
"TaskEvaluation",
BinaryData.FromString(
"""
{
"type": "object",
"properties": {
"IsComplete": {
"type": "boolean",
"description": "Has the email been sent and no more user input is required."
},
"UserMessage": {
"type": "string",
"description": "A natural language message to the user."
}
},
"required": ["IsComplete", "UserMessage"],
"additionalProperties": false
}
"""),
jsonSchemaFormatDescription: null,
jsonSchemaIsStrict: true),
}
};
}
@@ -0,0 +1,85 @@
// Copyright (c) Microsoft. All rights reserved.
using System.ComponentModel;
namespace Demo.Workflows.Declarative.CustomerSupport;
internal sealed class TicketingPlugin
{
private readonly Dictionary<string, TicketItem> _ticketStore = [];
[Description("Retrieve a ticket by identifier from Azure DevOps.")]
public TicketItem? GetTicket(string id)
{
Trace(nameof(GetTicket));
this._ticketStore.TryGetValue(id, out TicketItem? ticket);
return ticket;
}
[Description("Create a ticket in Azure DevOps and return its identifier.")]
public string CreateTicket(string subject, string description, string notes)
{
Trace(nameof(CreateTicket));
TicketItem ticket = new()
{
Subject = subject,
Description = description,
Notes = notes,
Id = Guid.NewGuid().ToString("N"),
};
this._ticketStore[ticket.Id] = ticket;
return ticket.Id;
}
[Description("Resolve an existing ticket in Azure DevOps given its identifier.")]
public void ResolveTicket(string id, string resolutionSummary)
{
Trace(nameof(ResolveTicket));
if (this._ticketStore.TryGetValue(id, out TicketItem? ticket))
{
ticket.Status = TicketStatus.Resolved;
}
}
[Description("Send an email notification to escalate ticket engagement.")]
public void SendNotification(string id, string email, string cc, string body)
{
Trace(nameof(SendNotification));
}
private static void Trace(string functionName)
{
Console.ForegroundColor = ConsoleColor.DarkMagenta;
try
{
Console.WriteLine($"\nFUNCTION: {functionName}");
}
finally
{
Console.ResetColor();
}
}
public enum TicketStatus
{
Open,
InProgress,
Resolved,
Closed,
}
public sealed class TicketItem
{
public TicketStatus Status { get; set; } = TicketStatus.Open;
public string Subject { get; init; } = string.Empty;
public string Id { get; init; } = string.Empty;
public string Description { get; init; } = string.Empty;
public string Notes { get; init; } = string.Empty;
}
}
@@ -15,7 +15,7 @@ namespace Demo.Workflows.Declarative.DeepResearch;
/// </summary>
/// <remarks>
/// See the README.md file in the parent folder (../README.md) for detailed
/// information the configuration required to run this sample.
/// information about the configuration required to run this sample.
/// </remarks>
internal sealed class Program
{
@@ -16,7 +16,7 @@ namespace Demo.Workflows.Declarative.FunctionTools;
/// </summary>
/// <remarks>
/// See the README.md file in the parent folder (../README.md) for detailed
/// information the configuration required to run this sample.
/// information about the configuration required to run this sample.
/// </remarks>
internal sealed class Program
{
@@ -15,7 +15,7 @@ namespace Demo.Workflows.Declarative.InputArguments;
/// </summary>
/// <remarks>
/// See the README.md file in the parent folder (../README.md) for detailed
/// information the configuration required to run this sample.
/// information about the configuration required to run this sample.
/// </remarks>
internal sealed class Program
{
@@ -14,7 +14,7 @@ namespace Demo.Workflows.Declarative.Marketing;
/// </summary>
/// <remarks>
/// See the README.md file in the parent folder (../README.md) for detailed
/// information the configuration required to run this sample.
/// information about the configuration required to run this sample.
/// </remarks>
internal sealed class Program
{
@@ -14,7 +14,7 @@ namespace Demo.Workflows.Declarative.StudentTeacher;
/// </summary>
/// <remarks>
/// See the README.md file in the parent folder (../README.md) for detailed
/// information the configuration required to run this sample.
/// information about the configuration required to run this sample.
/// </remarks>
internal sealed class Program
{
@@ -15,7 +15,7 @@ namespace Demo.Workflows.Declarative.ToolApproval;
/// </summary>
/// <remarks>
/// See the README.md file in the parent folder (../README.md) for detailed
/// information the configuration required to run this sample.
/// information about the configuration required to run this sample.
/// </remarks>
internal sealed class Program
{
@@ -13,6 +13,7 @@ using System.Threading.Tasks;
using Azure.AI.Agents;
using Azure.Core;
using Microsoft.Extensions.AI;
using OpenAI;
using OpenAI.Responses;
namespace Microsoft.Agents.AI.Workflows.Declarative;
@@ -24,8 +25,7 @@ namespace Microsoft.Agents.AI.Workflows.Declarative;
/// project endpoint and credentials to authenticate requests.</remarks>
/// <param name="projectEndpoint">A <see cref="Uri"/> instance representing the endpoint URL of the Foundry project. This must be a valid, non-null URI pointing to the project.</param>
/// <param name="projectCredentials">The credentials used to authenticate with the Foundry project. This must be a valid instance of <see cref="TokenCredential"/>.</param>
/// <param name="httpClient">An optional <see cref="HttpClient"/> instance to be used for making HTTP requests. If not provided, a default client will be used.</param>
public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential projectCredentials, HttpClient? httpClient = null) : WorkflowAgentProvider
public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential projectCredentials) : WorkflowAgentProvider
{
private readonly Dictionary<string, AgentVersion> _versionCache = [];
private readonly Dictionary<string, AIAgent> _agentCache = [];
@@ -36,7 +36,18 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj
/// <summary>
/// Optional options used when creating the <see cref="AgentClient"/>.
/// </summary>
public AgentClientOptions? ClientOptions { get; init; }
public AgentClientOptions? AgentClientOptions { get; init; }
/// <summary>
/// Optional options used when invoking the <see cref="AIAgent"/>.
/// </summary>
public OpenAIClientOptions? OpenAIClientOptions { get; init; }
/// <summary>
/// An optional <see cref="HttpClient"/> instance to be used for making HTTP requests.
/// If not provided, a default client will be used.
/// </summary>
public HttpClient? HttpClient { get; init; }
/// <inheritdoc/>
public override async Task<string> CreateConversationAsync(CancellationToken cancellationToken = default)
@@ -161,7 +172,7 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj
AgentClient client = this.GetAgentClient();
agent = client.GetAIAgent(agentVersion, tools: null, clientFactory: null, openAIClientOptions: null, services: null);
agent = client.GetAIAgent(agentVersion, tools: null, clientFactory: null, this.OpenAIClientOptions, services: null);
FunctionInvokingChatClient? functionInvokingClient = agent.GetService<FunctionInvokingChatClient>();
if (functionInvokingClient is not null)
@@ -221,11 +232,11 @@ public sealed class AzureAgentProvider(Uri projectEndpoint, TokenCredential proj
{
if (this._agentClient is null)
{
AgentClientOptions clientOptions = this.ClientOptions ?? new();
AgentClientOptions clientOptions = this.AgentClientOptions ?? new();
if (httpClient is not null)
if (this.HttpClient is not null)
{
clientOptions.Transport = new HttpClientPipelineTransport(httpClient);
clientOptions.Transport = new HttpClientPipelineTransport(this.HttpClient);
}
AgentClient newClient = new(projectEndpoint, projectCredentials, clientOptions);
@@ -137,18 +137,23 @@ internal sealed class WorkflowActionVisitor : DialogActionVisitor
conditionItem.Accept(this);
}
if (lastConditionItemId is not null)
{
// Create clean start for else action from prior conditions
this.RestartAfter(lastConditionItemId, action.Id);
}
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, action.IsElse);
}
else
{
string stepId = Steps.Post(action.Id);
this._workflowModel.AddLink(action.Id, stepId, action.IsElse);
}
}
protected override void Visit(GotoAction item)
@@ -35,7 +35,7 @@ public sealed class DeclarativeWorkflowTest(ITestOutputHelper output) : Workflow
this.RunWorkflowAsync(GetWorkflowPath(workflowFileName, isSample: true), testcaseFileName, externalConveration);
[Theory]
[InlineData("ConfirmInput.yaml", "ConfirmInput.json", true)]
[InlineData("ConfirmInput.yaml", "ConfirmInput.json", false)]
[InlineData("RequestExternalInput.yaml", "RequestExternalInput.json", false)]
public Task ValidateMultiTurnAsync(string workflowFileName, string testcaseFileName, bool isSample) =>
this.RunWorkflowAsync(GetWorkflowPath(workflowFileName, isSample), testcaseFileName, useJsonCheckpoint: true);
@@ -0,0 +1,61 @@
#
# This workflow demonstrates how to use the Question action
# to request user input and confirm it matches the original input.
#
# Note: This workflow doesn't make use of any agents.
#
kind: Workflow
trigger:
kind: OnConversationStart
id: workflow_demo
actions:
# Capture original input
- kind: SetVariable
id: set_project
variable: Local.OriginalInput
value: =System.LastMessage.Text
# Request input from user
- kind: Question
id: question_confirm
alwaysPrompt: false
autoSend: false
property: Local.ConfirmedInput
prompt:
kind: Message
text:
- "CONFIRM:"
entity:
kind: StringPrebuiltEntity
# Confirm input
- kind: ConditionGroup
id: check_completion
conditions:
# Didn't match
- condition: =Local.OriginalInput <> Local.ConfirmedInput
id: check_confirm
actions:
- kind: SendActivity
id: sendActivity_mismatch
activity: |-
"{Local.ConfirmedInput}" does not match the original input of "{Local.OriginalInput}". Please try again.
- kind: GotoAction
id: goto_again
actionId: question_confirm
# Confirmed
elseActions:
- kind: SendActivity
id: sendActivity_confirmed
activity: |-
You entered:
{Local.OriginalInput}
Confirmed input:
{Local.ConfirmedInput}
@@ -117,7 +117,7 @@ public sealed class DeclarativeWorkflowTest(ITestOutputHelper output) : Workflow
this.AssertNotExecuted("sendActivity_even");
this.AssertMessage("ODD");
}
this.AssertExecuted("end_all");
this.AssertExecuted("activity_final");
}
[Theory]
@@ -141,7 +141,30 @@ public sealed class DeclarativeWorkflowTest(ITestOutputHelper output) : Workflow
this.AssertExecuted("sendActivity_odd");
this.AssertNotExecuted("sendActivity_else");
}
this.AssertExecuted("end_all");
this.AssertExecuted("activity_final");
}
[Theory]
[InlineData(12, 4)]
[InlineData(37, 9)]
public async Task ConditionActionWithFallThroughAsync(int input, int expectedActions)
{
await this.RunWorkflowAsync("ConditionFallThrough.yaml", input);
this.AssertExecutionCount(expectedActions);
this.AssertExecuted("setVariable_test");
this.AssertExecuted("conditionGroup_test", isScope: true);
if (input % 2 == 0)
{
this.AssertNotExecuted("conditionItem_odd");
this.AssertNotExecuted("sendActivity_odd");
}
else
{
this.AssertExecuted("conditionItem_odd", isScope: true);
this.AssertExecuted("sendActivity_odd");
this.AssertMessage("ODD");
}
this.AssertExecuted("activity_final");
}
[Theory]
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// </auto-generated>
@@ -129,6 +129,27 @@ public static class WorkflowProvider
}
}
/// <summary>
/// Formats a message template and sends an activity event.
/// </summary>
internal sealed class ActivityFinalExecutor(FormulaSession session) : ActionExecutor(id: "activity_final", session)
{
// <inheritdoc />
protected override async ValueTask<object?> ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)
{
string activityText =
await context.FormatTemplateAsync(
"""
All done!
"""
);
AgentRunResponse response = new([new ChatMessage(ChatRole.Assistant, activityText)]);
await context.AddEventAsync(new AgentRunResponseEvent(this.Id, response)).ConfigureAwait(false);
return default;
}
}
public static Workflow CreateWorkflow<TInput>(
DeclarativeWorkflowOptions options,
Func<TInput, ChatMessage>? inputTransform = null)
@@ -147,7 +168,7 @@ public static class WorkflowProvider
DelegateExecutor conditionItemEvenactions = new(id: "conditionItem_evenActions", myWorkflowRoot.Session);
SendactivityEvenExecutor sendActivityEven = new(myWorkflowRoot.Session);
DelegateExecutor conditionGroupTestPost = new(id: "conditionGroup_test_Post", myWorkflowRoot.Session);
DelegateExecutor endAll = new(id: "end_all", myWorkflowRoot.Session);
ActivityFinalExecutor activityFinal = new(myWorkflowRoot.Session);
DelegateExecutor conditionItemOddPost = new(id: "conditionItem_odd_Post", myWorkflowRoot.Session);
DelegateExecutor conditionItemEvenPost = new(id: "conditionItem_even_Post", myWorkflowRoot.Session);
DelegateExecutor conditionItemOddactionsPost = new(id: "conditionItem_oddActions_Post", myWorkflowRoot.Session);
@@ -166,7 +187,7 @@ public static class WorkflowProvider
builder.AddEdge(conditionItemOddactions, sendActivityOdd);
builder.AddEdge(conditionItemEven, conditionItemEvenactions);
builder.AddEdge(conditionItemEvenactions, sendActivityEven);
builder.AddEdge(conditionGroupTestPost, endAll);
builder.AddEdge(conditionGroupTestPost, activityFinal);
builder.AddEdge(conditionItemOddPost, conditionGroupTestPost);
builder.AddEdge(conditionItemEvenPost, conditionGroupTestPost);
builder.AddEdge(sendActivityOdd, conditionItemOddactionsPost);
@@ -177,4 +198,4 @@ public static class WorkflowProvider
// Build the workflow
return builder.Build(validateOrphans: false);
}
}
}
@@ -27,5 +27,6 @@ trigger:
id: sendActivity_even
activity: EVEN
- kind: EndConversation
id: end_all
- kind: SendActivity
id: activity_final
activity: All done!
@@ -1,4 +1,4 @@
// ------------------------------------------------------------------------------
// ------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// </auto-generated>
@@ -123,6 +123,27 @@ public static class WorkflowProvider
}
}
/// <summary>
/// Formats a message template and sends an activity event.
/// </summary>
internal sealed class ActivityFinalExecutor(FormulaSession session) : ActionExecutor(id: "activity_final", session)
{
// <inheritdoc />
protected override async ValueTask<object?> ExecuteAsync(IWorkflowContext context, CancellationToken cancellationToken)
{
string activityText =
await context.FormatTemplateAsync(
"""
All done!
"""
);
AgentRunResponse response = new([new ChatMessage(ChatRole.Assistant, activityText)]);
await context.AddEventAsync(new AgentRunResponseEvent(this.Id, response)).ConfigureAwait(false);
return default;
}
}
public static Workflow CreateWorkflow<TInput>(
DeclarativeWorkflowOptions options,
Func<TInput, ChatMessage>? inputTransform = null)
@@ -141,7 +162,7 @@ public static class WorkflowProvider
DelegateExecutor conditionItemOddRestart = new(id: "conditionItem_odd_Restart", myWorkflowRoot.Session);
SendactivityElseExecutor sendActivityElse = new(myWorkflowRoot.Session);
DelegateExecutor conditionGroupTestPost = new(id: "conditionGroup_test_Post", myWorkflowRoot.Session);
DelegateExecutor endAll = new(id: "end_all", myWorkflowRoot.Session);
ActivityFinalExecutor activityFinal = new(myWorkflowRoot.Session);
DelegateExecutor conditionItemOddPost = new(id: "conditionItem_odd_Post", myWorkflowRoot.Session);
DelegateExecutor conditionItemOddactionsPost = new(id: "conditionItem_oddActions_Post", myWorkflowRoot.Session);
DelegateExecutor conditionGroupTestelseactionsPost = new(id: "conditionGroup_testElseActions_Post", myWorkflowRoot.Session);
@@ -159,7 +180,7 @@ public static class WorkflowProvider
builder.AddEdge(conditionItemOddactions, sendActivityOdd);
builder.AddEdge(conditionItemOddRestart, conditionGroupTestelseactions);
builder.AddEdge(conditionGroupTestelseactions, sendActivityElse);
builder.AddEdge(conditionGroupTestPost, endAll);
builder.AddEdge(conditionGroupTestPost, activityFinal);
builder.AddEdge(conditionItemOddPost, conditionGroupTestPost);
builder.AddEdge(sendActivityOdd, conditionItemOddactionsPost);
builder.AddEdge(conditionItemOddactionsPost, conditionItemOddPost);
@@ -169,4 +190,4 @@ public static class WorkflowProvider
// Build the workflow
return builder.Build(validateOrphans: false);
}
}
}
@@ -24,5 +24,6 @@ trigger:
id: sendActivity_else
activity: EVEN
- kind: EndConversation
id: end_all
- kind: SendActivity
id: activity_final
activity: All done!
@@ -0,0 +1,25 @@
kind: Workflow
trigger:
kind: OnConversationStart
id: my_workflow
actions:
- kind: SetVariable
id: setVariable_test
variable: Local.TestValue
value: =Value(System.LastMessageText)
- kind: ConditionGroup
id: conditionGroup_test
conditions:
- id: conditionItem_odd
condition: =Mod(Local.TestValue, 2) = 1
actions:
- kind: SendActivity
id: sendActivity_odd
activity: ODD
- kind: SendActivity
id: activity_final
activity: All done!
+164
View File
@@ -0,0 +1,164 @@
#
# This workflow demonstrates using multiple agents to provide automated
# troubleshooting steps to resolve common issues with escalation options.
#
# Example input:
# My PC keeps rebooting and I can't use it.
#
kind: Workflow
trigger:
kind: OnConversationStart
id: workflow_demo
actions:
# Interact with user until the issue has been resolved or
# a determination is made that a ticket is required.
- kind: InvokeAzureAgent
id: service_agent
conversationId: =System.ConversationId
agent:
name: SelfServiceAgent
input:
externalLoop:
when: |-
=Not(Local.ServiceParameters.IsResolved)
And
Not(Local.ServiceParameters.NeedsTicket)
output:
responseObject: Local.ServiceParameters
# All done if issue is resolved.
- kind: ConditionGroup
id: check_if_resolved
conditions:
- condition: =Local.ServiceParameters.IsResolved
id: test_if_resolved
actions:
- kind: GotoAction
id: end_when_resolved
actionId: all_done
# Create the ticket.
- kind: InvokeAzureAgent
id: ticket_agent
agent:
name: TicketingAgent
input:
arguments:
IssueDescription: =Local.ServiceParameters.IssueDescription
AttemptedResolutionSteps: =Local.ServiceParameters.AttemptedResolutionSteps
output:
responseObject: Local.TicketParameters
# Capture the attempted resolution steps.
- kind: SetVariable
id: capture_attempted_resolution
variable: Local.ResolutionSteps
value: =Local.ServiceParameters.AttemptedResolutionSteps
# Notify user of ticket identifier.
- kind: SendActivity
id: log_ticket
activity: "Created ticket #{Local.TicketParameters.TicketId}"
# Determine which team for which route the ticket.
- kind: InvokeAzureAgent
id: routing_agent
agent:
name: TicketRoutingAgent
input:
messages: =UserMessage(Local.ServiceParameters.IssueDescription)
output:
responseObject: Local.RoutingParameters
# Notify user of routing decision.
- kind: SendActivity
id: log_route
activity: Routing to {Local.RoutingParameters.TeamName}
- kind: ConditionGroup
id: check_routing
conditions:
- condition: =Local.RoutingParameters.TeamName = "Windows Support"
id: route_to_support
actions:
# Invoke the support agent to attempt to resolve the issue.
- kind: CreateConversation
id: conversation_support
conversationId: Local.SupportConversationId
- kind: InvokeAzureAgent
id: support_agent
conversationId: =Local.SupportConversationId
agent:
name: WindowsSupportAgent
input:
arguments:
IssueDescription: =Local.ServiceParameters.IssueDescription
AttemptedResolutionSteps: =Local.ServiceParameters.AttemptedResolutionSteps
externalLoop:
when: |-
=Not(Local.SupportParameters.IsResolved)
And
Not(Local.SupportParameters.NeedsEscalation)
output:
autoSend: true
responseObject: Local.SupportParameters
# Capture the attempted resolution steps.
- kind: SetVariable
id: capture_support_resolution
variable: Local.ResolutionSteps
value: =Local.SupportParameters.ResolutionSummary
# Check if the issue was resolved by support.
- kind: ConditionGroup
id: check_resolved
conditions:
# Resolve ticket
- condition: =Local.SupportParameters.IsResolved
id: handle_if_resolved
actions:
- kind: InvokeAzureAgent
id: resolution_agent
agent:
name: TicketResolutionAgent
input:
arguments:
TicketId: =Local.TicketParameters.TicketId
ResolutionSummary: =Local.SupportParameters.ResolutionSummary
- kind: GotoAction
id: end_when_solved
actionId: all_done
# Escalate the ticket by sending an email notification.
- kind: CreateConversation
id: conversation_escalate
conversationId: Local.EscalationConversationId
- kind: InvokeAzureAgent
id: escalate_agent
conversationId: =Local.EscalationConversationId
agent:
name: TicketEscalationAgent
input:
arguments:
TicketId: =Local.TicketParameters.TicketId
IssueDescription: =Local.ServiceParameters.IssueDescription
ResolutionSummary: =Local.ResolutionSteps
externalLoop:
when: =Not(Local.EscalationParameters.IsComplete)
output:
autoSend: true
responseObject: Local.EscalationParameters
# All done
- kind: EndWorkflow
id: all_done