| | | 1 | | namespace NexusLabs.Needlr.AgentFramework.Workflows; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// The complete topology of a graph workflow, discovered from attributes at |
| | | 5 | | /// runtime. Immutable once built. |
| | | 6 | | /// </summary> |
| | 61 | 7 | | internal sealed record GraphTopology( |
| | 139 | 8 | | Type? EntryType, |
| | 213 | 9 | | HashSet<Type> AllTypes, |
| | 271 | 10 | | Dictionary<Type, GraphJoinMode> JoinModes, |
| | 222 | 11 | | Dictionary<Type, List<Type>> IncomingTypes, |
| | 366 | 12 | | Dictionary<Type, IReadOnlyList<Type>> InboundEdges, |
| | 101 | 13 | | Dictionary<Type, IReadOnlyList<Type>> OutboundEdges, |
| | 86 | 14 | | GraphRoutingMode GraphRoutingMode, |
| | 177 | 15 | | Dictionary<Type, List<GraphEdgeDetail>> OutgoingEdgesBySource, |
| | 79 | 16 | | Dictionary<Type, GraphRoutingMode> EffectiveRoutingModes, |
| | 51 | 17 | | Dictionary<(Type Source, Type Target), bool> EdgeIsRequired, |
| | 23 | 18 | | Func<IReadOnlyList<string>, string>? ReducerFunc, |
| | 63 | 19 | | Type? ReducerType) |
| | | 20 | | { |
| | | 21 | | /// <summary> |
| | | 22 | | /// Whether any node in this graph uses <see cref="GraphJoinMode.WaitAny"/>. |
| | | 23 | | /// </summary> |
| | | 24 | | public bool HasWaitAnyNodes => |
| | 77 | 25 | | JoinModes.Values.Any(m => m == GraphJoinMode.WaitAny); |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// Whether this graph requires the Needlr-native executor instead of the |
| | | 29 | | /// MAF BSP engine. The MAF BSP path only supports unconditional WaitAll |
| | | 30 | | /// graphs with Deterministic/AllMatching routing and no reducers. Any |
| | | 31 | | /// advanced feature forces the Needlr-native executor. |
| | | 32 | | /// </summary> |
| | | 33 | | public bool RequiresNeedlrExecutor => |
| | 43 | 34 | | HasWaitAnyNodes || |
| | 43 | 35 | | HasConditions || |
| | 43 | 36 | | HasOptionalEdges || |
| | 43 | 37 | | HasReducer || |
| | 43 | 38 | | HasNonTrivialRouting; |
| | | 39 | | |
| | | 40 | | private bool HasConditions => |
| | 21 | 41 | | OutgoingEdgesBySource.Values |
| | 17 | 42 | | .SelectMany(edges => edges) |
| | 41 | 43 | | .Any(e => e.Condition is not null); |
| | | 44 | | |
| | | 45 | | private bool HasOptionalEdges => |
| | 26 | 46 | | EdgeIsRequired.Values.Any(isReq => !isReq); |
| | | 47 | | |
| | | 48 | | private bool HasReducer => |
| | 12 | 49 | | ReducerFunc is not null; |
| | | 50 | | |
| | | 51 | | private bool HasNonTrivialRouting => |
| | 9 | 52 | | GraphRoutingMode != GraphRoutingMode.Deterministic && |
| | 9 | 53 | | GraphRoutingMode != GraphRoutingMode.AllMatching || |
| | 9 | 54 | | EffectiveRoutingModes.Values.Any(m => |
| | 12 | 55 | | m != GraphRoutingMode.Deterministic && |
| | 12 | 56 | | m != GraphRoutingMode.AllMatching); |
| | | 57 | | } |