Skip to content

AgentFrameworkBuilderExtensions

NexusLabs.Foundry.MicrosoftAgentFramework

NexusLabs.Foundry.MicrosoftAgentFramework

AgentFrameworkBuilderExtensions Class

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

public static class AgentFrameworkBuilderExtensions

Inheritance System.Object 🡒 AgentFrameworkBuilderExtensions

Methods

AgentFrameworkBuilderExtensions.AddAgent<TAgent>(this AgentFrameworkBuilder) Method

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

public static NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder AddAgent<TAgent>(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe)
    where TAgent : class;

Type parameters

TAgent

Parameters

syringe AgentFrameworkBuilder

Returns

AgentFrameworkBuilder

AgentFrameworkBuilderExtensions.AddAgentFunctionGroupsFromAssemblies(this AgentFrameworkBuilder) Method

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

public static NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder AddAgentFunctionGroupsFromAssemblies(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe);

Parameters

syringe AgentFrameworkBuilder

Returns

AgentFrameworkBuilder

AgentFrameworkBuilderExtensions.AddAgentFunctionGroupsFromAssemblies(this AgentFrameworkBuilder, IReadOnlyList<Assembly>) Method

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

public static NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder AddAgentFunctionGroupsFromAssemblies(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe, System.Collections.Generic.IReadOnlyList<System.Reflection.Assembly> assemblies);

Parameters

syringe AgentFrameworkBuilder

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

Returns

AgentFrameworkBuilder

AgentFrameworkBuilderExtensions.AddAgentFunctionGroupsFromGenerated(this AgentFrameworkBuilder, 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.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder AddAgentFunctionGroupsFromGenerated(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe, System.Collections.Generic.IReadOnlyDictionary<string,System.Collections.Generic.IReadOnlyList<System.Type>> groups);

Parameters

syringe AgentFrameworkBuilder

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

AgentFrameworkBuilder

AgentFrameworkBuilderExtensions.AddAgentFunctionsFromGenerated(this AgentFrameworkBuilder, 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.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder AddAgentFunctionsFromGenerated(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe, System.Collections.Generic.IReadOnlyList<System.Type> functionTypes);

Parameters

syringe AgentFrameworkBuilder

The agent framework syringe to configure.

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

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

Returns

AgentFrameworkBuilder

Remarks

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

AgentFrameworkBuilderExtensions.AddAgentsFromGenerated(this AgentFrameworkBuilder, 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.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder AddAgentsFromGenerated(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe, System.Collections.Generic.IReadOnlyList<System.Type> agentTypes);

Parameters

syringe AgentFrameworkBuilder

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

Returns

AgentFrameworkBuilder

AgentFrameworkBuilderExtensions.ConfigureMetrics(this AgentFrameworkBuilder, Action<AgentFrameworkMetricsOptions>) Method

Configures the meter and ActivitySource names used by IAgentMetrics. Without this call, both default to "NexusLabs.Foundry.MicrosoftAgentFramework".

public static NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder ConfigureMetrics(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe, System.Action<NexusLabs.Foundry.MicrosoftAgentFramework.Diagnostics.AgentFrameworkMetricsOptions> configure);

Parameters

syringe AgentFrameworkBuilder

configure System.Action<AgentFrameworkMetricsOptions>

Returns

AgentFrameworkBuilder

Remarks

Consumers with existing dashboards keyed to a specific meter name can set it here to avoid a dashboard migration when adopting Foundry's metrics:

.UsingAgentFramework(af => af
    .ConfigureMetrics(o => o.MeterName = "ExampleProduct.Agents"))

AgentFrameworkBuilderExtensions.ConfigurePipelineMetrics(this AgentFrameworkBuilder, Action<PipelineMetricsOptions>) Method

Configures pipeline-shape OpenTelemetry metrics emitted by IPipelineMetrics via the meter and ActivitySource names on PipelineMetricsOptions. Without this call, the DI-registered IPipelineMetrics is the no-op implementation — observability is opt-in with zero overhead by default.

public static NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder ConfigurePipelineMetrics(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe, System.Action<NexusLabs.Foundry.MicrosoftAgentFramework.Diagnostics.PipelineMetricsOptions> configure);

Parameters

syringe AgentFrameworkBuilder

configure System.Action<PipelineMetricsOptions>

Returns

AgentFrameworkBuilder

Remarks

Sibling of ConfigureMetrics(this AgentFrameworkBuilder, Action<AgentFrameworkMetricsOptions>) — that targets per-agent-run metrics; this one targets per-pipeline / per-stage metrics emitted by SequentialPipelineRunner. Most consumers will want pipeline metrics under a separate meter (e.g. "ExampleProduct.Pipelines") so OTel views and Prometheus aggregation can target each scope independently:

.UsingAgentFramework(af => af
    .ConfigureMetrics(o => o.MeterName = "ExampleProduct.Agents")
    .ConfigurePipelineMetrics(o => o.MeterName = "ExampleProduct.Pipelines"))

AgentFrameworkBuilderExtensions.UsingChatClient(this AgentFrameworkBuilder, IChatClient) Method

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

public static NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder UsingChatClient(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe, Microsoft.Extensions.AI.IChatClient chatClient);

Parameters

syringe AgentFrameworkBuilder

chatClient Microsoft.Extensions.AI.IChatClient

Returns

AgentFrameworkBuilder

AgentFrameworkBuilderExtensions.UsingChatClient(this AgentFrameworkBuilder, 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.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder UsingChatClient(this NexusLabs.Foundry.MicrosoftAgentFramework.AgentFrameworkBuilder syringe, System.Func<System.IServiceProvider,Microsoft.Extensions.AI.IChatClient> chatClientFactory);

Parameters

syringe AgentFrameworkBuilder

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

Returns

AgentFrameworkBuilder