Skip to content

NeedlrAgentMiddlewareExtensions

NexusLabs.Needlr.AgentFramework.Workflows

NexusLabs.Needlr.AgentFramework.Workflows.Middleware

NeedlrAgentMiddlewareExtensions Class

Extension methods that add Needlr middleware to the NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe and to MAF's Microsoft.Agents.AI.AIAgentBuilder directly.

public static class NeedlrAgentMiddlewareExtensions

Inheritance System.Object 🡒 NeedlrAgentMiddlewareExtensions

Methods

NeedlrAgentMiddlewareExtensions.UseResilience(this AIAgentBuilder) Method

Adds a default resilience pipeline to an Microsoft.Agents.AI.AIAgentBuilder directly, for agents not managed by Needlr.

public static Microsoft.Agents.AI.AIAgentBuilder UseResilience(this Microsoft.Agents.AI.AIAgentBuilder builder);

Parameters

builder Microsoft.Agents.AI.AIAgentBuilder

Returns

Microsoft.Agents.AI.AIAgentBuilder

NeedlrAgentMiddlewareExtensions.UseResilience(this AIAgentBuilder, ResiliencePipeline<AgentResponse>) Method

Adds a custom resilience pipeline to an Microsoft.Agents.AI.AIAgentBuilder directly, for agents not managed by Needlr.

public static Microsoft.Agents.AI.AIAgentBuilder UseResilience(this Microsoft.Agents.AI.AIAgentBuilder builder, Polly.ResiliencePipeline<Microsoft.Agents.AI.AgentResponse> pipeline);

Parameters

builder Microsoft.Agents.AI.AIAgentBuilder

pipeline Polly.ResiliencePipeline<Microsoft.Agents.AI.AgentResponse>

Returns

Microsoft.Agents.AI.AIAgentBuilder

NeedlrAgentMiddlewareExtensions.UseToolResultMiddleware(this AIAgentBuilder) Method

Adds ToolResultFunctionMiddleware to an Microsoft.Agents.AI.AIAgentBuilder directly, for agents not managed by Needlr.

public static Microsoft.Agents.AI.AIAgentBuilder UseToolResultMiddleware(this Microsoft.Agents.AI.AIAgentBuilder builder);

Parameters

builder Microsoft.Agents.AI.AIAgentBuilder

Returns

Microsoft.Agents.AI.AIAgentBuilder

NeedlrAgentMiddlewareExtensions.UsingResilience(this AgentFrameworkSyringe) Method

Wraps every agent created by the factory with a default resilience pipeline: 2 retries with exponential back-off and a 120-second timeout.

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

Parameters

syringe NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe

Returns

NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe

Remarks

Per-agent settings can be overridden by applying NexusLabs.Needlr.AgentFramework.AgentResilienceAttribute to the agent class.

For a custom pipeline use the UsingResilience(this AgentFrameworkSyringe, Action<ResiliencePipelineBuilder<AgentResponse>>) overload.

NeedlrAgentMiddlewareExtensions.UsingResilience(this AgentFrameworkSyringe, Action<ResiliencePipelineBuilder<AgentResponse>>) Method

Wraps every agent created by the factory with a custom resilience pipeline.

public static NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe UsingResilience(this NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe syringe, System.Action<Polly.ResiliencePipelineBuilder<Microsoft.Agents.AI.AgentResponse>> configure);

Parameters

syringe NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe

The syringe to configure.

configure System.Action<Polly.ResiliencePipelineBuilder<Microsoft.Agents.AI.AgentResponse>>

Callback to configure the Polly.ResiliencePipelineBuilder<>.

Returns

NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe

NeedlrAgentMiddlewareExtensions.UsingToolResultMiddleware(this AgentFrameworkSyringe) Method

Adds ToolResultFunctionMiddleware to every agent created by the factory.

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

Parameters

syringe NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe

Returns

NexusLabs.Needlr.AgentFramework.AgentFrameworkSyringe

Remarks

This ensures that all [AgentFunction] methods return a safe, structured JSON payload to the LLM — even when they throw an unhandled exception.