Record Class ToolResult
java.lang.Object
java.lang.Record
group.worldstandard.pudel.api.agent.ToolResult
- Record Components:
success- whether the execution was successfulresult- the result message (shown to user via agent)error- error message if the execution failedtoolName- the name of the tool that was executedexecutionTimeMs- 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 Summary
ConstructorsConstructorDescriptionToolResult(boolean success, String result, String error, String toolName, long executionTimeMs) Creates an instance of aToolResultrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.error()Returns the value of theerrorrecord component.longReturns the value of theexecutionTimeMsrecord component.static ToolResultCreates a ToolResult representing a failed tool execution.final inthashCode()Returns a hash code value for this object.static ToolResultnotAvailable(String toolName, String reason) Creates a ToolResult indicating that a tool is not available for execution.static ToolResultCreates a ToolResult indicating that the specified tool was not found.static ToolResultpermissionDenied(String toolName, String reason) Creates a ToolResult indicating that the tool execution was denied due to insufficient permissions.result()Returns the value of theresultrecord component.booleansuccess()Returns the value of thesuccessrecord component.static ToolResultCreates a successful tool execution result.toolName()Returns the value of thetoolNamerecord component.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
ToolResult
public ToolResult(boolean success, String result, String error, String toolName, long executionTimeMs) Creates an instance of aToolResultrecord class.- Parameters:
success- the value for thesuccessrecord componentresult- the value for theresultrecord componenterror- the value for theerrorrecord componenttoolName- the value for thetoolNamerecord componentexecutionTimeMs- the value for theexecutionTimeMsrecord component
-
-
Method Details
-
success
Creates a successful tool execution result.- Parameters:
toolName- the name of the tool that was executedresult- the result message to be shown to the user via the agentexecutionTimeMs- the execution time in milliseconds- Returns:
- a ToolResult instance representing a successful execution
-
failure
Creates a ToolResult representing a failed tool execution.- Parameters:
toolName- the name of the tool that was executederror- error message describing the failureexecutionTimeMs- execution time in milliseconds- Returns:
- a ToolResult instance indicating failure with the provided details
-
notFound
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
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 availablereason- the reason why the tool is not available- Returns:
- a ToolResult instance representing the unavailability of the tool
-
permissionDenied
Creates a ToolResult indicating that the tool execution was denied due to insufficient permissions.- Parameters:
toolName- the name of the tool that was deniedreason- the reason why permission was denied- Returns:
- a ToolResult representing a permission denied outcome
-
toString
-
hashCode
-
equals
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 withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
success
-
result
-
error
-
toolName
-
executionTimeMs
public long executionTimeMs()Returns the value of theexecutionTimeMsrecord component.- Returns:
- the value of the
executionTimeMsrecord component
-