Skip to content

AgentFrameworkSyringeExtensions

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework

AgentFrameworkSyringeExtensions Class

Extension methods for AgentFrameworkSyringe providing fluent configuration of the Microsoft Agent Framework integration.

public static class AgentFrameworkSyringeExtensions

Inheritance System.Object 🡒 AgentFrameworkSyringeExtensions

Methods

AgentFrameworkSyringeExtensions.AddAgent<TAgent>(this AgentFrameworkSyringe) Method

Registers a single declared agent type for string-based lookup via CreateAgent(string). The type must be decorated with NeedlrAiAgentAttribute.

public static NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe AddAgent<TAgent>(this NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe syringe)
    where TAgent : class;

Type parameters

TAgent

Parameters

syringe AgentFrameworkSyringe

Returns

AgentFrameworkSyringe

AgentFrameworkSyringeExtensions.AddAgentFunctionGroupsFromAssemblies(this AgentFrameworkSyringe) Method

Scans registered assemblies for classes decorated with AgentFunctionGroupAttribute and registers them by group name. Requires UsingReflection() to be configured.

public static NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe AddAgentFunctionGroupsFromAssemblies(this NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe syringe);

Parameters

syringe AgentFrameworkSyringe

Returns

AgentFrameworkSyringe

AgentFrameworkSyringeExtensions.AddAgentFunctionGroupsFromAssemblies(this AgentFrameworkSyringe, IReadOnlyList<Assembly>) Method

Scans the provided assemblies for classes decorated with AgentFunctionGroupAttribute and registers them by group name.

public static NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe AddAgentFunctionGroupsFromAssemblies(this NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe syringe, System.Collections.Generic.IReadOnlyList<System.Reflection.Assembly> assemblies);

Parameters

syringe AgentFrameworkSyringe

assemblies System.Collections.Generic.IReadOnlyList<System.Reflection.Assembly>

Returns

AgentFrameworkSyringe

AgentFrameworkSyringeExtensions.AddAgentFunctionGroupsFromGenerated(this AgentFrameworkSyringe, IReadOnlyDictionary<string,IReadOnlyList<Type>>) Method

Adds agent function groups from a compile-time generated group map. This is the recommended approach for AOT/trimmed applications.

public static NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe AddAgentFunctionGroupsFromGenerated(this NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe syringe, System.Collections.Generic.IReadOnlyDictionary<string,System.Collections.Generic.IReadOnlyList<System.Type>> groups);

Parameters

syringe AgentFrameworkSyringe

The agent framework syringe to configure.

groups System.Collections.Generic.IReadOnlyDictionary<System.String,System.Collections.Generic.IReadOnlyList<System.Type>>

Compile-time discovered group map, typically from the generated AgentFrameworkFunctionGroupRegistry.AllGroups.

Returns

AgentFrameworkSyringe

AgentFrameworkSyringeExtensions.AddAgentFunctionsFromGenerated(this AgentFrameworkSyringe, IReadOnlyList<Type>) Method

Adds agent functions from a compile-time generated list of types. This is the recommended approach for AOT/trimmed applications because the source generator discovers types at build time rather than runtime.

public static NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe AddAgentFunctionsFromGenerated(this NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe syringe, System.Collections.Generic.IReadOnlyList<System.Type> functionTypes);

Parameters

syringe AgentFrameworkSyringe

The agent framework syringe to configure.

functionTypes System.Collections.Generic.IReadOnlyList<System.Type>

Compile-time discovered function types, typically from the generated NexusLabs.Needlr.Generated.AgentFrameworkFunctions.AllFunctionTypes.

Returns

AgentFrameworkSyringe

Remarks

This overload performs no reflection for type discovery. The NexusLabs.Needlr.AgentFramework.AgentFactory still uses reflection when building Microsoft.Extensions.AI.AIFunction schema from method signatures — the same inherent limitation present in Microsoft.Extensions.AI.

AgentFrameworkSyringeExtensions.AddAgentsFromGenerated(this AgentFrameworkSyringe, IReadOnlyList<Type>) Method

Registers a compile-time generated list of declared agent types for string-based lookup via CreateAgent(string). Typically called with the output of the generated AgentRegistry.AllAgentTypes.

public static NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe AddAgentsFromGenerated(this NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe syringe, System.Collections.Generic.IReadOnlyList<System.Type> agentTypes);

Parameters

syringe AgentFrameworkSyringe

agentTypes System.Collections.Generic.IReadOnlyList<System.Type>

Returns

AgentFrameworkSyringe

AgentFrameworkSyringeExtensions.UsingChatClient(this AgentFrameworkSyringe, IChatClient) Method

Sets the Microsoft.Extensions.AI.IChatClient used by all agents created from the factory. This is the preferred alternative to calling NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringeExtensions.Configure(NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe,System.Action{NexusLabs.Needlr.AgentFramework.AgentFrameworkConfigureOptions}) and setting ChatClientFactory.

public static NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe UsingChatClient(this NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe syringe, Microsoft.Extensions.AI.IChatClient chatClient);

Parameters

syringe AgentFrameworkSyringe

chatClient Microsoft.Extensions.AI.IChatClient

Returns

AgentFrameworkSyringe

AgentFrameworkSyringeExtensions.UsingChatClient(this AgentFrameworkSyringe, Func<IServiceProvider,IChatClient>) Method

Sets a factory that creates the Microsoft.Extensions.AI.IChatClient used by all agents. The factory receives the DI System.IServiceProvider for resolving dependencies.

public static NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe UsingChatClient(this NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe syringe, System.Func<System.IServiceProvider,Microsoft.Extensions.AI.IChatClient> chatClientFactory);

Parameters

syringe AgentFrameworkSyringe

chatClientFactory System.Func<System.IServiceProvider,Microsoft.Extensions.AI.IChatClient>

Returns

AgentFrameworkSyringe