| | | 1 | | namespace NexusLabs.Needlr.AgentFramework; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Declares a handoff target for a <see cref="NeedlrAiAgentAttribute"/>-annotated agent. |
| | | 5 | | /// Apply this attribute one or more times to specify which agents the decorated agent can hand off |
| | | 6 | | /// to when used as the initial agent in a handoff workflow via |
| | | 7 | | /// <see cref="IWorkflowFactory.CreateHandoffWorkflow{TInitialAgent}"/>. |
| | | 8 | | /// </summary> |
| | | 9 | | /// <remarks> |
| | | 10 | | /// When the <c>NexusLabs.Needlr.AgentFramework.Generators</c> package is referenced, the source |
| | | 11 | | /// generator emits a strongly-typed extension method (e.g. <c>CreateTriageHandoffWorkflow</c>) |
| | | 12 | | /// on <see cref="IWorkflowFactory"/> for each agent type that carries this attribute. The generated |
| | | 13 | | /// method encapsulates the agent type so the composition root requires no direct type references. |
| | | 14 | | /// </remarks> |
| | | 15 | | /// <example> |
| | | 16 | | /// <code> |
| | | 17 | | /// [NeedlrAiAgent(Instructions = "Triage incoming customer requests.")] |
| | | 18 | | /// [AgentHandoffsTo(typeof(BillingAgent), "Route billing or payment questions to the billing agent")] |
| | | 19 | | /// [AgentHandoffsTo(typeof(SupportAgent), "Route general support requests to the support agent")] |
| | | 20 | | /// public class TriageAgent { } |
| | | 21 | | /// |
| | | 22 | | /// // The source generator emits: |
| | | 23 | | /// // workflowFactory.CreateTriageAgentHandoffWorkflow() |
| | | 24 | | /// // which wires all handoffs without requiring direct type references at the call site. |
| | | 25 | | /// </code> |
| | | 26 | | /// </example> |
| | | 27 | | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] |
| | | 28 | | public sealed class AgentHandoffsToAttribute : Attribute |
| | | 29 | | { |
| | | 30 | | /// <summary> |
| | | 31 | | /// Initializes a new instance of <see cref="AgentHandoffsToAttribute"/>. |
| | | 32 | | /// </summary> |
| | | 33 | | /// <param name="targetAgentType"> |
| | | 34 | | /// The type of the target agent. Must be annotated with <see cref="NeedlrAiAgentAttribute"/>. |
| | | 35 | | /// </param> |
| | | 36 | | /// <param name="handoffReason"> |
| | | 37 | | /// A description of when the decorated agent should hand off to <paramref name="targetAgentType"/>. |
| | | 38 | | /// Passed to the underlying MAF handoff builder as the tool description. When <see langword="null"/>, |
| | | 39 | | /// MAF derives the reason from the target agent's description or name. |
| | | 40 | | /// </param> |
| | 402 | 41 | | public AgentHandoffsToAttribute(Type targetAgentType, string? handoffReason = null) |
| | | 42 | | { |
| | 402 | 43 | | ArgumentNullException.ThrowIfNull(targetAgentType); |
| | 402 | 44 | | TargetAgentType = targetAgentType; |
| | 402 | 45 | | HandoffReason = handoffReason; |
| | 402 | 46 | | } |
| | | 47 | | |
| | | 48 | | /// <summary>Gets the type of the target agent to hand off to.</summary> |
| | 12 | 49 | | public Type TargetAgentType { get; } |
| | | 50 | | |
| | | 51 | | /// <summary>Gets the optional reason describing when to hand off to <see cref="TargetAgentType"/>.</summary> |
| | 12 | 52 | | public string? HandoffReason { get; } |
| | | 53 | | } |