| | | 1 | | using Microsoft.Extensions.AI; |
| | | 2 | | |
| | | 3 | | using NexusLabs.Needlr.AgentFramework.Progress; |
| | | 4 | | |
| | | 5 | | namespace NexusLabs.Needlr.AgentFramework.Diagnostics; |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Extension methods for wiring <see cref="DiagnosticsFunctionInvokingChatClient"/> |
| | | 9 | | /// into an MEAI chat client pipeline. |
| | | 10 | | /// </summary> |
| | | 11 | | public static class DiagnosticsFunctionInvocationExtensions |
| | | 12 | | { |
| | | 13 | | /// <summary> |
| | | 14 | | /// Inserts a <see cref="DiagnosticsFunctionInvokingChatClient"/> into the pipeline |
| | | 15 | | /// that records per-tool-call diagnostics, OTel metrics, and Activity spans. |
| | | 16 | | /// </summary> |
| | | 17 | | /// <remarks> |
| | | 18 | | /// <para> |
| | | 19 | | /// This replaces the standard <c>UseFunctionInvocation()</c> call. Do not use both — |
| | | 20 | | /// it would create two <c>FunctionInvokingChatClient</c> layers and produce |
| | | 21 | | /// duplicate tool calls. |
| | | 22 | | /// </para> |
| | | 23 | | /// </remarks> |
| | | 24 | | /// <param name="builder">The chat client builder.</param> |
| | | 25 | | /// <param name="metrics">Optional OTel metrics recorder.</param> |
| | | 26 | | /// <param name="progressAccessor">Optional progress reporter for real-time events.</param> |
| | | 27 | | /// <returns>The builder, for chaining.</returns> |
| | | 28 | | public static ChatClientBuilder UseDiagnosticsFunctionInvocation( |
| | | 29 | | this ChatClientBuilder builder, |
| | | 30 | | IAgentMetrics? metrics = null, |
| | | 31 | | IProgressReporterAccessor? progressAccessor = null) |
| | | 32 | | { |
| | 1 | 33 | | ArgumentNullException.ThrowIfNull(builder); |
| | | 34 | | |
| | 1 | 35 | | return builder.Use(innerClient => |
| | 2 | 36 | | new DiagnosticsFunctionInvokingChatClient( |
| | 2 | 37 | | innerClient, metrics, progressAccessor)); |
| | | 38 | | } |
| | | 39 | | } |