PhaseContext
NexusLabs.Needlr.AgentFramework.Workflows¶
NexusLabs.Needlr.AgentFramework.Workflows.Sequential¶
PhaseContext Class¶
Provides typed access to pipeline state during phase lifecycle hooks (OnEnterAsync and OnExitAsync).
public sealed record PhaseContext : System.IEquatable<NexusLabs.Needlr.AgentFramework.Workflows.Sequential.PhaseContext>
Inheritance System.Object 🡒 PhaseContext
Implements System.IEquatable<PhaseContext>
Example¶
var policy = new PipelinePhasePolicy
{
OnEnterAsync = (ctx, ct) =>
{
var state = ctx.GetRequiredState<MyPipelineState>();
Console.WriteLine($"Phase {ctx.PhaseIndex + 1}/{ctx.TotalPhases}: {ctx.PhaseName}");
return ValueTask.CompletedTask;
},
};
Constructors¶
PhaseContext(string, int, int, IWorkspace, object) Constructor¶
Provides typed access to pipeline state during phase lifecycle hooks (OnEnterAsync and OnExitAsync).
public PhaseContext(string PhaseName, int PhaseIndex, int TotalPhases, NexusLabs.Needlr.AgentFramework.Workspace.IWorkspace Workspace, object? PipelineState=null);
Parameters¶
PhaseName System.String
Human-readable name of the current phase.
PhaseIndex System.Int32
Zero-based index of the current phase in the pipeline.
TotalPhases System.Int32
Total number of phases in the pipeline.
Workspace NexusLabs.Needlr.AgentFramework.Workspace.IWorkspace
The shared workspace for the pipeline.
PipelineState System.Object
Optional shared state object passed to all phases. Use GetRequiredState<T>() for type-safe access.
Example¶
var policy = new PipelinePhasePolicy
{
OnEnterAsync = (ctx, ct) =>
{
var state = ctx.GetRequiredState<MyPipelineState>();
Console.WriteLine($"Phase {ctx.PhaseIndex + 1}/{ctx.TotalPhases}: {ctx.PhaseName}");
return ValueTask.CompletedTask;
},
};
Properties¶
PhaseContext.PhaseIndex Property¶
Zero-based index of the current phase in the pipeline.
Property Value¶
PhaseContext.PhaseName Property¶
Human-readable name of the current phase.
Property Value¶
PhaseContext.PipelineState Property¶
Optional shared state object passed to all phases. Use GetRequiredState<T>() for type-safe access.
Property Value¶
PhaseContext.TotalPhases Property¶
Total number of phases in the pipeline.
Property Value¶
PhaseContext.Workspace Property¶
The shared workspace for the pipeline.
Property Value¶
NexusLabs.Needlr.AgentFramework.Workspace.IWorkspace
Methods¶
PhaseContext.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.