Interrupt<Input, Output> class final

A special kind of Tool that always interrupts the generation loop.

Interrupts make it simpler to implement "human-in-the-loop" and out-of-band processing patterns that require waiting on external actions to complete. When the model calls an interrupt, the tool request bubbles back to the caller (with finishReason == interrupted) instead of executing any logic. You can then resume generation on a follow-up generate call by supplying interruptRespond to provide an answer.

A pure interrupt can only be responded to, never restarted: its body always interrupts, so restarting it (via interruptRestart) would just interrupt again, forever. That is why its tool metadata carries restartable: false. If you need a tool that interrupts once and then runs to completion when resumed, use a regular Tool whose function returns .interrupt(...) conditionally (for example, based on ctx.resumed).

This is the unregistered constructor form (the analog of Tool); it can be passed directly to generate/generateStream via the tools: parameter, including with the lightweight lite.dart API. To define and register an interrupt on a full Genkit instance, use defineInterrupt.

Example:

final confirm = Interrupt<Map<String, dynamic>, String>(
  name: 'confirmAction',
  description: 'Asks the user to confirm before proceeding.',
  inputSchema: SchemanticType.map(
    SchemanticType.string(),
    SchemanticType.dynamicSchema(),
  ),
);
Inheritance

Constructors

Interrupt({required String name, required String description, SchemanticType<Input>? inputSchema, SchemanticType<Output>? outputSchema, Map<String, dynamic>? metadata, FutureOr<Object?> requestMetadata(Input input, ToolFnArg<Input> ctx)?})

Properties

actionType → ActionType
finalinherited
description → String?
finalinherited
hashCode → int
The hash code for this object.
no setterinherited
initSchema → SchemanticType<void>?
finalinherited
inputSchema → SchemanticType<Input>?
finalinherited
key → String?
The fully-qualified registry key (/$actionType/$name) or, for actions resolved through a dynamic action provider, the DAP key (/dynamic-action-provider/<host>:<actionType>/<name>).
no setterinherited
metadata → Map<String, dynamic>
finalinherited
name → String
finalinherited
outputSchema → SchemanticType<ToolResult<Output>>?
finalinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
streamSchema → SchemanticType<void>?
finalinherited
toolOutputSchema → SchemanticType<Output>?
The schema of Output, as passed to the constructor's outputSchema. It is what the model, the Dev UI and MCP tools/list see as the tool's output.
finalinherited

Methods

call(Input? input, {StreamingCallback<void>? onChunk, Map<String, dynamic>? context, Stream<Input>? inputStream, void init, TraceStartCallback? onTraceStart, CancellationToken? cancel}) → Future<ToolResult<Output>>
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
run(Input? input, {StreamingCallback<void>? onChunk, Map<String, dynamic>? context, Stream<Input>? inputStream, void init, TraceStartCallback? onTraceStart, CancellationToken? cancel}) → Future<RunResult<ToolResult<Output>>>
inherited
runRaw(dynamic input, {StreamingCallback<void>? onChunk, Map<String, dynamic>? context, Stream<Input>? inputStream, dynamic init, TraceStartCallback? onTraceStart, CancellationToken? cancel}) → Future<RunResult<ToolResult<Output>>>
inherited
stream(Input? input, {Map<String, dynamic>? context, Stream<Input>? inputStream, void init, CancellationToken? cancel}) → ActionStream<void, ToolResult<Output>>
inherited
streamBidi({Stream<Input>? inputStream, StreamingCallback<void>? onChunk, Map<String, dynamic>? context, void init, CancellationToken? cancel}) → BidiActionStream<void, ToolResult<Output>, Input>
Starts a bidirectional session with this action: send inputs with BidiActionStream.send while consuming output chunks.
inherited
toJson() → Map<String, dynamic>
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited