CritiqueAndReviseExecutor
NexusLabs.Needlr.AgentFramework.Workflows¶
NexusLabs.Needlr.AgentFramework.Workflows.Sequential¶
CritiqueAndReviseExecutor Class¶
Implements an evaluate→revise→retry loop. A critic agent evaluates the current state, a programmatic check determines pass/fail, and if it fails a reviser agent applies feedback. The loop repeats up to the configured maximum number of additional attempts.
public sealed class CritiqueAndReviseExecutor : NexusLabs.Needlr.AgentFramework.Workflows.Sequential.IStageExecutor
Inheritance System.Object 🡒 CritiqueAndReviseExecutor
Implements IStageExecutor
Example¶
var executor = new CritiqueAndReviseExecutor(
criticAgent,
reviserAgent,
ctx => $"Review the draft in the workspace for quality.",
(ctx, feedback) => $"Revise the draft. Feedback: {feedback}",
(diag, feedback) => feedback?.Contains("PASS") == true,
maxRetries: 2);
var result = await executor.ExecuteAsync(context, cancellationToken);
Constructors¶
CritiqueAndReviseExecutor(AIAgent, AIAgent, Func<StageExecutionContext,string>, Func<StageExecutionContext,string,string>, Func<IAgentRunDiagnostics,string,bool>, int, Func<StageExecutionContext,string,bool>, Func<StageExecutionContext,string,Task>) Constructor¶
Initializes a new CritiqueAndReviseExecutor.
public CritiqueAndReviseExecutor(Microsoft.Agents.AI.AIAgent critic, Microsoft.Agents.AI.AIAgent reviser, System.Func<NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionContext,string> criticPromptFactory, System.Func<NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionContext,string,string> reviserPromptFactory, System.Func<NexusLabs.Needlr.AgentFramework.Diagnostics.IAgentRunDiagnostics?,string?,bool> passCheck, int maxRetries=3, System.Func<NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionContext,string?,bool>? postPassCheck=null, System.Func<NexusLabs.Needlr.AgentFramework.Workflows.Sequential.StageExecutionContext,string,System.Threading.Tasks.Task>? onRevisionCompleted=null);
Parameters¶
critic Microsoft.Agents.AI.AIAgent
The AI agent that evaluates the current state.
reviser Microsoft.Agents.AI.AIAgent
The AI agent that applies revision feedback.
criticPromptFactory System.Func<StageExecutionContext,System.String>
Builds the prompt sent to the critic agent from the stage context.
reviserPromptFactory System.Func<StageExecutionContext,System.String,System.String>
Builds the prompt sent to the reviser agent from the stage context and critic feedback.
passCheck System.Func<NexusLabs.Needlr.AgentFramework.Diagnostics.IAgentRunDiagnostics,System.String,System.Boolean>
Determines whether the critic's response constitutes a pass.
maxRetries System.Int32
Maximum number of revision attempts after the initial critique. Defaults to 3.
postPassCheck System.Func<StageExecutionContext,System.String,System.Boolean>
Optional secondary check applied after passCheck returns true. Returns false to override the pass and continue revision.
onRevisionCompleted System.Func<StageExecutionContext,System.String,System.Threading.Tasks.Task>
Optional callback invoked after the reviser runs, receiving the reviser's output text.
Methods¶
CritiqueAndReviseExecutor.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.