Interface ToolResponse

All Superinterfaces:
MetaCarrier

public interface ToolResponse extends MetaCarrier
The response to a tool call

The result can represent either success or an error. In both cases it can contain structured and unstructured content.

Returning a ToolResponse from a Tool-annotated method gives more control over the response that's returned to the client.

  • Method Details

    • content

      List<ContentBlock> content()
      The unstructured result data.

      A tool call can return one or more unstructured content objects as the result of a tool call.

      Returns:
      the result contents
    • structuredContent

      Optional<Object> structuredContent()
      The structured response data.

      Tools which declare an output schema return structured content. The structured content will be converted to JSON using a platform-specific mechanism.

      Returns:
      the structured content, or an empty Optional if there is no structured content
    • isError

      boolean isError()
      Whether or not the tool call resulted in an error.

      When a tool call results in an error, the content should describe the error.

      Returns:
      true if the response represents an error, false otherwise
    • builder

      static ToolResponse.Builder builder()
      Create a builder for a new ToolResponse
      Returns:
      the new ToolResponse builder
    • ofText

      static ToolResponse ofText(String text)
      Creates a new successful ToolResponse with a single text content block.
      Parameters:
      text - the text content
      Returns:
      the new tool response
    • ofError

      static ToolResponse ofError(String error)
      Creates a new error ToolResponse with a single text content block containing the error message.
      Parameters:
      error - the error message
      Returns:
      the new tool response
    • ofStructured

      static ToolResponse ofStructured(Object structuredContent)
      Creates a new successful ToolResponse with structured content.
      Parameters:
      structuredContent - the structured content
      Returns:
      the new tool response