mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Add error handling to additional workflow samples with agents
Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com>
This commit is contained in:
committed by
Jacob Alber
Unverified
parent
66111a5705
commit
ddf1d63854
@@ -64,9 +64,23 @@ public static class Program
|
||||
await using StreamingRun run = await InProcessExecution.StreamAsync(workflow, input: "What is temperature?");
|
||||
await foreach (WorkflowEvent evt in run.WatchStreamAsync())
|
||||
{
|
||||
if (evt is WorkflowOutputEvent output)
|
||||
switch (evt)
|
||||
{
|
||||
Console.WriteLine($"Workflow completed with results:\n{output.Data}");
|
||||
case WorkflowOutputEvent output:
|
||||
Console.WriteLine($"Workflow completed with results:\n{output.Data}");
|
||||
break;
|
||||
|
||||
case ExecutorFailedEvent failureEvent:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Executor failed [{failureEvent.ExecutorId}]: {failureEvent.Data?.Message ?? "Unknown error"}");
|
||||
Console.ResetColor();
|
||||
break;
|
||||
|
||||
case WorkflowErrorEvent errorEvent:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Workflow error: {errorEvent.Exception?.Message ?? "Unknown error"}");
|
||||
Console.ResetColor();
|
||||
throw errorEvent.Exception ?? new InvalidOperationException("Workflow encountered an error.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
-2
@@ -68,9 +68,23 @@ public static class Program
|
||||
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
|
||||
await foreach (WorkflowEvent evt in run.WatchStreamAsync())
|
||||
{
|
||||
if (evt is WorkflowOutputEvent outputEvent)
|
||||
switch (evt)
|
||||
{
|
||||
Console.WriteLine($"{outputEvent}");
|
||||
case WorkflowOutputEvent outputEvent:
|
||||
Console.WriteLine($"{outputEvent}");
|
||||
break;
|
||||
|
||||
case ExecutorFailedEvent failureEvent:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Executor failed [{failureEvent.ExecutorId}]: {failureEvent.Data?.Message ?? "Unknown error"}");
|
||||
Console.ResetColor();
|
||||
break;
|
||||
|
||||
case WorkflowErrorEvent errorEvent:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Workflow error: {errorEvent.Exception?.Message ?? "Unknown error"}");
|
||||
Console.ResetColor();
|
||||
throw errorEvent.Exception ?? new InvalidOperationException("Workflow encountered an error.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,9 +84,23 @@ public static class Program
|
||||
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
|
||||
await foreach (WorkflowEvent evt in run.WatchStreamAsync())
|
||||
{
|
||||
if (evt is WorkflowOutputEvent outputEvent)
|
||||
switch (evt)
|
||||
{
|
||||
Console.WriteLine($"{outputEvent}");
|
||||
case WorkflowOutputEvent outputEvent:
|
||||
Console.WriteLine($"{outputEvent}");
|
||||
break;
|
||||
|
||||
case ExecutorFailedEvent failureEvent:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Executor failed [{failureEvent.ExecutorId}]: {failureEvent.Data?.Message ?? "Unknown error"}");
|
||||
Console.ResetColor();
|
||||
break;
|
||||
|
||||
case WorkflowErrorEvent errorEvent:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Workflow error: {errorEvent.Exception?.Message ?? "Unknown error"}");
|
||||
Console.ResetColor();
|
||||
throw errorEvent.Exception ?? new InvalidOperationException("Workflow encountered an error.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+19
-6
@@ -92,14 +92,27 @@ public static class Program
|
||||
await run.TrySendMessageAsync(new TurnToken(emitEvents: true));
|
||||
await foreach (WorkflowEvent evt in run.WatchStreamAsync())
|
||||
{
|
||||
if (evt is WorkflowOutputEvent outputEvent)
|
||||
switch (evt)
|
||||
{
|
||||
Console.WriteLine($"{outputEvent}");
|
||||
}
|
||||
case WorkflowOutputEvent outputEvent:
|
||||
Console.WriteLine($"{outputEvent}");
|
||||
break;
|
||||
|
||||
if (evt is DatabaseEvent databaseEvent)
|
||||
{
|
||||
Console.WriteLine($"{databaseEvent}");
|
||||
case DatabaseEvent databaseEvent:
|
||||
Console.WriteLine($"{databaseEvent}");
|
||||
break;
|
||||
|
||||
case ExecutorFailedEvent failureEvent:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Executor failed [{failureEvent.ExecutorId}]: {failureEvent.Data?.Message ?? "Unknown error"}");
|
||||
Console.ResetColor();
|
||||
break;
|
||||
|
||||
case WorkflowErrorEvent errorEvent:
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine($"Workflow error: {errorEvent.Exception?.Message ?? "Unknown error"}");
|
||||
Console.ResetColor();
|
||||
throw errorEvent.Exception ?? new InvalidOperationException("Workflow encountered an error.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user