| | | 1 | | namespace NexusLabs.Needlr.AgentFramework; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Declares a termination condition that is wired into the group chat manager for this agent |
| | | 5 | | /// (Layer 1). The condition is evaluated inside MAF's group chat loop, before the next agent |
| | | 6 | | /// turn starts, giving a clean early exit. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <remarks> |
| | | 9 | | /// <para> |
| | | 10 | | /// Apply to a class also decorated with <see cref="AgentGroupChatMemberAttribute"/>. Multiple |
| | | 11 | | /// conditions may be stacked; OR semantics apply (first match stops the workflow). |
| | | 12 | | /// </para> |
| | | 13 | | /// <para> |
| | | 14 | | /// The <c>conditionType</c> must implement <see cref="IWorkflowTerminationCondition"/>. |
| | | 15 | | /// Constructor arguments for the condition are passed via <c>ctorArgs</c>. |
| | | 16 | | /// </para> |
| | | 17 | | /// <example> |
| | | 18 | | /// <code> |
| | | 19 | | /// [AgentGroupChatMember("code-review")] |
| | | 20 | | /// [AgentTerminationCondition(typeof(KeywordTerminationCondition), "APPROVED")] |
| | | 21 | | /// public class ApprovalAgent { } |
| | | 22 | | /// </code> |
| | | 23 | | /// </example> |
| | | 24 | | /// </remarks> |
| | | 25 | | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] |
| | | 26 | | public sealed class AgentTerminationConditionAttribute : Attribute |
| | | 27 | | { |
| | | 28 | | /// <summary> |
| | | 29 | | /// Initializes a new instance of <see cref="AgentTerminationConditionAttribute"/>. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="conditionType"> |
| | | 32 | | /// The type that implements <see cref="IWorkflowTerminationCondition"/>. An instance is |
| | | 33 | | /// created at workflow construction time via |
| | | 34 | | /// <see cref="Activator.CreateInstance(Type, object[])"/> with <paramref name="ctorArgs"/>. |
| | | 35 | | /// </param> |
| | | 36 | | /// <param name="ctorArgs"> |
| | | 37 | | /// Arguments forwarded to the condition's constructor. May be empty if the condition has a |
| | | 38 | | /// parameterless constructor. |
| | | 39 | | /// </param> |
| | 196 | 40 | | public AgentTerminationConditionAttribute(Type conditionType, params object[] ctorArgs) |
| | | 41 | | { |
| | 196 | 42 | | ArgumentNullException.ThrowIfNull(conditionType); |
| | 196 | 43 | | ConditionType = conditionType; |
| | 196 | 44 | | CtorArgs = ctorArgs ?? []; |
| | 196 | 45 | | } |
| | | 46 | | |
| | | 47 | | /// <summary>Gets the type of the termination condition to instantiate.</summary> |
| | 1 | 48 | | public Type ConditionType { get; } |
| | | 49 | | |
| | | 50 | | /// <summary>Gets the constructor arguments forwarded when instantiating the condition.</summary> |
| | 1 | 51 | | public object[] CtorArgs { get; } |
| | | 52 | | } |