mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Minor cleanup. MCP tool works.
This commit is contained in:
@@ -7,7 +7,7 @@ namespace SingleAgent;
|
||||
/// <summary>
|
||||
/// Parses an Order ID from a string input and returns an Order object populated.
|
||||
/// </summary>
|
||||
internal sealed class OrderLookupExecutor() : Executor<string, Order>("OrderLookup")
|
||||
internal sealed class OrderLookup() : Executor<string, Order>("OrderLookup")
|
||||
{
|
||||
public override async ValueTask<Order> HandleAsync(string message, IWorkflowContext context, CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -19,7 +19,7 @@ internal sealed class OrderLookupExecutor() : Executor<string, Order>("OrderLook
|
||||
/// <summary>
|
||||
/// Enriches an Order object with additional information.
|
||||
/// </summary>
|
||||
internal sealed class OrderEnricherExecutor() : Executor<Order, Order>("EnrichOrder")
|
||||
internal sealed class OrderEnrich() : Executor<Order, Order>("EnrichOrder")
|
||||
{
|
||||
public override async ValueTask<Order> HandleAsync(Order message, IWorkflowContext context, CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -33,7 +33,7 @@ internal sealed class OrderEnricherExecutor() : Executor<Order, Order>("EnrichOr
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class PaymentProcessorExecutor() : Executor<Order, Order>("ProcessPayment")
|
||||
internal sealed class PaymentProcessor() : Executor<Order, Order>("ProcessPayment")
|
||||
{
|
||||
public override async ValueTask<Order> HandleAsync(Order message, IWorkflowContext context, CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -43,6 +43,14 @@ internal sealed class PaymentProcessorExecutor() : Executor<Order, Order>("Proce
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class OrderCancel() : Executor<Order, string>("OrderCancel")
|
||||
{
|
||||
public override async ValueTask<string> HandleAsync(Order message, IWorkflowContext context, CancellationToken cancellationToken = default)
|
||||
{
|
||||
return $"Order {message.Id} cancelled at {DateTime.UtcNow:g} UTC.";
|
||||
}
|
||||
}
|
||||
|
||||
internal sealed class Order
|
||||
{
|
||||
public Order(string id, decimal amount)
|
||||
|
||||
@@ -20,12 +20,10 @@ Func<string, string> orderParserFunc = input =>
|
||||
};
|
||||
var orderParserExecutor = orderParserFunc.BindAsExecutor("OrderParser");
|
||||
|
||||
Func<string, string> cancelOrderFunc = input => $"Cancelled order:{input}";
|
||||
var orderArchiver = orderParserFunc.BindAsExecutor("OrderArchiver");
|
||||
|
||||
OrderLookupExecutor orderLookupExecutor = new();
|
||||
OrderEnricherExecutor orderEnricherExeecutor = new();
|
||||
PaymentProcessorExecutor paymentProcessorExecutor = new();
|
||||
OrderLookup orderLookupExecutor = new();
|
||||
OrderEnrich orderEnricherExeecutor = new();
|
||||
PaymentProcessor paymentProcessorExecutor = new();
|
||||
OrderCancel orderArchiverExecutor = new();
|
||||
|
||||
Workflow processOrder = new WorkflowBuilder(orderParserExecutor)
|
||||
.WithName("FulfillOrder")
|
||||
@@ -39,12 +37,16 @@ Workflow cancelOrder = new WorkflowBuilder(orderParserExecutor)
|
||||
.WithName("CancelOrder")
|
||||
.WithDescription("Cancel an order")
|
||||
.AddEdge(orderParserExecutor, orderLookupExecutor)
|
||||
.AddEdge(orderLookupExecutor, orderArchiver)
|
||||
.AddEdge(orderLookupExecutor, orderArchiverExecutor)
|
||||
.Build();
|
||||
|
||||
var host = FunctionsApplication.CreateBuilder(args)
|
||||
.ConfigureFunctionsWebApplication()
|
||||
.ConfigureDurableOptions(options => options.Workflows.AddWorkflow([processOrder, cancelOrder]))
|
||||
.ConfigureDurableOptions(options =>
|
||||
{
|
||||
options.Workflows.AddWorkflow(processOrder);
|
||||
options.Workflows.AddWorkflow(cancelOrder, true);
|
||||
})
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
|
||||
Reference in New Issue
Block a user