Skip to content

IAIAgentBuilderPlugin

NexusLabs.Needlr.AgentFramework

NexusLabs.Needlr.AgentFramework

IAIAgentBuilderPlugin Interface

Extension point for adding middleware layers to every agent created by IAgentFactory. Implementations are registered via NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe.Plugins and applied in order during CreateAgent<TAgent>().

public interface IAIAgentBuilderPlugin

Example

public sealed class LoggingPlugin : IAIAgentBuilderPlugin
{
    public void Configure(AIAgentBuilderPluginOptions options)
    {
        options.AgentBuilder.Use(
            runFunc: async (messages, session, runOptions, innerAgent, ct) =>
            {
                Console.WriteLine($"Agent '{innerAgent.Name}' starting...");
                var response = await innerAgent.RunAsync(messages, session, runOptions, ct);
                Console.WriteLine($"Agent '{innerAgent.Name}' completed.");
                return response;
            },
            runStreamingFunc: null);
    }
}

Remarks

Built-in plugins include the diagnostics middleware (AgentDiagnosticsPlugin) and resilience middleware (AgentResiliencePlugin). Custom plugins can add logging, rate limiting, content filtering, or any other cross-cutting concern that should apply to every agent.

Methods

IAIAgentBuilderPlugin.Configure(AIAgentBuilderPluginOptions) Method

Called once per agent creation to configure the builder's middleware pipeline. Use AgentBuilder to add Use(...) middleware layers.

void Configure(NexusLabs.Needlr.AgentFramework.AIAgentBuilderPluginOptions options);

Parameters

options AIAgentBuilderPluginOptions

Provides access to the AIAgentBuilder for the agent being constructed.