Table of Contents

Class OrchestrationContext

Namespace
LMKit.Agents.Orchestration
Assembly
LM-Kit.NET.dll

Provides shared context and state during orchestrated execution.

The context is passed between agents in a workflow and can be used to share data, accumulate results, and coordinate execution. All mutating members are safe to call from multiple agents executing concurrently (e.g., from ParallelOrchestrator); reads return point-in-time snapshots.

public sealed class OrchestrationContext
Inheritance
OrchestrationContext
Inherited Members

Examples

Reading orchestration state from a BeforeAgentExecution handler:

using LMKit.Agents.Orchestration;

orchestrator.BeforeAgentExecution += (sender, e) => { OrchestrationContext ctx = e.Context; Console.WriteLine($"Step {ctx.CurrentStep}: starting agent on input '{ctx.CurrentInput}'");

// Share data across agents:
ctx.SetState("started_at_step", ctx.CurrentStep);

// Cooperatively stop the orchestration if a prior step failed:
if (ctx.Results.Count > 0 && ctx.Results[^1].Status != AgentExecutionStatus.Completed)
{
    ctx.Stop("previous step did not complete");
}

};

Constructors

OrchestrationContext(string)

Initializes a new instance of the OrchestrationContext class.

Properties

AccumulatedOutput

Gets or sets the accumulated output from agents.

CurrentInput

Gets or sets the current working input being passed between agents.

CurrentStep

Gets the current step number in the orchestration (1-based).

OriginalInput

Gets the original input that started the orchestration.

Results

Gets a snapshot of the results from agents that have executed.

ShouldStop

Gets or sets a value indicating whether the orchestration should stop. Volatile-backed: a write from one parallel agent is immediately visible to other agents polling this flag for early-exit signaling.

StopReason

Gets or sets the reason for stopping, if applicable.

Trace

Gets a snapshot of the execution trace for debugging.

Methods

AddResult(AgentExecutionResult, string)

Records an agent execution result.

AddTrace(string)

Adds a trace entry for debugging.

GetState<T>(string, T)

Retrieves a value from the shared state.

GetTotalInferenceCount()

Gets the total inference count across all recorded results.

HasState(string)

Checks if a state key exists.

SetState(string, object)

Stores a value in the shared state.

Stop(string)

Signals that the orchestration should stop.

Share