-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathWorkflowOutputEvent.cs
More file actions
82 lines (71 loc) · 3.12 KB
/
WorkflowOutputEvent.cs
File metadata and controls
82 lines (71 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) Microsoft. All rights reserved.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;
namespace Microsoft.Agents.AI.Workflows;
/// <summary>
/// Event triggered when a workflow executor yields output.
/// </summary>
[JsonDerivedType(typeof(AgentResponseEvent))]
[JsonDerivedType(typeof(AgentResponseUpdateEvent))]
public class WorkflowOutputEvent : WorkflowEvent
{
/// <summary>
/// Initializes a new instance of the <see cref="WorkflowOutputEvent"/> class.
/// </summary>
/// <param name="data">The output data.</param>
/// <param name="executorId">The identifier of the executor that yielded this output.</param>
public WorkflowOutputEvent(object data, string executorId) : base(data)
{
this.ExecutorId = executorId;
}
/// <summary>
/// The unique identifier of the executor that yielded this output.
/// </summary>
public string ExecutorId { get; }
/// <summary>
/// The unique identifier of the executor that yielded this output.
/// </summary>
[Obsolete("Use ExecutorId instead.")]
public string SourceId => this.ExecutorId;
/// <summary>
/// Determines whether the underlying data is of the specified type or a derived type.
/// </summary>
/// <typeparam name="T">The type to compare with the type of the underlying data.</typeparam>
/// <returns>true if the underlying data is assignable to type T; otherwise, false.</returns>
public bool Is<T>() => this.IsType(typeof(T));
/// <summary>
/// Determines whether the underlying data is of the specified type or a derived type, and
/// returns it as that type if it is.
/// </summary>
/// <typeparam name="T">The type to compare with the type of the underlying data.</typeparam>
/// <returns>true if the underlying data is assignable to type T; otherwise, false.</returns>
public bool Is<T>([NotNullWhen(true)] out T? maybeValue)
{
if (this.Data is T value)
{
maybeValue = value;
return true;
}
maybeValue = default;
return false;
}
/// <summary>
/// Determines whether the underlying data is of the specified type or a derived type.
/// </summary>
/// <param name="type">The type to compare with the type of the underlying data.</param>
/// <returns>true if the underlying data is assignable to type T; otherwise, false.</returns>
public bool IsType(Type type) => this.Data is { } data && type.IsInstanceOfType(data);
/// <summary>
/// Attempts to retrieve the underlying data as the specified type.
/// </summary>
/// <typeparam name="T">The type to which to cast.</typeparam>
/// <returns>The value of Data as to the target type.</returns>
public T? As<T>() => this.Data is T value ? value : default;
/// <summary>
/// Attempts to retrieve the underlying data as the specified type.
/// </summary>
/// <param name="type">The type to which to cast.</param>
/// <returns>The value of Data as to the target type.</returns>
public object? AsType(Type type) => this.IsType(type) ? this.Data : null;
}