| | | 1 | | namespace NexusLabs.Needlr.AgentFramework.Workflows.Sequential; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Configures runtime behavior for a single pipeline stage, including |
| | | 5 | | /// conditional skipping, post-execution validation with retries, and |
| | | 6 | | /// per-stage token budgets. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <example> |
| | | 9 | | /// <code> |
| | | 10 | | /// var policy = new StageExecutionPolicy |
| | | 11 | | /// { |
| | | 12 | | /// ShouldSkip = ctx => ctx.StageIndex > 3, |
| | | 13 | | /// PostValidation = result => result.ResponseText?.Contains("error") == true |
| | | 14 | | /// ? "Response contained an error" |
| | | 15 | | /// : null, |
| | | 16 | | /// MaxAttempts = 3, |
| | | 17 | | /// TokenBudget = 5000, |
| | | 18 | | /// }; |
| | | 19 | | /// </code> |
| | | 20 | | /// </example> |
| | | 21 | | public sealed record StageExecutionPolicy |
| | | 22 | | { |
| | | 23 | | /// <summary> |
| | | 24 | | /// Evaluated at runtime. When true, the stage is skipped entirely. |
| | | 25 | | /// </summary> |
| | 26 | 26 | | public Func<StageExecutionContext, bool>? ShouldSkip { get; init; } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Called after stage execution. Returns <see langword="null"/> on success, |
| | | 30 | | /// or an error message that triggers a retry (up to <see cref="MaxAttempts"/>). |
| | | 31 | | /// </summary> |
| | 16 | 32 | | public Func<StageExecutionResult, string?>? PostValidation { get; init; } |
| | | 33 | | |
| | | 34 | | /// <summary> |
| | | 35 | | /// Maximum execution attempts for post-validation retries. Default is 1 (no retry). |
| | | 36 | | /// </summary> |
| | 45 | 37 | | public int MaxAttempts { get; init; } = 1; |
| | | 38 | | |
| | | 39 | | /// <summary> |
| | | 40 | | /// Optional per-stage token budget. When set, the runner scopes a child |
| | | 41 | | /// budget tracker for this stage. |
| | | 42 | | /// </summary> |
| | 10 | 43 | | public long? TokenBudget { get; init; } |
| | | 44 | | |
| | | 45 | | /// <summary> |
| | | 46 | | /// Called after stage execution (success or failure, not skip). |
| | | 47 | | /// Receives the execution result and context for workspace checks or state updates. |
| | | 48 | | /// </summary> |
| | 22 | 49 | | public Func<StageExecutionResult, StageExecutionContext, Task>? AfterExecution { get; init; } |
| | | 50 | | } |