Skip to content

ToolResultFunctionMiddleware

NexusLabs.Needlr.AgentFramework.Workflows

NexusLabs.Needlr.AgentFramework.Workflows.Middleware

ToolResultFunctionMiddleware Class

MAF function-invocation middleware that intercepts [AgentFunction] return values and exceptions, ensuring the LLM always receives a structured JSON response instead of a raw stack trace.

public sealed class ToolResultFunctionMiddleware : NexusLabs.Needlr.AgentFramework.IAIAgentBuilderPlugin

Inheritance System.Object 🡒 ToolResultFunctionMiddleware

Implements NexusLabs.Needlr.AgentFramework.IAIAgentBuilderPlugin

Remarks

When an [AgentFunction] method returns a NexusLabs.Needlr.AgentFramework.Tools.IToolResult: - Success — the LLM receives the NexusLabs.Needlr.AgentFramework.Tools.IToolResult.BoxedValue directly. - Failure — the LLM receives { "error": { … } } (the NexusLabs.Needlr.AgentFramework.Tools.IToolResult.BoxedError wrapped), and the original System.Exception is preserved on NexusLabs.Needlr.AgentFramework.Tools.IToolResult.Exception for diagnostics.

When an [AgentFunction] throws an unhandled exception, the middleware catches it, wraps it in an NexusLabs.Needlr.AgentFramework.Tools.ToolResult.UnhandledFailure(System.Exception) result, and returns a safe generic error message to the LLM. NexusLabs.Needlr.AgentFramework.Tools.IToolResult.IsTransient is null in this case.

Non-NexusLabs.Needlr.AgentFramework.Tools.IToolResult return values pass through unchanged.

Methods

ToolResultFunctionMiddleware.Configure(AIAgentBuilderPluginOptions) Method

Called during agent factory initialisation to configure the agent builder.

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

Parameters

options NexusLabs.Needlr.AgentFramework.AIAgentBuilderPluginOptions

Implements Configure(AIAgentBuilderPluginOptions)