You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(agents): update Go interrupts to the interruptible-tool API
Switch the Go interrupts guide from the older ai.InterruptWith /
ctx.IsResumed pattern to genkitx.DefineInterruptibleTool with a typed
resume payload, tool.Interrupt/tool.InterruptAs, and the tool's
Resume/Respond methods, matching the agents sample and launch surface.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: src/content/docs/docs/agents/interrupts.mdx
+25-13Lines changed: 25 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,11 +147,14 @@ Wait for the final response before treating the turn as durably interrupted, bec
147
147
148
148
## Interrupt from a tool
149
149
150
-
Go does not have a separate interruptible tool type. A normal tool defined with `genkit.DefineTool` signals an interrupt by returning `ai.InterruptWith(ctx, metadata)` from inside its function. The lower-level form is `ctx.Interrupt(&ai.InterruptOptions{Metadata: ...})`.
151
-
152
-
The tool detects a resumed call with `ctx.IsResumed()` and can read the original input with `ai.OriginalInputAs[T](ctx)`. Keep approval and execution logic in one tool, and require the client to explicitly resume the turn.
150
+
Define an interruptible tool with `genkitx.DefineInterruptibleTool`. Its third parameter is a typed *resume payload*: `nil` on the first call, and populated with the client's answer when the turn is resumed. The tool pauses by returning `tool.Interrupt(metadata)`; on resume it runs again from the top with the payload set. Keep approval and execution logic in one tool, and require the client to explicitly resume the turn.
Build resume parts from the tool, then send them with `conn.SendResume`. Use `RestartWith` to re-execute the original tool, optionally with `ai.WithNewInput` to change its arguments. The tool runs again with `ctx.IsResumed()` true.
229
+
Build resume parts from the tool, then send them with `conn.SendResume`. Use `Resume` to re-execute the tool, delivering the client's typed answer to its resume parameter. The tool runs again from the top, this time with a non-nil payload.
0 commit comments