Skip to content

ToolResult

NexusLabs.Foundry.MicrosoftAgentFramework

NexusLabs.Foundry.MicrosoftAgentFramework.Tools

ToolResult Class

Static factory providing shorthand constructors for ToolResult<TValue,TError> using the default ToolError shape.

public static class ToolResult

Inheritance System.Object 🡒 ToolResult

Methods

ToolResult.Fail<TValue,TError>(TError, Exception, Nullable<bool>) Method

Creates a failure ToolResult<TValue,TError> with a custom error shape.

public static NexusLabs.Foundry.MicrosoftAgentFramework.Tools.ToolResult<TValue,TError> Fail<TValue,TError>(TError error, System.Exception? ex=null, System.Nullable<bool> isTransient=null)
    where TError : class;

Type parameters

TValue

TError

Parameters

error TError

ex System.Exception

isTransient System.Nullable<System.Boolean>

Returns

NexusLabs.Foundry.MicrosoftAgentFramework.Tools.ToolResult<TValue,TError>

ToolResult.Fail<TValue>(string, Exception, Nullable<bool>, string) Method

Creates a failure ToolResult<TValue,TError> from a message string.

public static NexusLabs.Foundry.MicrosoftAgentFramework.Tools.ToolResult<TValue,NexusLabs.Foundry.MicrosoftAgentFramework.Tools.ToolError> Fail<TValue>(string message, System.Exception? ex=null, System.Nullable<bool> isTransient=null, string? suggestion=null);

Type parameters

TValue

Parameters

message System.String

ex System.Exception

isTransient System.Nullable<System.Boolean>

suggestion System.String

Returns

NexusLabs.Foundry.MicrosoftAgentFramework.Tools.ToolResult<TValue,ToolError>

ToolResult.Ok<TValue>(TValue) Method

Creates a successful ToolResult<TValue,TError>.

public static NexusLabs.Foundry.MicrosoftAgentFramework.Tools.ToolResult<TValue,NexusLabs.Foundry.MicrosoftAgentFramework.Tools.ToolError> Ok<TValue>(TValue value);

Type parameters

TValue

Parameters

value TValue

Returns

NexusLabs.Foundry.MicrosoftAgentFramework.Tools.ToolResult<TValue,ToolError>

ToolResult.UnhandledFailure(Exception, Func<Exception,ToolError>) Method

Creates an IToolResult for an unhandled exception caught by middleware. IsTransient is null because middleware cannot determine whether the failure is transient without domain knowledge.

public static NexusLabs.Foundry.MicrosoftAgentFramework.Tools.IToolResult UnhandledFailure(System.Exception ex, System.Func<System.Exception,NexusLabs.Foundry.MicrosoftAgentFramework.Tools.ToolError>? formatter=null);

Parameters

ex System.Exception

The exception that escaped the tool body.

formatter System.Func<System.Exception,ToolError>

Optional formatter that converts the exception into the LLM-facing ToolError. When null, a default formatter is used that includes the exception type name without the message body.

Returns

IToolResult

Remarks

The default LLM-facing error message is "An unexpected error occurred ({ExceptionTypeName}). Please try again." — the type name is included so the model can distinguish a shape mismatch from a timeout from an authorization failure and choose a sensible recovery strategy. The System.Exception.Message body is intentionally \<em>not\</em> included to avoid leaking application or PII details (DB connection strings, user data, internal IDs). Pass formatter to override the LLM-facing message — useful when an application wants to keep the bland legacy message or surface domain-specific guidance.