Skip to content

DelegateStageExecutor

NexusLabs.Needlr.AgentFramework.Workflows

NexusLabs.Needlr.AgentFramework.Workflows.Sequential

DelegateStageExecutor Class

Executes a pipeline stage by invoking a caller-provided delegate. Use for programmatic stages that do not involve an AI agent.

public sealed class DelegateStageExecutor : NexusLabs.Needlr.AgentFramework.Workflows.Sequential.IStageExecutor

Inheritance System.Object 🡒 DelegateStageExecutor

Implements IStageExecutor

Example

var executor = new DelegateStageExecutor(async (ctx, ct) =>
{
    var content = ctx.Workspace.TryReadFile("draft.md");
    // Transform content...
    ctx.Workspace.TryWriteFile("final.md", "transformed content");
});

var result = await executor.ExecuteAsync(context, cancellationToken);

Constructors

DelegateStageExecutor(Func<StageExecutionContext,CancellationToken,Task>) Constructor

Executes a pipeline stage by invoking a caller-provided delegate. Use for programmatic stages that do not involve an AI agent.

public DelegateStageExecutor(System.Func<NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionContext,System.Threading.CancellationToken,System.Threading.Tasks.Task> step);

Parameters

step System.Func<StageExecutionContext,System.Threading.CancellationToken,System.Threading.Tasks.Task>

The async delegate to execute for this stage.

Example

var executor = new DelegateStageExecutor(async (ctx, ct) =>
{
    var content = ctx.Workspace.TryReadFile("draft.md");
    // Transform content...
    ctx.Workspace.TryWriteFile("final.md", "transformed content");
});

var result = await executor.ExecuteAsync(context, cancellationToken);

Methods

DelegateStageExecutor.ExecuteAsync(StageExecutionContext, CancellationToken) Method

Executes the stage logic and returns a result indicating success or failure.

public System.Threading.Tasks.Task<NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionResult> ExecuteAsync(NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionContext context, System.Threading.CancellationToken cancellationToken);

Parameters

context StageExecutionContext

The execution context providing access to shared pipeline state.

cancellationToken System.Threading.CancellationToken

Token to observe for cancellation.

Implements ExecuteAsync(StageExecutionContext, CancellationToken)

Returns

System.Threading.Tasks.Task<StageExecutionResult>
A StageExecutionResult describing the outcome.