| | | 1 | | namespace NexusLabs.Needlr.AgentFramework; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Declares a termination condition that is evaluated by Needlr's <c>RunAsync</c> execution |
| | | 5 | | /// helpers after each completed agent turn (Layer 2). Unlike |
| | | 6 | | /// <see cref="AgentTerminationConditionAttribute"/>, this works with all workflow types |
| | | 7 | | /// (group chat, handoff, sequential). |
| | | 8 | | /// </summary> |
| | | 9 | | /// <remarks> |
| | | 10 | | /// <para> |
| | | 11 | | /// Apply to any agent class. Multiple conditions may be stacked; OR semantics apply (first |
| | | 12 | | /// match stops the workflow). Conditions from all agents in the workflow are merged; a condition |
| | | 13 | | /// fires only when the agent it is declared on produces the matching response. |
| | | 14 | | /// </para> |
| | | 15 | | /// <para> |
| | | 16 | | /// The <c>conditionType</c> must implement <see cref="IWorkflowTerminationCondition"/>. |
| | | 17 | | /// Constructor arguments are passed via <c>ctorArgs</c>. |
| | | 18 | | /// </para> |
| | | 19 | | /// <para> |
| | | 20 | | /// For group chat workflows, prefer <see cref="AgentTerminationConditionAttribute"/> — it fires |
| | | 21 | | /// before the next turn starts, which is a cleaner stop than Layer 2 (which fires after the |
| | | 22 | | /// response is fully emitted). |
| | | 23 | | /// </para> |
| | | 24 | | /// <example> |
| | | 25 | | /// <code> |
| | | 26 | | /// // Stop a sequential pipeline early on extraction failure |
| | | 27 | | /// [AgentSequenceMember("content-pipeline", Order = 1)] |
| | | 28 | | /// [WorkflowRunTerminationCondition(typeof(KeywordTerminationCondition), "EXTRACTION_FAILED")] |
| | | 29 | | /// public class ContentExtractorAgent { } |
| | | 30 | | /// </code> |
| | | 31 | | /// </example> |
| | | 32 | | /// </remarks> |
| | | 33 | | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] |
| | | 34 | | public sealed class WorkflowRunTerminationConditionAttribute : Attribute |
| | | 35 | | { |
| | | 36 | | /// <summary> |
| | | 37 | | /// Initializes a new instance of <see cref="WorkflowRunTerminationConditionAttribute"/>. |
| | | 38 | | /// </summary> |
| | | 39 | | /// <param name="conditionType"> |
| | | 40 | | /// The type that implements <see cref="IWorkflowTerminationCondition"/>. An instance is |
| | | 41 | | /// created at workflow construction time via |
| | | 42 | | /// <see cref="Activator.CreateInstance(Type, object[])"/> with <paramref name="ctorArgs"/>. |
| | | 43 | | /// </param> |
| | | 44 | | /// <param name="ctorArgs"> |
| | | 45 | | /// Arguments forwarded to the condition's constructor. May be empty if the condition has a |
| | | 46 | | /// parameterless constructor. |
| | | 47 | | /// </param> |
| | 0 | 48 | | public WorkflowRunTerminationConditionAttribute(Type conditionType, params object[] ctorArgs) |
| | | 49 | | { |
| | 0 | 50 | | ArgumentNullException.ThrowIfNull(conditionType); |
| | 0 | 51 | | ConditionType = conditionType; |
| | 0 | 52 | | CtorArgs = ctorArgs ?? []; |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | /// <summary>Gets the type of the termination condition to instantiate.</summary> |
| | 0 | 56 | | public Type ConditionType { get; } |
| | | 57 | | |
| | | 58 | | /// <summary>Gets the constructor arguments forwarded when instantiating the condition.</summary> |
| | 0 | 59 | | public object[] CtorArgs { get; } |
| | | 60 | | } |