Record Class ToolResult

java.lang.Object
java.lang.Record
group.worldstandard.pudel.api.agent.ToolResult
Record Components:
success - whether the execution was successful
result - the result message (shown to user via agent)
error - error message if the execution failed
toolName - the name of the tool that was executed
executionTimeMs - execution time in milliseconds

public record ToolResult(boolean success, String result, String error, String toolName, long executionTimeMs) extends Record
Result of executing an agent tool.

Returned by the agent tool execution pipeline. Use the static factory methods to create results:

// In an @AgentTool method
return ToolResult.success("my_tool", "Result data", elapsed);
return ToolResult.failure("my_tool", "Something went wrong", elapsed);
  • Constructor Details

    • ToolResult

      public ToolResult(boolean success, String result, String error, String toolName, long executionTimeMs)
      Creates an instance of a ToolResult record class.
      Parameters:
      success - the value for the success record component
      result - the value for the result record component
      error - the value for the error record component
      toolName - the value for the toolName record component
      executionTimeMs - the value for the executionTimeMs record component
  • Method Details

    • success

      public static ToolResult success(String toolName, String result, long executionTimeMs)
      Creates a successful tool execution result.
      Parameters:
      toolName - the name of the tool that was executed
      result - the result message to be shown to the user via the agent
      executionTimeMs - the execution time in milliseconds
      Returns:
      a ToolResult instance representing a successful execution
    • failure

      public static ToolResult failure(String toolName, String error, long executionTimeMs)
      Creates a ToolResult representing a failed tool execution.
      Parameters:
      toolName - the name of the tool that was executed
      error - error message describing the failure
      executionTimeMs - execution time in milliseconds
      Returns:
      a ToolResult instance indicating failure with the provided details
    • notFound

      public static ToolResult notFound(String toolName)
      Creates a ToolResult indicating that the specified tool was not found.
      Parameters:
      toolName - the name of the tool that was not found
      Returns:
      a ToolResult instance representing a tool not found error
    • notAvailable

      public static ToolResult notAvailable(String toolName, String reason)
      Creates a ToolResult indicating that a tool is not available for execution.

      This method is typically used when a tool cannot be executed due to temporary unavailability, maintenance, or other transient issues.

      Parameters:
      toolName - the name of the tool that is not available
      reason - the reason why the tool is not available
      Returns:
      a ToolResult instance representing the unavailability of the tool
    • permissionDenied

      public static ToolResult permissionDenied(String toolName, String reason)
      Creates a ToolResult indicating that the tool execution was denied due to insufficient permissions.
      Parameters:
      toolName - the name of the tool that was denied
      reason - the reason why permission was denied
      Returns:
      a ToolResult representing a permission denied outcome
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • success

      public boolean success()
      Returns the value of the success record component.
      Returns:
      the value of the success record component
    • result

      public String result()
      Returns the value of the result record component.
      Returns:
      the value of the result record component
    • error

      public String error()
      Returns the value of the error record component.
      Returns:
      the value of the error record component
    • toolName

      public String toolName()
      Returns the value of the toolName record component.
      Returns:
      the value of the toolName record component
    • executionTimeMs

      public long executionTimeMs()
      Returns the value of the executionTimeMs record component.
      Returns:
      the value of the executionTimeMs record component