< Summary

Information
Class: NexusLabs.Needlr.AgentFramework.AgentFrameworkAccessorServiceCollectionExtensions
Assembly: NexusLabs.Needlr.AgentFramework
File(s): /home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/AgentFrameworkAccessorServiceCollectionExtensions.cs
Line coverage
100%
Covered lines: 12
Uncovered lines: 0
Coverable lines: 12
Total lines: 59
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddAgentFrameworkAccessors(...)100%11100%

File(s)

/home/runner/work/needlr/needlr/src/NexusLabs.Needlr.AgentFramework/AgentFrameworkAccessorServiceCollectionExtensions.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.Extensions.DependencyInjection.Extensions;
 3
 4using NexusLabs.Needlr.AgentFramework.Context;
 5using NexusLabs.Needlr.AgentFramework.Diagnostics;
 6
 7namespace NexusLabs.Needlr.AgentFramework;
 8
 9/// <summary>
 10/// Extension methods that register the small set of Needlr Agent Framework accessors
 11/// that tools and test harnesses depend on, without registering the full
 12/// <see cref="IAgentFactory"/> / <see cref="WorkflowFactory"/> / iterative-loop infrastructure.
 13/// </summary>
 14/// <remarks>
 15/// <para>
 16/// Use this when you need the Needlr accessors (<see cref="IAgentExecutionContextAccessor"/>,
 17/// <see cref="IAgentDiagnosticsAccessor"/>, <see cref="IInFlightAgentDiagnosticsAccessor"/>,
 18/// <see cref="IAgentDiagnosticsWriter"/>) but do not want the rest of the Agent Framework
 19/// wiring — typically because you are constructing a minimal service provider for a
 20/// tool-level test.
 21/// </para>
 22/// <para>
 23/// The <c>UsingAgentFramework()</c> extension on <see cref="NexusLabs.Needlr.Injection.ConfiguredSyringe"/>
 24/// already registers these accessors as part of its broader infrastructure setup. Calling
 25/// <see cref="AddAgentFrameworkAccessors"/> after <c>UsingAgentFramework()</c> is a no-op because
 26/// every registration uses <see cref="ServiceCollectionDescriptorExtensions.TryAdd(IServiceCollection, ServiceDescripto
 27/// </para>
 28/// </remarks>
 29public static class AgentFrameworkAccessorServiceCollectionExtensions
 30{
 31    /// <summary>
 32    /// Registers the Needlr Agent Framework accessor singletons:
 33    /// <see cref="IAgentExecutionContextAccessor"/>, <see cref="IAgentDiagnosticsAccessor"/>,
 34    /// <see cref="IInFlightAgentDiagnosticsAccessor"/>, and <see cref="IAgentDiagnosticsWriter"/>.
 35    /// </summary>
 36    /// <param name="services">The service collection to add registrations to.</param>
 37    /// <returns>The same <paramref name="services"/> instance for chaining.</returns>
 38    /// <remarks>
 39    /// All registrations use <c>TryAddSingleton</c>, so calling this method is safe even if the
 40    /// accessors have already been registered by <c>UsingAgentFramework()</c> or another path.
 41    /// </remarks>
 42    public static IServiceCollection AddAgentFrameworkAccessors(this IServiceCollection services)
 43    {
 7844        ArgumentNullException.ThrowIfNull(services);
 45
 7846        services.TryAddSingleton<IAgentExecutionContextAccessor, AgentExecutionContextAccessor>();
 7847        services.TryAddSingleton<AgentDiagnosticsAccessor>(sp =>
 7848            new AgentDiagnosticsAccessor(
 7849                sp.GetService<ChatCompletionCollectorHolder>(),
 7850                sp.GetService<ToolCallCollectorHolder>()));
 7851        services.TryAddSingleton<IAgentDiagnosticsAccessor>(sp =>
 7852            sp.GetRequiredService<AgentDiagnosticsAccessor>());
 7853        services.TryAddSingleton<IAgentDiagnosticsWriter>(sp =>
 7854            sp.GetRequiredService<AgentDiagnosticsAccessor>());
 7855        services.TryAddSingleton<IInFlightAgentDiagnosticsAccessor, InFlightAgentDiagnosticsAccessor>();
 56
 7857        return services;
 58    }
 59}