Class ToolInterruptException

All Implemented Interfaces:
Serializable

public class ToolInterruptException extends RuntimeException
Exception thrown when a tool execution is interrupted.

This exception is used to implement the interrupt pattern, which allows tools to pause execution and request user input (human-in-the-loop). When a tool throws this exception, the generation loop stops and returns the interrupt information to the caller.

Example usage:


 Tool<Input, Output> confirmTool = genkit.defineInterrupt(InterruptConfig.<Input, Output>builder()
 		.name("confirmAction").description("Ask user for confirmation before proceeding").inputSchema(Input.class)
 		.outputSchema(Output.class).build());
 
See Also:
  • Constructor Details

    • ToolInterruptException

      public ToolInterruptException()
      Creates a new ToolInterruptException with no metadata.
    • ToolInterruptException

      public ToolInterruptException(Map<String,Object> metadata)
      Creates a new ToolInterruptException with metadata.
      Parameters:
      metadata - additional metadata about the interrupt
    • ToolInterruptException

      public ToolInterruptException(String message, Map<String,Object> metadata)
      Creates a new ToolInterruptException with a message and metadata.
      Parameters:
      message - the exception message
      metadata - additional metadata about the interrupt
  • Method Details

    • getMetadata

      public Map<String,Object> getMetadata()
      Gets the interrupt metadata.
      Returns:
      the metadata, never null (returns empty map if not set)