StageExecutionContext
NexusLabs.Needlr.AgentFramework.Workflows¶
NexusLabs.Needlr.AgentFramework.Workflows.Sequential¶
StageExecutionContext Class¶
Provides typed access to the pipeline's shared state during stage execution.
public sealed record StageExecutionContext : System.IEquatable<NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionContext>
Inheritance System.Object 🡒 StageExecutionContext
Implements System.IEquatable<StageExecutionContext>
Example¶
public async Task<StageExecutionResult> ExecuteAsync(
StageExecutionContext context,
CancellationToken cancellationToken)
{
Console.WriteLine($"Running stage {context.StageIndex + 1}/{context.TotalStages}: {context.StageName}");
if (context.PhaseName is not null)
Console.WriteLine($" Phase: {context.PhaseName} (stage {context.StageIndexInPhase + 1}/{context.TotalStagesInPhase})");
return StageExecutionResult.Success(context.StageName, diagnostics: null, responseText: null);
}
Constructors¶
StageExecutionContext(IWorkspace, IAgentDiagnosticsAccessor, IProgressReporter, int, int, string, CancellationToken, object, string, Nullable<int>, Nullable<int>, Nullable<int>) Constructor¶
Provides typed access to the pipeline's shared state during stage execution.
public StageExecutionContext(NexusLabs.Needlr.AgentFramework.Workspace.IWorkspace Workspace, NexusLabs.Needlr.AgentFramework.Diagnostics.IAgentDiagnosticsAccessor DiagnosticsAccessor, NexusLabs.Needlr.AgentFramework.Progress.IProgressReporter? ProgressReporter, int StageIndex, int TotalStages, string StageName, System.Threading.CancellationToken CallerCancellationToken=default(System.Threading.CancellationToken), object? PipelineState=null, string? PhaseName=null, System.Nullable<int> PhaseIndex=null, System.Nullable<int> StageIndexInPhase=null, System.Nullable<int> TotalStagesInPhase=null);
Parameters¶
Workspace NexusLabs.Needlr.AgentFramework.Workspace.IWorkspace
The shared workspace for reading/writing files across stages.
DiagnosticsAccessor NexusLabs.Needlr.AgentFramework.Diagnostics.IAgentDiagnosticsAccessor
Accessor for capturing per-stage diagnostics.
ProgressReporter NexusLabs.Needlr.AgentFramework.Progress.IProgressReporter
Optional progress reporter for emitting pipeline events.
StageIndex System.Int32
Zero-based index of the current stage in the pipeline.
TotalStages System.Int32
Total number of stages in the pipeline.
StageName System.String
Human-readable name of the current stage.
CallerCancellationToken System.Threading.CancellationToken
The original caller's cancellation token. Decorators that create linked tokens (e.g. TimeoutExecutor) should check this to distinguish user cancellation from internal timeouts.
PipelineState System.Object
Optional shared state object passed to all stages in the pipeline. Use GetRequiredState<T>() to retrieve it with type safety.
PhaseName System.String
The name of the pipeline phase this stage belongs to, or null when running a flat (non-phased) pipeline.
PhaseIndex System.Nullable<System.Int32>
Zero-based index of the current phase, or null for flat pipelines.
StageIndexInPhase System.Nullable<System.Int32>
Zero-based index of the current stage within its phase, or null for flat pipelines.
TotalStagesInPhase System.Nullable<System.Int32>
Total number of stages in the current phase, or null for flat pipelines.
Example¶
public async Task<StageExecutionResult> ExecuteAsync(
StageExecutionContext context,
CancellationToken cancellationToken)
{
Console.WriteLine($"Running stage {context.StageIndex + 1}/{context.TotalStages}: {context.StageName}");
if (context.PhaseName is not null)
Console.WriteLine($" Phase: {context.PhaseName} (stage {context.StageIndexInPhase + 1}/{context.TotalStagesInPhase})");
return StageExecutionResult.Success(context.StageName, diagnostics: null, responseText: null);
}
Properties¶
StageExecutionContext.CallerCancellationToken Property¶
The original caller's cancellation token. Decorators that create linked tokens (e.g. TimeoutExecutor) should check this to distinguish user cancellation from internal timeouts.
Property Value¶
System.Threading.CancellationToken
StageExecutionContext.DiagnosticsAccessor Property¶
Accessor for capturing per-stage diagnostics.
public NexusLabs.Needlr.AgentFramework.Diagnostics.IAgentDiagnosticsAccessor DiagnosticsAccessor { get; init; }
Property Value¶
NexusLabs.Needlr.AgentFramework.Diagnostics.IAgentDiagnosticsAccessor
StageExecutionContext.PhaseIndex Property¶
Zero-based index of the current phase, or null for flat pipelines.
Property Value¶
StageExecutionContext.PhaseName Property¶
The name of the pipeline phase this stage belongs to, or null when running a flat (non-phased) pipeline.
Property Value¶
StageExecutionContext.PipelineState Property¶
Optional shared state object passed to all stages in the pipeline. Use GetRequiredState<T>() to retrieve it with type safety.
Property Value¶
StageExecutionContext.ProgressReporter Property¶
Optional progress reporter for emitting pipeline events.
Property Value¶
NexusLabs.Needlr.AgentFramework.Progress.IProgressReporter
StageExecutionContext.StageIndex Property¶
Zero-based index of the current stage in the pipeline.
Property Value¶
StageExecutionContext.StageIndexInPhase Property¶
Zero-based index of the current stage within its phase, or null for flat pipelines.
Property Value¶
StageExecutionContext.StageName Property¶
Human-readable name of the current stage.
Property Value¶
StageExecutionContext.TotalStages Property¶
Total number of stages in the pipeline.
Property Value¶
StageExecutionContext.TotalStagesInPhase Property¶
Total number of stages in the current phase, or null for flat pipelines.
Property Value¶
StageExecutionContext.Workspace Property¶
The shared workspace for reading/writing files across stages.
Property Value¶
NexusLabs.Needlr.AgentFramework.Workspace.IWorkspace
Methods¶
StageExecutionContext.GetRequiredState<T>() Method¶
Gets the typed pipeline state, or throws if no state was provided or the type doesn't match.
Type parameters¶
T
The expected pipeline state type.
Returns¶
T
The pipeline state cast to T.
Exceptions¶
System.InvalidOperationException
Thrown when PipelineState is null or not of type T.