| | | 1 | | namespace NexusLabs.Needlr.AgentFramework; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Declares a deterministic reducer node for fan-in convergence in a named |
| | | 5 | | /// graph workflow. The reducer aggregates branch outputs without incurring |
| | | 6 | | /// LLM cost — it is a pure function, not an agent. |
| | | 7 | | /// </summary> |
| | | 8 | | /// <remarks> |
| | | 9 | | /// <para> |
| | | 10 | | /// The <see cref="ReducerMethod"/> must be a <c>public static</c> method on the |
| | | 11 | | /// decorated class that accepts <see cref="System.Collections.Generic.IReadOnlyList{T}"/> |
| | | 12 | | /// of <see cref="string"/> and returns <see cref="string"/>. |
| | | 13 | | /// </para> |
| | | 14 | | /// </remarks> |
| | | 15 | | /// <example> |
| | | 16 | | /// <code> |
| | | 17 | | /// [AgentGraphReducer("ResearchPipeline", ReducerMethod = nameof(MergeResults))] |
| | | 18 | | /// public static class ResearchReducer |
| | | 19 | | /// { |
| | | 20 | | /// public static string MergeResults(IReadOnlyList<string> branchOutputs) |
| | | 21 | | /// => string.Join("\n---\n", branchOutputs); |
| | | 22 | | /// } |
| | | 23 | | /// </code> |
| | | 24 | | /// </example> |
| | | 25 | | [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] |
| | | 26 | | public sealed class AgentGraphReducerAttribute : Attribute |
| | | 27 | | { |
| | | 28 | | /// <summary> |
| | | 29 | | /// Initializes a new <see cref="AgentGraphReducerAttribute"/>. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="graphName">The name of the graph this reducer belongs to.</param> |
| | 184 | 32 | | public AgentGraphReducerAttribute(string graphName) |
| | | 33 | | { |
| | 184 | 34 | | ArgumentException.ThrowIfNullOrWhiteSpace(graphName); |
| | 184 | 35 | | GraphName = graphName; |
| | 184 | 36 | | } |
| | | 37 | | |
| | | 38 | | /// <summary>Gets the graph name this reducer belongs to.</summary> |
| | 184 | 39 | | public string GraphName { get; } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Gets or sets the name of the static method on the decorated class that |
| | | 43 | | /// performs the reduction. The method must accept |
| | | 44 | | /// <see cref="System.Collections.Generic.IReadOnlyList{T}"/> of |
| | | 45 | | /// <see cref="string"/> and return <see cref="string"/>. |
| | | 46 | | /// </summary> |
| | | 47 | | /// <remarks> |
| | | 48 | | /// If not specified, defaults to <c>"Reduce"</c> by convention. The source |
| | | 49 | | /// generator will look for a <c>public static string Reduce(IReadOnlyList<string>)</c> |
| | | 50 | | /// method on the decorated class. |
| | | 51 | | /// </remarks> |
| | 206 | 52 | | public string? ReducerMethod { get; set; } |
| | | 53 | | } |