mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Minor cleanups
This commit is contained in:
@@ -50,8 +50,8 @@ IHost host = Host.CreateDefaultBuilder(args)
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
// Get the DurableExecutionEnvironment from DI - no need to manually resolve DurableTaskClient
|
||||
DurableExecutionEnvironment durableExecution = host.Services.GetRequiredService<DurableExecutionEnvironment>();
|
||||
// Get the IWorkflowClient from DI - no need to manually resolve DurableTaskClient
|
||||
IWorkflowClient workflowClient = host.Services.GetRequiredService<IWorkflowClient>();
|
||||
|
||||
Console.WriteLine("Durable Workflow Sample");
|
||||
Console.WriteLine("Workflow: OrderLookup (2s) -> OrderCancel (5s) -> SendEmail (1s)");
|
||||
@@ -75,7 +75,7 @@ while (true)
|
||||
|
||||
try
|
||||
{
|
||||
await StartNewWorkflowAsync(input, cancelOrder, durableExecution);
|
||||
await StartNewWorkflowAsync(input, cancelOrder, workflowClient);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -87,13 +87,13 @@ while (true)
|
||||
|
||||
await host.StopAsync();
|
||||
|
||||
// Start a new workflow using DurableExecutionEnvironment (no DurableTaskClient needed)
|
||||
async Task StartNewWorkflowAsync(string orderId, Workflow workflow, DurableExecutionEnvironment execution)
|
||||
// Start a new workflow using IWorkflowClient (no DurableTaskClient needed)
|
||||
async Task StartNewWorkflowAsync(string orderId, Workflow workflow, IWorkflowClient client)
|
||||
{
|
||||
Console.WriteLine($"Starting workflow for order '{orderId}'...");
|
||||
|
||||
// RunAsync returns IRun, cast to DurableRun for durable-specific features like WaitForCompletionAsync
|
||||
await using DurableRun run = (DurableRun)await execution.RunAsync(workflow, orderId);
|
||||
await using DurableRun run = (DurableRun)await client.RunAsync(workflow, orderId);
|
||||
Console.WriteLine($"Instance ID: {run.InstanceId}");
|
||||
|
||||
try
|
||||
|
||||
@@ -77,8 +77,8 @@ IHost host = Host.CreateDefaultBuilder(args)
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
// Get the DurableExecutionEnvironment from DI - no need to manually resolve DurableTaskClient
|
||||
DurableExecutionEnvironment durableExecution = host.Services.GetRequiredService<DurableExecutionEnvironment>();
|
||||
// Get the IWorkflowClient from DI - no need to manually resolve DurableTaskClient
|
||||
IWorkflowClient workflowClient = host.Services.GetRequiredService<IWorkflowClient>();
|
||||
|
||||
// Console UI
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
@@ -111,7 +111,7 @@ while (true)
|
||||
try
|
||||
{
|
||||
// Cast to DurableRun for durable-specific features like InstanceId and WaitForCompletionAsync
|
||||
await using DurableRun run = (DurableRun)await durableExecution.RunAsync(workflow, input);
|
||||
await using DurableRun run = (DurableRun)await workflowClient.RunAsync(workflow, input);
|
||||
Console.ForegroundColor = ConsoleColor.Gray;
|
||||
Console.WriteLine($"Instance: {run.InstanceId}");
|
||||
Console.ResetColor();
|
||||
|
||||
@@ -43,8 +43,8 @@ IHost host = Host.CreateDefaultBuilder(args)
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
// Get the DurableExecutionEnvironment from DI - no need to manually resolve DurableTaskClient
|
||||
DurableExecutionEnvironment durableExecution = host.Services.GetRequiredService<DurableExecutionEnvironment>();
|
||||
// Get the IWorkflowClient from DI - no need to manually resolve DurableTaskClient
|
||||
IWorkflowClient workflowClient = host.Services.GetRequiredService<IWorkflowClient>();
|
||||
|
||||
// Start the workflow with an expense ID as input
|
||||
string expenseId = "EXP-2025-001";
|
||||
@@ -52,7 +52,7 @@ Console.WriteLine($"Starting expense reimbursement workflow for expense: {expens
|
||||
|
||||
// Start the workflow and get a streaming handle
|
||||
// Cast to DurableStreamingRun for durable-specific features like InstanceId and SendResponseAsync
|
||||
await using DurableStreamingRun run = (DurableStreamingRun)await durableExecution.StreamAsync(expenseApproval, expenseId);
|
||||
await using DurableStreamingRun run = (DurableStreamingRun)await workflowClient.StreamAsync(expenseApproval, expenseId);
|
||||
|
||||
Console.WriteLine($"Workflow started with instance ID: {run.InstanceId}");
|
||||
Console.WriteLine("Watching for workflow events...\n");
|
||||
|
||||
@@ -54,8 +54,8 @@ IHost host = Host.CreateDefaultBuilder(args)
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
// Get the DurableExecutionEnvironment from DI - no need to manually resolve DurableTaskClient
|
||||
DurableExecutionEnvironment durableExecution = host.Services.GetRequiredService<DurableExecutionEnvironment>();
|
||||
// Get the IWorkflowClient from DI - no need to manually resolve DurableTaskClient
|
||||
IWorkflowClient workflowClient = host.Services.GetRequiredService<IWorkflowClient>();
|
||||
|
||||
Console.WriteLine("Workflow Events Demo - Enter order ID (or 'exit'):");
|
||||
|
||||
@@ -70,7 +70,7 @@ while (true)
|
||||
|
||||
try
|
||||
{
|
||||
await RunWorkflowWithStreamingAsync(input, cancelOrder, durableExecution);
|
||||
await RunWorkflowWithStreamingAsync(input, cancelOrder, workflowClient);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -83,11 +83,11 @@ while (true)
|
||||
await host.StopAsync();
|
||||
|
||||
// Runs a workflow and streams events as they occur
|
||||
async Task RunWorkflowWithStreamingAsync(string orderId, Workflow workflow, DurableExecutionEnvironment execution)
|
||||
async Task RunWorkflowWithStreamingAsync(string orderId, Workflow workflow, IWorkflowClient client)
|
||||
{
|
||||
// StreamAsync starts the workflow and returns a handle for observing events
|
||||
// Cast to DurableStreamingRun for durable-specific features like InstanceId
|
||||
await using DurableStreamingRun run = (DurableStreamingRun)await execution.StreamAsync(workflow, orderId);
|
||||
await using DurableStreamingRun run = (DurableStreamingRun)await client.StreamAsync(workflow, orderId);
|
||||
Console.WriteLine($"Started: {run.InstanceId}");
|
||||
|
||||
// WatchStreamAsync yields events as they're emitted by executors
|
||||
|
||||
@@ -61,8 +61,8 @@ IHost host = Host.CreateDefaultBuilder(args)
|
||||
|
||||
await host.StartAsync();
|
||||
|
||||
// Get the DurableExecutionEnvironment from DI - no need to manually resolve DurableTaskClient
|
||||
DurableExecutionEnvironment durableExecution = host.Services.GetRequiredService<DurableExecutionEnvironment>();
|
||||
// Get the IWorkflowClient from DI - no need to manually resolve DurableTaskClient
|
||||
IWorkflowClient workflowClient = host.Services.GetRequiredService<IWorkflowClient>();
|
||||
|
||||
Console.WriteLine("Workflow Events Demo - Enter input for slogan generation (or 'exit'):");
|
||||
|
||||
@@ -77,7 +77,7 @@ while (true)
|
||||
|
||||
try
|
||||
{
|
||||
await RunWorkflowWithStreamingAsync(input, workflow, durableExecution);
|
||||
await RunWorkflowWithStreamingAsync(input, workflow, workflowClient);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -90,11 +90,11 @@ while (true)
|
||||
await host.StopAsync();
|
||||
|
||||
// Runs a workflow and streams events as they occur
|
||||
async Task RunWorkflowWithStreamingAsync(string orderId, Workflow workflow, DurableExecutionEnvironment execution)
|
||||
async Task RunWorkflowWithStreamingAsync(string orderId, Workflow workflow, IWorkflowClient client)
|
||||
{
|
||||
// StreamAsync starts the workflow and returns a handle for observing events
|
||||
// Cast to DurableStreamingRun for durable-specific features like InstanceId
|
||||
await using DurableStreamingRun run = (DurableStreamingRun)await execution.StreamAsync(workflow, orderId);
|
||||
await using DurableStreamingRun run = (DurableStreamingRun)await client.StreamAsync(workflow, orderId);
|
||||
Console.WriteLine($"Started: {run.InstanceId}");
|
||||
|
||||
// WatchStreamAsync yields events as they're emitted by executors
|
||||
|
||||
Reference in New Issue
Block a user