ToolResult
NexusLabs.Needlr.AgentFramework¶
NexusLabs.Needlr.AgentFramework.Tools¶
ToolResult Class¶
Static factory providing shorthand constructors for ToolResult<TValue,TError> using the default ToolError shape.
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.Needlr.AgentFramework.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
isTransient System.Nullable<System.Boolean>
Returns¶
NexusLabs.Needlr.AgentFramework.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.Needlr.AgentFramework.Tools.ToolResult<TValue,NexusLabs.Needlr.AgentFramework.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
isTransient System.Nullable<System.Boolean>
suggestion System.String
Returns¶
NexusLabs.Needlr.AgentFramework.Tools.ToolResult<TValue,ToolError>
ToolResult.Ok<TValue>(TValue) Method¶
Creates a successful ToolResult<TValue,TError>.
public static NexusLabs.Needlr.AgentFramework.Tools.ToolResult<TValue,NexusLabs.Needlr.AgentFramework.Tools.ToolError> Ok<TValue>(TValue value);
Type parameters¶
TValue
Parameters¶
value TValue
Returns¶
NexusLabs.Needlr.AgentFramework.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.Needlr.AgentFramework.Tools.IToolResult UnhandledFailure(System.Exception ex, System.Func<System.Exception,NexusLabs.Needlr.AgentFramework.Tools.ToolError>? formatter=null);
Parameters¶
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¶
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.