| | | 1 | | using NexusLabs.Needlr.AgentFramework.Diagnostics; |
| | | 2 | | |
| | | 3 | | namespace NexusLabs.Needlr.AgentFramework.Workflows.Sequential; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Describes the outcome of executing a single pipeline stage, including |
| | | 7 | | /// diagnostics, response text, and success/failure state. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <param name="StageName">The name of the stage that was executed.</param> |
| | | 10 | | /// <param name="Diagnostics">Captured diagnostics for the stage, or <see langword="null"/> if not available.</param> |
| | | 11 | | /// <param name="ResponseText">The text response produced by the stage, or <see langword="null"/> for non-agent stages.< |
| | | 12 | | /// <param name="Succeeded">Whether the stage completed successfully.</param> |
| | | 13 | | /// <param name="Exception">The exception that caused failure, or <see langword="null"/> on success.</param> |
| | | 14 | | /// <param name="FailureDisposition">Controls how the pipeline runner handles a failed result. |
| | | 15 | | /// Only meaningful when <paramref name="Succeeded"/> is <see langword="false"/>.</param> |
| | | 16 | | /// <example> |
| | | 17 | | /// <code> |
| | | 18 | | /// var result = StageExecutionResult.Success("Writer", diagnostics, "Draft text"); |
| | | 19 | | /// if (result.Succeeded) |
| | | 20 | | /// Console.WriteLine($"Stage '{result.StageName}' produced: {result.ResponseText}"); |
| | | 21 | | /// </code> |
| | | 22 | | /// </example> |
| | 168 | 23 | | public sealed record StageExecutionResult( |
| | 10 | 24 | | string StageName, |
| | 174 | 25 | | IAgentRunDiagnostics? Diagnostics, |
| | 94 | 26 | | string? ResponseText, |
| | 130 | 27 | | bool Succeeded, |
| | 26 | 28 | | Exception? Exception = null, |
| | 189 | 29 | | FailureDisposition FailureDisposition = FailureDisposition.AbortPipeline) |
| | | 30 | | { |
| | | 31 | | /// <summary> |
| | | 32 | | /// Creates a successful result for a stage. |
| | | 33 | | /// </summary> |
| | | 34 | | /// <param name="stageName">The name of the completed stage.</param> |
| | | 35 | | /// <param name="diagnostics">Captured diagnostics, or <see langword="null"/>.</param> |
| | | 36 | | /// <param name="responseText">The text response, or <see langword="null"/>.</param> |
| | | 37 | | /// <returns>A successful <see cref="StageExecutionResult"/>.</returns> |
| | | 38 | | public static StageExecutionResult Success( |
| | | 39 | | string stageName, |
| | | 40 | | IAgentRunDiagnostics? diagnostics, |
| | | 41 | | string? responseText) => |
| | 126 | 42 | | new(stageName, diagnostics, responseText, Succeeded: true); |
| | | 43 | | |
| | | 44 | | /// <summary> |
| | | 45 | | /// Creates a failed result for a stage. |
| | | 46 | | /// </summary> |
| | | 47 | | /// <param name="stageName">The name of the failed stage.</param> |
| | | 48 | | /// <param name="exception">The exception that caused the failure.</param> |
| | | 49 | | /// <param name="diagnostics">Captured diagnostics, or <see langword="null"/>.</param> |
| | | 50 | | /// <param name="disposition">How the pipeline runner should handle this failure. |
| | | 51 | | /// Defaults to <see cref="FailureDisposition.AbortPipeline"/>.</param> |
| | | 52 | | /// <returns>A failed <see cref="StageExecutionResult"/>.</returns> |
| | | 53 | | public static StageExecutionResult Failed( |
| | | 54 | | string stageName, |
| | | 55 | | Exception exception, |
| | | 56 | | IAgentRunDiagnostics? diagnostics = null, |
| | | 57 | | FailureDisposition disposition = FailureDisposition.AbortPipeline) => |
| | 42 | 58 | | new(stageName, diagnostics, ResponseText: null, Succeeded: false, |
| | 42 | 59 | | Exception: exception, FailureDisposition: disposition); |
| | | 60 | | |
| | | 61 | | /// <summary> |
| | | 62 | | /// Creates a result indicating the stage was skipped. |
| | | 63 | | /// </summary> |
| | | 64 | | /// <param name="stageName">The name of the skipped stage.</param> |
| | | 65 | | /// <returns>A successful <see cref="StageExecutionResult"/> with no diagnostics or response.</returns> |
| | | 66 | | public static StageExecutionResult Skipped(string stageName) => |
| | 0 | 67 | | new(stageName, Diagnostics: null, ResponseText: null, Succeeded: true); |
| | | 68 | | } |