Class InterruptRequest

java.lang.Object
com.google.genkit.ai.InterruptRequest

public class InterruptRequest extends Object
Represents an interrupt request from a tool.

When a tool triggers an interrupt, this class captures the tool request information and any associated metadata. The caller can then respond to the interrupt or restart the tool.

Example usage:


 // Check for interrupts in response
 List<InterruptRequest> interrupts = response.getInterrupts();
 if (!interrupts.isEmpty()) {
 	InterruptRequest interrupt = interrupts.get(0);
 	// Present to user and get response
 	String userResponse = getUserInput(interrupt.getToolRequest().getInput());

 	// Resume with user's response
 	ModelResponse resumed = chat.send(message, SendOptions.builder()
 			.resume(ResumeOptions.builder().respond(interrupt.respond(userResponse)).build()).build());
 }
 
  • Constructor Details

    • InterruptRequest

      public InterruptRequest(ToolRequest toolRequest, Map<String,Object> metadata)
      Creates a new InterruptRequest.
      Parameters:
      toolRequest - the original tool request
      metadata - the interrupt metadata
  • Method Details

    • getToolRequest

      public ToolRequest getToolRequest()
      Gets the tool request that was interrupted.
      Returns:
      the tool request
    • getMetadata

      public Map<String,Object> getMetadata()
      Gets the interrupt metadata.
      Returns:
      the metadata
    • isInterrupt

      public boolean isInterrupt()
      Checks if this is an interrupt.
      Returns:
      true if this is an interrupt (always true for InterruptRequest)
    • respond

      public ToolResponse respond(Object output)
      Creates a tool response to respond to this interrupt.
      Parameters:
      output - the output data to respond with
      Returns:
      a ToolResponse part
    • respond

      public ToolResponse respond(Object output, Map<String,Object> responseMetadata)
      Creates a tool response to respond to this interrupt with additional metadata.
      Parameters:
      output - the output data to respond with
      responseMetadata - additional metadata for the response
      Returns:
      a ToolResponse part
    • restart

      public ToolRequest restart()
      Creates a tool request to restart this interrupt.
      Returns:
      a ToolRequest to restart execution
    • restart

      public ToolRequest restart(Map<String,Object> resumedMetadata)
      Creates a tool request to restart this interrupt with new metadata.
      Parameters:
      resumedMetadata - metadata for the resumed execution
      Returns:
      a ToolRequest to restart execution
    • restart

      public ToolRequest restart(Map<String,Object> resumedMetadata, Object replaceInput)
      Creates a tool request to restart this interrupt with new input.
      Parameters:
      resumedMetadata - metadata for the resumed execution
      replaceInput - new input to replace the original
      Returns:
      a ToolRequest to restart execution
    • toString

      public String toString()
      Overrides:
      toString in class Object