Table of Contents

Enum ToolCallResultType

Namespace
LMKit.Agents.Tools
Assembly
LM-Kit.NET.dll

Classifies the outcome of a tool invocation.

public enum ToolCallResultType

Fields

Success = 0

The tool executed successfully and returned a result.

This is the expected outcome when a tool completes normally. The ResultJson contains the tool's return value, which should be a valid JSON value (object, array, string, number, boolean, or null).

Expected JSON: Any valid JSON value representing the tool's output.

Error = 1

The tool failed to execute or produced an application-level error.

This status indicates something went wrong during tool execution. Common causes include invalid arguments, network failures, resource not found, or internal tool errors.

Expected JSON: {"error": {"message": "...", "code": "OPTIONAL_CODE", "type": "OptionalType"}}

The model receives this error information and can adapt its response accordingly, potentially trying alternative approaches or informing the user of the issue.

Canceled = 2

The tool invocation was cancelled before or during execution.

Cancellation typically occurs due to:

  • User-initiated cancellation via CancellationToken
  • Policy vetoing the call (e.g., in a BeforeToolInvocation handler)
  • System-level cancellation (e.g., application shutdown)

Expected JSON: {"canceled": {"reason": "...", "by": "user|policy|system"}}

Timeout = 3

The tool did not complete within the allowed time budget.

Timeout occurs when a tool takes longer than the configured maximum duration. This is distinct from cancellation in that it was not intentionally stopped, but rather exceeded resource limits.

Expected JSON: {"timeout": {"durationMs": 30000}}

Consider retrying with an extended timeout, using a fallback approach, or informing the user that the operation is taking longer than expected.

Denied = 4

The tool invocation was denied by the ToolPermissionPolicy.

This status indicates the configured permission policy blocked the tool from executing. The model receives this information so it can adapt its approach without retrying the same denied tool.

Expected JSON: {"denied": {"tool": "...", "reason": "..."}}

Examples

Example: Handling different result types

using LMKit.Agents.Tools;
using System.Text.Json;

void ProcessToolResult(ToolCallResult result)
{
    switch (result.Type)
    {
        case ToolCallResultType.Success:
            Console.WriteLine($"Tool succeeded: {result.ResultJson}");
            break;

        case ToolCallResultType.Error:
            Console.WriteLine($"Tool failed: {result.ResultJson}");
            // Could retry or use fallback
            break;

        case ToolCallResultType.Canceled:
            Console.WriteLine("Tool was cancelled");
            break;

        case ToolCallResultType.Timeout:
            Console.WriteLine("Tool timed out");
            // Could retry with longer timeout
            break;

        default:
            // Future-proof: handle unknown types
            Console.WriteLine($"Unknown result type: {result.Type}");
            break;
    }
}

Remarks

ToolCallResultType indicates how a tool call concluded. Always check this value before processing the ResultJson to understand what kind of content to expect.

Forward Compatibility:
Handle unknown enum values defensively to remain compatible with future SDK versions. Consider treating unknown values as Error or logging and continuing.

JSON Payload Conventions:
Each result type has a recommended JSON structure for its payload, documented on each enum member. These conventions help maintain consistency across tools.