Package com.google.genkit.ai
Class InterruptRequest
java.lang.Object
com.google.genkit.ai.InterruptRequest
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 Summary
ConstructorsConstructorDescriptionInterruptRequest(ToolRequest toolRequest, Map<String, Object> metadata) Creates a new InterruptRequest. -
Method Summary
Modifier and TypeMethodDescriptionGets the interrupt metadata.Gets the tool request that was interrupted.booleanChecks if this is an interrupt.Creates a tool response to respond to this interrupt.Creates a tool response to respond to this interrupt with additional metadata.restart()Creates a tool request to restart this interrupt.Creates a tool request to restart this interrupt with new metadata.Creates a tool request to restart this interrupt with new input.toString()
-
Constructor Details
-
InterruptRequest
Creates a new InterruptRequest.- Parameters:
toolRequest- the original tool requestmetadata- the interrupt metadata
-
-
Method Details
-
getToolRequest
Gets the tool request that was interrupted.- Returns:
- the tool request
-
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
Creates a tool response to respond to this interrupt.- Parameters:
output- the output data to respond with- Returns:
- a ToolResponse part
-
respond
Creates a tool response to respond to this interrupt with additional metadata.- Parameters:
output- the output data to respond withresponseMetadata- additional metadata for the response- Returns:
- a ToolResponse part
-
restart
Creates a tool request to restart this interrupt.- Returns:
- a ToolRequest to restart execution
-
restart
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
Creates a tool request to restart this interrupt with new input.- Parameters:
resumedMetadata- metadata for the resumed executionreplaceInput- new input to replace the original- Returns:
- a ToolRequest to restart execution
-
toString
-