Nuta
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować się zalogować lub zmienić katalog.
Dostęp do tej strony wymaga autoryzacji. Możesz spróbować zmienić katalogi.
System zdarzeń przepływu pracy zapewnia obserwowalność wykonania przepływu pracy. Zdarzenia są emitowane w kluczowych punktach podczas wykonywania i mogą być odbierane w czasie rzeczywistym za pośrednictwem transmisji strumieniowej.
Wbudowane typy zdarzeń
// Workflow lifecycle events
WorkflowStartedEvent // Workflow execution begins
WorkflowOutputEvent // Workflow outputs data
WorkflowErrorEvent // Workflow encounters an error
WorkflowWarningEvent // Workflow encountered a warning
// Executor events
ExecutorInvokedEvent // Executor starts processing
ExecutorCompletedEvent // Executor finishes processing
ExecutorFailedEvent // Executor encounters an error
AgentResponseEvent // An agent run produces output
AgentResponseUpdateEvent // An agent run produces a streaming update
// Superstep events
SuperStepStartedEvent // Superstep begins
SuperStepCompletedEvent // Superstep completes
// Request events
RequestInfoEvent // A request is issued
# All events use the unified WorkflowEvent class with a type discriminator:
WorkflowEvent.type == "started" # Workflow execution begins
WorkflowEvent.type == "output" # Workflow produces an output
WorkflowEvent.type == "error" # Workflow encounters an error
WorkflowEvent.type == "warning" # Workflow encountered a warning
WorkflowEvent.type == "executor_invoked" # Executor starts processing
WorkflowEvent.type == "executor_completed" # Executor finishes processing
WorkflowEvent.type == "executor_failed" # Executor encounters an error
WorkflowEvent.type == "superstep_started" # Superstep begins
WorkflowEvent.type == "superstep_completed" # Superstep completes
WorkflowEvent.type == "request_info" # A request is issued
Korzystanie ze zdarzeń
using Microsoft.Agents.AI.Workflows;
await foreach (WorkflowEvent evt in run.WatchStreamAsync())
{
switch (evt)
{
case ExecutorInvokedEvent invoke:
Console.WriteLine($"Starting {invoke.ExecutorId}");
break;
case ExecutorCompletedEvent complete:
Console.WriteLine($"Completed {complete.ExecutorId}: {complete.Data}");
break;
case WorkflowOutputEvent output:
Console.WriteLine($"Workflow output: {output.Data}");
return;
case WorkflowErrorEvent error:
Console.WriteLine($"Workflow error: {error.Exception}");
return;
}
}
from agent_framework import WorkflowEvent
async for event in workflow.run_stream(input_message):
if event.type == "executor_invoked":
print(f"Starting {event.executor_id}")
elif event.type == "executor_completed":
print(f"Completed {event.executor_id}: {event.data}")
elif event.type == "output":
print(f"Workflow produced output: {event.data}")
return
elif event.type == "error":
print(f"Workflow error: {event.data}")
return
Zdarzenia niestandardowe
Definiowanie i emitowanie zdarzeń niestandardowych podczas wykonywania przepływu pracy w celu zwiększenia możliwości obserwowania.
using Microsoft.Agents.AI.Workflows;
internal sealed class CustomEvent(string message) : WorkflowEvent(message) { }
internal sealed partial class CustomExecutor() : Executor("CustomExecutor")
{
[MessageHandler]
private async ValueTask HandleAsync(string message, IWorkflowContext context)
{
await context.AddEventAsync(new CustomEvent($"Processing message: {message}"));
// Executor logic...
}
}
from agent_framework import (
handler,
Executor,
WorkflowContext,
WorkflowEvent,
)
class CustomExecutor(Executor):
@handler
async def handle(self, message: str, ctx: WorkflowContext[str]) -> None:
await ctx.add_event(WorkflowEvent("data", data=f"Processing message: {message}"))
# Executor logic...
Dalsze kroki
Powiązane tematy: