| | | 1 | | namespace NexusLabs.Needlr.AgentFramework.Workflows.Sequential; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Executes a pipeline stage by invoking a caller-provided delegate. |
| | | 5 | | /// Use for programmatic stages that do not involve an AI agent. |
| | | 6 | | /// </summary> |
| | | 7 | | /// <param name="step">The async delegate to execute for this stage.</param> |
| | | 8 | | /// <example> |
| | | 9 | | /// <code> |
| | | 10 | | /// var executor = new DelegateStageExecutor(async (ctx, ct) => |
| | | 11 | | /// { |
| | | 12 | | /// var content = ctx.Workspace.TryReadFile("draft.md"); |
| | | 13 | | /// // Transform content... |
| | | 14 | | /// ctx.Workspace.TryWriteFile("final.md", "transformed content"); |
| | | 15 | | /// }); |
| | | 16 | | /// |
| | | 17 | | /// var result = await executor.ExecuteAsync(context, cancellationToken); |
| | | 18 | | /// </code> |
| | | 19 | | /// </example> |
| | | 20 | | [DoNotAutoRegister] |
| | 111 | 21 | | public sealed class DelegateStageExecutor( |
| | 111 | 22 | | Func<StageExecutionContext, CancellationToken, Task> step) : IStageExecutor |
| | | 23 | | { |
| | | 24 | | /// <inheritdoc /> |
| | | 25 | | public async Task<StageExecutionResult> ExecuteAsync( |
| | | 26 | | StageExecutionContext context, |
| | | 27 | | CancellationToken cancellationToken) |
| | | 28 | | { |
| | 83 | 29 | | await step(context, cancellationToken); |
| | 81 | 30 | | return StageExecutionResult.Success(context.StageName, diagnostics: null, responseText: null); |
| | 81 | 31 | | } |
| | | 32 | | } |