LangEx.Interrupt (LangEx v0.11.3)

Copy Markdown View Source

Pause graph execution and wait for external input.

Call interrupt/1 inside any node function. Each call site gets a stable ID derived from the node name and the call order within the node ("node:0", "node:1", ...). If a resume value has been provided for that ID, it is returned immediately. Otherwise execution pauses and the payload is surfaced to the caller.

A node may interrupt multiple times: on each resume the node re-runs from the top, earlier interrupt/1 calls return their recorded values, and the first unanswered call pauses again.

Because the node re-runs from the top, side effects placed before an interrupt/1 call execute again on resume — keep them idempotent or move them to a node after the interrupt.

Call-site restrictions

interrupt/1 must run in the process executing the graph node. Tool functions dispatched by LangEx.Tool.Node and any process spawned inside a node run outside that context, so calling interrupt/1 there raises (with the default tool error handling, the raise turns into an error tool message). Interrupt from a dedicated graph node before or after the tool step instead.

Summary

Functions

Pauses graph execution with the given payload.

Functions

interrupt(payload \\ nil)

@spec interrupt(term()) :: term()

Pauses graph execution with the given payload.

Returns the resume value when the graph is resumed via LangEx.invoke(graph, %Command{resume: value}, config: ...). Resume with a single value to answer the first pending interrupt, or with a map of %{interrupt_id => value} to answer several at once.