mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Add YieldOutputAsync calls to 05_WorkflowEvents sample executors
The integration test asserts that WorkflowOutputEvent is found in the stream, but the sample executors only used AddEventAsync for custom events and never called YieldOutputAsync. Since WorkflowOutputEvent is only emitted via explicit YieldOutputAsync calls, the assertion would fail. Added YieldOutputAsync to each executor to match the test expectation and demonstrate the API in the sample. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -40,7 +40,7 @@ internal sealed record Order(string Id, DateTime OrderDate, bool IsCancelled, st
|
||||
internal sealed record Customer(string Name, string Email);
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
// Executors - emit events via IWorkflowContext.AddEventAsync
|
||||
// Executors - emit events via AddEventAsync and YieldOutputAsync
|
||||
// ═══════════════════════════════════════════════════════════════════════════════
|
||||
|
||||
/// <summary>
|
||||
@@ -67,6 +67,9 @@ internal sealed class OrderLookup() : Executor<string, Order>("OrderLookup")
|
||||
|
||||
await context.AddEventAsync(new OrderFoundEvent(order.Customer.Name), cancellationToken);
|
||||
|
||||
// YieldOutputAsync emits a WorkflowOutputEvent observable via streaming
|
||||
await context.YieldOutputAsync(order, cancellationToken);
|
||||
|
||||
return order;
|
||||
}
|
||||
}
|
||||
@@ -96,6 +99,8 @@ internal sealed class OrderCancel() : Executor<Order, Order>("OrderCancel")
|
||||
await context.AddEventAsync(new CancellationProgressEvent(100, "Complete"), cancellationToken);
|
||||
await context.AddEventAsync(new OrderCancelledEvent(), cancellationToken);
|
||||
|
||||
await context.YieldOutputAsync(cancelledOrder, cancellationToken);
|
||||
|
||||
return cancelledOrder;
|
||||
}
|
||||
}
|
||||
@@ -117,6 +122,8 @@ internal sealed class SendEmail() : Executor<Order, string>("SendEmail")
|
||||
|
||||
await context.AddEventAsync(new EmailSentEvent(message.Customer.Email), cancellationToken);
|
||||
|
||||
await context.YieldOutputAsync(result, cancellationToken);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user