Skip to content

IWorkflowTerminationCondition

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework

IWorkflowTerminationCondition Interface

Evaluates whether a workflow should terminate early after an agent response.

public interface IWorkflowTerminationCondition

Remarks

Implement this interface to provide custom termination logic. Built-in implementations are available in the NexusLabs.Needlr.AgentFramework.Workflows package: - KeywordTerminationCondition — stops when a response contains a keyword. - RegexTerminationCondition — stops when a response matches a regex. - ToolCallTerminationCondition — stops when an agent calls a specific tool. Preferred over keyword matching for structured approval workflows.

Conditions are declared on agent classes via AgentTerminationConditionAttribute (Layer 1: group chat, fires before the next turn) or WorkflowRunTerminationConditionAttribute (Layer 2: any workflow type, fires via RunAsync).

Methods

IWorkflowTerminationCondition.ShouldTerminate(TerminationContext) Method

Determines whether the workflow should terminate after the given agent response.

bool ShouldTerminate(NexusLabs.Needlr.AgentFramework.TerminationContext context);

Parameters

context TerminationContext

Context for the completed agent turn.

Returns

System.Boolean
true to stop the workflow; false to continue.