Skip to content

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.

public int PhaseIndex { get; init; }

Property Value

System.Int32

PhaseContext.PhaseName Property

Human-readable name of the current phase.

public string PhaseName { get; init; }

Property Value

System.String

PhaseContext.PipelineState Property

Optional shared state object passed to all phases. Use GetRequiredState<T>() for type-safe access.

public object? PipelineState { get; init; }

Property Value

System.Object

PhaseContext.TotalPhases Property

Total number of phases in the pipeline.

public int TotalPhases { get; init; }

Property Value

System.Int32

PhaseContext.Workspace Property

The shared workspace for the pipeline.

public NexusLabs.Needlr.AgentFramework.Workspace.IWorkspace Workspace { get; init; }

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.

public T GetRequiredState<T>()
    where T : class;

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.